Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / third-party / benchmark / src / CMakeLists.txt
blobe814a4e00f7c2a8fbdd7f6dcdce9989d98e3d46c
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>)
30 # libpfm, if available
31 if (HAVE_LIBPFM)
32   target_link_libraries(benchmark PRIVATE pfm)
33   add_definitions(-DHAVE_LIBPFM)
34 endif()
36 # Link threads.
37 target_link_libraries(benchmark PRIVATE Threads::Threads)
39 target_link_libraries(benchmark PRIVATE ${BENCHMARK_CXX_LIBRARIES})
41 if(HAVE_LIB_RT)
42   target_link_libraries(benchmark PRIVATE rt)
43 endif(HAVE_LIB_RT)
46 # We need extra libraries on Windows
47 if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
48   target_link_libraries(benchmark PRIVATE shlwapi)
49 endif()
51 # We need extra libraries on Solaris
52 if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
53   target_link_libraries(benchmark PRIVATE kstat)
54 endif()
56 # Benchmark main library
57 add_library(benchmark_main "benchmark_main.cc")
58 add_library(benchmark::benchmark_main ALIAS benchmark_main)
59 set_target_properties(benchmark_main PROPERTIES
60   OUTPUT_NAME "benchmark_main"
61   VERSION ${GENERIC_LIB_VERSION}
62   SOVERSION ${GENERIC_LIB_SOVERSION}
64 target_link_libraries(benchmark_main PUBLIC benchmark::benchmark)
67 set(generated_dir "${PROJECT_BINARY_DIR}")
69 set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
70 set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
71 set(pkg_config "${generated_dir}/${PROJECT_NAME}.pc")
72 set(targets_to_export benchmark benchmark_main)
73 set(targets_export_name "${PROJECT_NAME}Targets")
75 set(namespace "${PROJECT_NAME}::")
77 include(CMakePackageConfigHelpers)
79 configure_package_config_file (
80   ${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
81   ${project_config}
82   INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
83   NO_SET_AND_CHECK_MACRO
84   NO_CHECK_REQUIRED_COMPONENTS_MACRO
86 write_basic_package_version_file(
87   "${version_config}" VERSION ${GENERIC_LIB_VERSION} COMPATIBILITY SameMajorVersion
90 configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY)
92 export (
93   TARGETS ${targets_to_export}
94   NAMESPACE "${namespace}"
95   FILE ${generated_dir}/${targets_export_name}.cmake
98 if (BENCHMARK_ENABLE_INSTALL)
99   # Install target (will install the library to specified CMAKE_INSTALL_PREFIX variable)
100   install(
101     TARGETS ${targets_to_export}
102     EXPORT ${targets_export_name}
103     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
104     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
105     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
106     INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
108   install(
109     DIRECTORY "${PROJECT_SOURCE_DIR}/include/benchmark"
110     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
111     FILES_MATCHING PATTERN "*.*h")
113   install(
114       FILES "${project_config}" "${version_config}"
115       DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
117   install(
118       FILES "${pkg_config}"
119       DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
121   install(
122       EXPORT "${targets_export_name}"
123       NAMESPACE "${namespace}"
124       DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
125 endif()
127 if (BENCHMARK_ENABLE_DOXYGEN)
128   find_package(Doxygen REQUIRED)
129   set(DOXYGEN_QUIET YES)
130   set(DOXYGEN_RECURSIVE YES)
131   set(DOXYGEN_GENERATE_HTML YES)
132   set(DOXYGEN_GENERATE_MAN NO)
133   set(DOXYGEN_MARKDOWN_SUPPORT YES)
134   set(DOXYGEN_BUILTIN_STL_SUPPORT YES)
135   set(DOXYGEN_EXTRACT_PACKAGE YES)
136   set(DOXYGEN_EXTRACT_STATIC YES)
137   set(DOXYGEN_SHOW_INCLUDE_FILES YES)
138   set(DOXYGEN_BINARY_TOC YES)
139   set(DOXYGEN_TOC_EXPAND YES)
140   set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "index.md")
141   doxygen_add_docs(benchmark_doxygen
142     docs
143     include
144     src
145     ALL
146     WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
147     COMMENT "Building documentation with Doxygen.")
148   if (BENCHMARK_ENABLE_INSTALL AND BENCHMARK_INSTALL_DOCS)
149     install(
150       DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/"
151       DESTINATION ${CMAKE_INSTALL_DOCDIR})
152   endif()
153 else()
154   if (BENCHMARK_ENABLE_INSTALL AND BENCHMARK_INSTALL_DOCS)
155     install(
156       DIRECTORY "${PROJECT_SOURCE_DIR}/docs/"
157       DESTINATION ${CMAKE_INSTALL_DOCDIR})
158   endif()
159 endif()