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