From a6ad799a4d26c4ed54bb1a90c1ae664e0767e6f6 Mon Sep 17 00:00:00 2001 From: Geoff Romer Date: Thu, 2 Apr 2015 09:15:49 -0700 Subject: [PATCH 1/5] Configure 'benchmark' cmake target so that when other targets depend on it, they get the appropriate include directories and link libraries automatically. --- src/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eebed294..29e10f4d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,10 +18,12 @@ else() endif() add_library(benchmark ${SOURCE_FILES} ${RE_FILES}) +find_package(Threads REQUIRED) -# Link threading if building a shared library. +# Link threading if building a shared library, otherwise let client do it. if (BUILD_SHARED_LIBS) - find_package(Threads REQUIRED) + target_link_libraries(benchmark PRIVATE ${CMAKE_THREAD_LIBS_INIT}) +else() target_link_libraries(benchmark ${CMAKE_THREAD_LIBS_INIT}) endif() @@ -36,6 +38,8 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") target_link_libraries(benchmark Shlwapi) endif() +target_include_directories(benchmark PUBLIC ${PROJECT_SOURCE_DIR}/include) + # Install target (will install the library to specified CMAKE_INSTALL_PREFIX variable) install( TARGETS benchmark From 89a1edae15aa1662205e77c63ab9acb31488a6bb Mon Sep 17 00:00:00 2001 From: Geoff Romer Date: Thu, 2 Apr 2015 14:35:59 -0700 Subject: [PATCH 2/5] Require cmake 2.8.12 in order to support target_include_directories, and simplify thread linking logic. --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2e7273d..a1ef15a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 2.8) +cmake_minimum_required (VERSION 2.8.12) project (benchmark) option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 29e10f4d..90e7b892 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,14 +18,9 @@ else() endif() add_library(benchmark ${SOURCE_FILES} ${RE_FILES}) -find_package(Threads REQUIRED) -# Link threading if building a shared library, otherwise let client do it. -if (BUILD_SHARED_LIBS) - target_link_libraries(benchmark PRIVATE ${CMAKE_THREAD_LIBS_INIT}) -else() - target_link_libraries(benchmark ${CMAKE_THREAD_LIBS_INIT}) -endif() +find_package(Threads REQUIRED) +target_link_libraries(benchmark ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(benchmark PROPERTIES OUTPUT_NAME "benchmark" From 3078ce9bc5dc3d594dd1b1009cbf365495901b0f Mon Sep 17 00:00:00 2001 From: Geoff Romer Date: Thu, 2 Apr 2015 15:00:22 -0700 Subject: [PATCH 3/5] Link pthread as an INTERFACE library. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 90e7b892..3d3d72c3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,7 @@ endif() add_library(benchmark ${SOURCE_FILES} ${RE_FILES}) find_package(Threads REQUIRED) -target_link_libraries(benchmark ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(benchmark INTERFACE ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(benchmark PROPERTIES OUTPUT_NAME "benchmark" From dcb1a3dad44240a6c07118c9fb6a4ae0cca285ff Mon Sep 17 00:00:00 2001 From: Geoff Romer Date: Thu, 2 Apr 2015 15:24:48 -0700 Subject: [PATCH 4/5] Drop down to CMake 2.8.11, and drop INTERFACE since that version doesn't support it. --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1ef15a7..41c7e4be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 2.8.12) +cmake_minimum_required (VERSION 2.8.11) project (benchmark) option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d3d72c3..90e7b892 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,7 @@ endif() add_library(benchmark ${SOURCE_FILES} ${RE_FILES}) find_package(Threads REQUIRED) -target_link_libraries(benchmark INTERFACE ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(benchmark ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(benchmark PROPERTIES OUTPUT_NAME "benchmark" From 1e0ed3a21cee0b1d7b634dd9632d26fb4e41aebc Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Fri, 3 Apr 2015 13:33:54 -0700 Subject: [PATCH 5/5] Rearrange the pieces --- CMakeLists.txt | 3 +++ src/CMakeLists.txt | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41c7e4be..cb57f3ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,9 @@ cxx_feature_check(GNU_POSIX_REGEX) cxx_feature_check(POSIX_REGEX) cxx_feature_check(STEADY_CLOCK) +# Ensure we have pthreads +find_package(Threads REQUIRED) + # Set up directories include_directories(${PROJECT_SOURCE_DIR}/include) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 90e7b892..811d0755 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,20 +19,22 @@ endif() add_library(benchmark ${SOURCE_FILES} ${RE_FILES}) -find_package(Threads REQUIRED) -target_link_libraries(benchmark ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(benchmark PROPERTIES OUTPUT_NAME "benchmark" VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} - ) +) + +# Link threads. +target_link_libraries(benchmark ${CMAKE_THREAD_LIBS_INIT}) # We need extra libraries on Windows if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") target_link_libraries(benchmark Shlwapi) endif() +# Expose public API target_include_directories(benchmark PUBLIC ${PROJECT_SOURCE_DIR}/include) # Install target (will install the library to specified CMAKE_INSTALL_PREFIX variable)