[llvm-exegesis][NFC] Improve parsing of the YAML files
[llvm-core.git] / utils / benchmark / src / CMakeLists.txt
blob5b3d52270de5dd8ba6ca5611a730e501e5e08efd
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})
7 endif()
9 file(GLOB
10   SOURCE_FILES
11     *.cc
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}")
17 endforeach()
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}
24   FOLDER "Utils"
26 target_include_directories(benchmark PUBLIC
27     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
28     )
30 # Link threads.
31 target_link_libraries(benchmark  ${BENCHMARK_CXX_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
32 find_library(LIBRT rt)
33 if(LIBRT)
34   target_link_libraries(benchmark ${LIBRT})
35 endif()
37 # We need extra libraries on Windows
38 if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
39   target_link_libraries(benchmark Shlwapi)
40 endif()
42 # We need extra libraries on Solaris
43 if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
44   target_link_libraries(benchmark kstat)
45 endif()
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}
53   FOLDER "Utils"
55 target_include_directories(benchmark PUBLIC
56     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
57     )
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)
85   install(
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})
93   install(
94     DIRECTORY "${PROJECT_SOURCE_DIR}/include/benchmark"
95     DESTINATION ${include_install_dir}
96     FILES_MATCHING PATTERN "*.*h")
98   install(
99       FILES "${project_config}" "${version_config}"
100       DESTINATION "${config_install_dir}")
102   install(
103       FILES "${pkg_config}"
104       DESTINATION "${pkgconfig_install_dir}")
106   install(
107       EXPORT "${targets_export_name}"
108       NAMESPACE "${namespace}"
109       DESTINATION "${config_install_dir}")
110 endif()