1 # Allow the source files to find headers in src/
2 include_directories(${PROJECT_SOURCE_DIR}/src)
4 if (DEFINED BENCHMARK_CXX_LINKER_FLAGS)
5 list(APPEND CMAKE_SHARED_LINKER_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS})
6 list(APPEND CMAKE_MODULE_LINKER_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS})
12 ${PROJECT_SOURCE_DIR}/include/benchmark/*.h
13 ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
14 file(GLOB BENCHMARK_MAIN "benchmark_main.cc")
15 foreach(item ${BENCHMARK_MAIN})
16 list(REMOVE_ITEM SOURCE_FILES "${item}")
19 add_library(benchmark ${SOURCE_FILES})
20 set_target_properties(benchmark PROPERTIES
21 OUTPUT_NAME "benchmark"
22 VERSION ${GENERIC_LIB_VERSION}
23 SOVERSION ${GENERIC_LIB_SOVERSION}
26 target_include_directories(benchmark PUBLIC
27 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
31 target_link_libraries(benchmark ${BENCHMARK_CXX_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
32 find_library(LIBRT rt)
34 target_link_libraries(benchmark ${LIBRT})
37 # We need extra libraries on Windows
38 if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
39 target_link_libraries(benchmark Shlwapi)
42 # We need extra libraries on Solaris
43 if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
44 target_link_libraries(benchmark kstat)
47 # Benchmark main library
48 add_library(benchmark_main "benchmark_main.cc")
49 set_target_properties(benchmark_main PROPERTIES
50 OUTPUT_NAME "benchmark_main"
51 VERSION ${GENERIC_LIB_VERSION}
52 SOVERSION ${GENERIC_LIB_SOVERSION}
55 target_include_directories(benchmark PUBLIC
56 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
58 target_link_libraries(benchmark_main benchmark)
60 set(include_install_dir "include")
61 set(lib_install_dir "lib/")
62 set(bin_install_dir "bin/")
63 set(config_install_dir "lib/cmake/${PROJECT_NAME}")
64 set(pkgconfig_install_dir "lib/pkgconfig")
66 set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
68 set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
69 set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
70 set(pkg_config "${generated_dir}/${PROJECT_NAME}.pc")
71 set(targets_export_name "${PROJECT_NAME}Targets")
73 set(namespace "${PROJECT_NAME}::")
75 include(CMakePackageConfigHelpers)
76 write_basic_package_version_file(
77 "${version_config}" VERSION ${GIT_VERSION} COMPATIBILITY SameMajorVersion
80 configure_file("${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" "${project_config}" @ONLY)
81 configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY)
83 if (BENCHMARK_ENABLE_INSTALL)
84 # Install target (will install the library to specified CMAKE_INSTALL_PREFIX variable)
86 TARGETS benchmark benchmark_main
87 EXPORT ${targets_export_name}
88 ARCHIVE DESTINATION ${lib_install_dir}
89 LIBRARY DESTINATION ${lib_install_dir}
90 RUNTIME DESTINATION ${bin_install_dir}
91 INCLUDES DESTINATION ${include_install_dir})
94 DIRECTORY "${PROJECT_SOURCE_DIR}/include/benchmark"
95 DESTINATION ${include_install_dir}
96 FILES_MATCHING PATTERN "*.*h")
99 FILES "${project_config}" "${version_config}"
100 DESTINATION "${config_install_dir}")
103 FILES "${pkg_config}"
104 DESTINATION "${pkgconfig_install_dir}")
107 EXPORT "${targets_export_name}"
108 NAMESPACE "${namespace}"
109 DESTINATION "${config_install_dir}")