Here is my workable CMakelists.txt. The benchmark library is in /usr/local/lib/libbenchmark.a and it is built with the standard process in google benchmark
cmake_minimum_required(VERSION 3.5.1)
project(tiny_benchmark)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_CXX_EXTENSIONS off)
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
# set(CMAKE_STANDARD_LIBRARIES ${CMAKE_STANDARD_LIBRARIES} pthread benchmark /usr/local/lib/benchmark.a)
# set(CMAKE_STANDARD_LIBRARIES ${CMAKE_STANDARD_LIBRARIES} pthread)
add_executable(foo foo.cpp)
add_executable(bar bar.cpp)
target_link_libraries(foo pthread benchmark)
target_link_libraries(bar pthread benchmark)
Since I have many small benchmark tool to build so I don't want call target_link_libraries(bar pthread benchmark)
for every library.
I want to just define the executable. and the pthread and benchmark can be added automatically.
I found CMAKE_STANDARD_LIBRARIES is designed for this purpose, but I tried CMAKE_STANDARD_LIBRARIES and CMAKE_CXX_STANDARD_LIBRARIES in many format, but no one works.
what error did I make in this case? my cmake version is 3.5.1.
Thanks
You may use link_libraries command. Its effect similar to target_link_libraries
, but is applied to all targets created after the call.
link_libraries(pthread benchmark)
add_executable(foo foo.cpp)
add_executable(bar bar.cpp)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With