1# Allow the source files to find headers in src/ 2include_directories(${PROJECT_SOURCE_DIR}/src) 3 4if (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}) 7endif() 8 9file(GLOB 10 SOURCE_FILES 11 *.cc 12 ${PROJECT_SOURCE_DIR}/include/benchmark/*.h 13 ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 14list(FILTER SOURCE_FILES EXCLUDE REGEX "benchmark_main\\.cc") 15 16add_library(benchmark ${SOURCE_FILES}) 17set_target_properties(benchmark PROPERTIES 18 OUTPUT_NAME "benchmark" 19 VERSION ${GENERIC_LIB_VERSION} 20 SOVERSION ${GENERIC_LIB_SOVERSION} 21) 22target_include_directories(benchmark PUBLIC 23 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> 24 ) 25 26# Link threads. 27target_link_libraries(benchmark ${BENCHMARK_CXX_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 28find_library(LIBRT rt) 29if(LIBRT) 30 target_link_libraries(benchmark ${LIBRT}) 31endif() 32 33# We need extra libraries on Windows 34if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 35 target_link_libraries(benchmark Shlwapi) 36endif() 37 38# We need extra libraries on Solaris 39if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") 40 target_link_libraries(benchmark kstat) 41endif() 42 43# Benchmark main library 44add_library(benchmark_main "benchmark_main.cc") 45set_target_properties(benchmark_main PROPERTIES 46 OUTPUT_NAME "benchmark_main" 47 VERSION ${GENERIC_LIB_VERSION} 48 SOVERSION ${GENERIC_LIB_SOVERSION} 49) 50target_include_directories(benchmark PUBLIC 51 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> 52 ) 53target_link_libraries(benchmark_main benchmark) 54 55set(include_install_dir "include") 56set(lib_install_dir "lib/") 57set(bin_install_dir "bin/") 58set(config_install_dir "lib/cmake/${PROJECT_NAME}") 59set(pkgconfig_install_dir "lib/pkgconfig") 60 61set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") 62 63set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") 64set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") 65set(pkg_config "${generated_dir}/${PROJECT_NAME}.pc") 66set(targets_export_name "${PROJECT_NAME}Targets") 67 68set(namespace "${PROJECT_NAME}::") 69 70include(CMakePackageConfigHelpers) 71write_basic_package_version_file( 72 "${version_config}" VERSION ${GIT_VERSION} COMPATIBILITY SameMajorVersion 73) 74 75configure_file("${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" "${project_config}" @ONLY) 76configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY) 77 78if (BENCHMARK_ENABLE_INSTALL) 79 # Install target (will install the library to specified CMAKE_INSTALL_PREFIX variable) 80 install( 81 TARGETS benchmark benchmark_main 82 EXPORT ${targets_export_name} 83 ARCHIVE DESTINATION ${lib_install_dir} 84 LIBRARY DESTINATION ${lib_install_dir} 85 RUNTIME DESTINATION ${bin_install_dir} 86 INCLUDES DESTINATION ${include_install_dir}) 87 88 install( 89 DIRECTORY "${PROJECT_SOURCE_DIR}/include/benchmark" 90 DESTINATION ${include_install_dir} 91 FILES_MATCHING PATTERN "*.*h") 92 93 install( 94 FILES "${project_config}" "${version_config}" 95 DESTINATION "${config_install_dir}") 96 97 install( 98 FILES "${pkg_config}" 99 DESTINATION "${pkgconfig_install_dir}") 100 101 install( 102 EXPORT "${targets_export_name}" 103 NAMESPACE "${namespace}" 104 DESTINATION "${config_install_dir}") 105endif() 106