• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Allow the source files to find headers in src/
2include(GNUInstallDirs)
3include_directories(${PROJECT_SOURCE_DIR}/src)
4
5if (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})
8endif()
9
10file(GLOB
11  SOURCE_FILES
12    *.cc
13    ${PROJECT_SOURCE_DIR}/include/benchmark/*.h
14    ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
15file(GLOB BENCHMARK_MAIN "benchmark_main.cc")
16foreach(item ${BENCHMARK_MAIN})
17  list(REMOVE_ITEM SOURCE_FILES "${item}")
18endforeach()
19
20add_library(benchmark ${SOURCE_FILES})
21add_library(benchmark::benchmark ALIAS benchmark)
22set_target_properties(benchmark PROPERTIES
23  OUTPUT_NAME "benchmark"
24  VERSION ${GENERIC_LIB_VERSION}
25  SOVERSION ${GENERIC_LIB_SOVERSION}
26)
27target_include_directories(benchmark PUBLIC
28  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
29
30# libpfm, if available
31if (HAVE_LIBPFM)
32  target_link_libraries(benchmark PRIVATE pfm)
33  add_definitions(-DHAVE_LIBPFM)
34endif()
35
36# Link threads.
37target_link_libraries(benchmark PRIVATE Threads::Threads)
38
39target_link_libraries(benchmark PRIVATE ${BENCHMARK_CXX_LIBRARIES})
40
41if(HAVE_LIB_RT)
42  target_link_libraries(benchmark PRIVATE rt)
43endif(HAVE_LIB_RT)
44
45
46# We need extra libraries on Windows
47if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
48  target_link_libraries(benchmark PRIVATE shlwapi)
49endif()
50
51# We need extra libraries on Solaris
52if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
53  target_link_libraries(benchmark PRIVATE kstat)
54endif()
55
56# Benchmark main library
57add_library(benchmark_main "benchmark_main.cc")
58add_library(benchmark::benchmark_main ALIAS benchmark_main)
59set_target_properties(benchmark_main PROPERTIES
60  OUTPUT_NAME "benchmark_main"
61  VERSION ${GENERIC_LIB_VERSION}
62  SOVERSION ${GENERIC_LIB_SOVERSION}
63)
64target_link_libraries(benchmark_main PUBLIC benchmark::benchmark)
65
66
67set(generated_dir "${PROJECT_BINARY_DIR}")
68
69set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
70set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
71set(pkg_config "${generated_dir}/${PROJECT_NAME}.pc")
72set(targets_to_export benchmark benchmark_main)
73set(targets_export_name "${PROJECT_NAME}Targets")
74
75set(namespace "${PROJECT_NAME}::")
76
77include(CMakePackageConfigHelpers)
78
79configure_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
85)
86write_basic_package_version_file(
87  "${version_config}" VERSION ${GENERIC_LIB_VERSION} COMPATIBILITY SameMajorVersion
88)
89
90configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY)
91
92export (
93  TARGETS ${targets_to_export}
94  NAMESPACE "${namespace}"
95  FILE ${generated_dir}/${targets_export_name}.cmake
96)
97
98if (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})
107
108  install(
109    DIRECTORY "${PROJECT_SOURCE_DIR}/include/benchmark"
110    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
111    FILES_MATCHING PATTERN "*.*h")
112
113  install(
114      FILES "${project_config}" "${version_config}"
115      DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
116
117  install(
118      FILES "${pkg_config}"
119      DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
120
121  install(
122      EXPORT "${targets_export_name}"
123      NAMESPACE "${namespace}"
124      DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
125endif()
126
127if (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()
153else()
154  if (BENCHMARK_ENABLE_INSTALL AND BENCHMARK_INSTALL_DOCS)
155    install(
156      DIRECTORY "${PROJECT_SOURCE_DIR}/docs/"
157      DESTINATION ${CMAKE_INSTALL_DOCDIR})
158  endif()
159endif()
160