Bump version to 19.1.0 (final)
[llvm-project.git] / third-party / benchmark / src / CMakeLists.txt
blob943594b70bcd0c9838d7c500fabe7deac3c4fae6
1 # Allow the source files to find headers in src/
2 include(GNUInstallDirs)
3 include_directories(${PROJECT_SOURCE_DIR}/src)
5 if (DEFINED BENCHMARK_CXX_LINKER_FLAGS)
6   list(APPEND CMAKE_SHARED_LINKER_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS})
7   list(APPEND CMAKE_MODULE_LINKER_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS})
8 endif()
10 file(GLOB
11   SOURCE_FILES
12     *.cc
13     ${PROJECT_SOURCE_DIR}/include/benchmark/*.h
14     ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
15 file(GLOB BENCHMARK_MAIN "benchmark_main.cc")
16 foreach(item ${BENCHMARK_MAIN})
17   list(REMOVE_ITEM SOURCE_FILES "${item}")
18 endforeach()
20 add_library(benchmark ${SOURCE_FILES})
21 add_library(benchmark::benchmark ALIAS benchmark)
22 set_target_properties(benchmark PROPERTIES
23   OUTPUT_NAME "benchmark"
24   VERSION ${GENERIC_LIB_VERSION}
25   SOVERSION ${GENERIC_LIB_SOVERSION}
27 target_include_directories(benchmark PUBLIC
28   $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
31 set_property(
32   SOURCE benchmark.cc
33   APPEND
34   PROPERTY COMPILE_DEFINITIONS
35   BENCHMARK_VERSION="${VERSION}"
38 # libpfm, if available
39 if (PFM_FOUND)
40   target_link_libraries(benchmark PRIVATE PFM::libpfm)
41   target_compile_definitions(benchmark PRIVATE -DHAVE_LIBPFM)
42 endif()
44 # pthread affinity, if available
45 if(HAVE_PTHREAD_AFFINITY)
46   target_compile_definitions(benchmark PRIVATE -DBENCHMARK_HAS_PTHREAD_AFFINITY)
47 endif()
49 # Link threads.
50 target_link_libraries(benchmark PRIVATE Threads::Threads)
52 target_link_libraries(benchmark PRIVATE ${BENCHMARK_CXX_LIBRARIES})
54 if(HAVE_LIB_RT)
55   target_link_libraries(benchmark PRIVATE rt)
56 endif(HAVE_LIB_RT)
59 # We need extra libraries on Windows
60 if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
61   target_link_libraries(benchmark PRIVATE shlwapi)
62 endif()
64 # We need extra libraries on Solaris
65 if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
66   target_link_libraries(benchmark PRIVATE kstat)
67 endif()
69 if (NOT BUILD_SHARED_LIBS)
70   target_compile_definitions(benchmark PUBLIC -DBENCHMARK_STATIC_DEFINE)
71 endif()
73 # Benchmark main library
74 add_library(benchmark_main "benchmark_main.cc")
75 add_library(benchmark::benchmark_main ALIAS benchmark_main)
76 set_target_properties(benchmark_main PROPERTIES
77   OUTPUT_NAME "benchmark_main"
78   VERSION ${GENERIC_LIB_VERSION}
79   SOVERSION ${GENERIC_LIB_SOVERSION}
80   DEFINE_SYMBOL benchmark_EXPORTS
82 target_link_libraries(benchmark_main PUBLIC benchmark::benchmark)
84 set(generated_dir "${PROJECT_BINARY_DIR}")
86 set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
87 set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
88 set(pkg_config "${generated_dir}/${PROJECT_NAME}.pc")
89 set(targets_to_export benchmark benchmark_main)
90 set(targets_export_name "${PROJECT_NAME}Targets")
92 set(namespace "${PROJECT_NAME}::")
94 include(CMakePackageConfigHelpers)
96 configure_package_config_file (
97   ${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
98   ${project_config}
99   INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
100   NO_SET_AND_CHECK_MACRO
101   NO_CHECK_REQUIRED_COMPONENTS_MACRO
103 write_basic_package_version_file(
104   "${version_config}" VERSION ${GENERIC_LIB_VERSION} COMPATIBILITY SameMajorVersion
107 configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY)
109 export (
110   TARGETS ${targets_to_export}
111   NAMESPACE "${namespace}"
112   FILE ${generated_dir}/${targets_export_name}.cmake
115 if (BENCHMARK_ENABLE_INSTALL)
116   # Install target (will install the library to specified CMAKE_INSTALL_PREFIX variable)
117   install(
118     TARGETS ${targets_to_export}
119     EXPORT ${targets_export_name}
120     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
121     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
122     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
123     INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
125   install(
126     DIRECTORY "${PROJECT_SOURCE_DIR}/include/benchmark"
127               "${PROJECT_BINARY_DIR}/include/benchmark"
128     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
129     FILES_MATCHING PATTERN "*.*h")
131   install(
132       FILES "${project_config}" "${version_config}"
133       DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
135   install(
136       FILES "${pkg_config}"
137       DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
139   install(
140       EXPORT "${targets_export_name}"
141       NAMESPACE "${namespace}"
142       DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
143 endif()
145 if (BENCHMARK_ENABLE_DOXYGEN)
146   find_package(Doxygen REQUIRED)
147   set(DOXYGEN_QUIET YES)
148   set(DOXYGEN_RECURSIVE YES)
149   set(DOXYGEN_GENERATE_HTML YES)
150   set(DOXYGEN_GENERATE_MAN NO)
151   set(DOXYGEN_MARKDOWN_SUPPORT YES)
152   set(DOXYGEN_BUILTIN_STL_SUPPORT YES)
153   set(DOXYGEN_EXTRACT_PACKAGE YES)
154   set(DOXYGEN_EXTRACT_STATIC YES)
155   set(DOXYGEN_SHOW_INCLUDE_FILES YES)
156   set(DOXYGEN_BINARY_TOC YES)
157   set(DOXYGEN_TOC_EXPAND YES)
158   set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "index.md")
159   doxygen_add_docs(benchmark_doxygen
160     docs
161     include
162     src
163     ALL
164     WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
165     COMMENT "Building documentation with Doxygen.")
166   if (BENCHMARK_ENABLE_INSTALL AND BENCHMARK_INSTALL_DOCS)
167     install(
168       DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/"
169       DESTINATION ${CMAKE_INSTALL_DOCDIR})
170   endif()
171 else()
172   if (BENCHMARK_ENABLE_INSTALL AND BENCHMARK_INSTALL_DOCS)
173     install(
174       DIRECTORY "${PROJECT_SOURCE_DIR}/docs/"
175       DESTINATION ${CMAKE_INSTALL_DOCDIR})
176   endif()
177 endif()