GetGooglebench.cmake 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Search prebuilt googlebench. If nothing found - download, unpack, build and then search again
  2. # allow to get googlebench from bundle also (instead of download)
  3. set ( GBENCH_GITHUB "https://github.com/google/benchmark/archive/main.zip" )
  4. set ( GBENCH_ZIP "benchmark-main.zip" ) # that is default filename if you download GBENCH_GITHUB using browser
  5. set ( GBENCH_URL "${LIBS_BUNDLE}/${GBENCH_ZIP}" )
  6. if (TARGET benchmark::benchmark_main)
  7. return ()
  8. endif ()
  9. macro ( fixup_benches_and_return_if_found )
  10. if (TARGET benchmark::benchmark)
  11. set_target_properties ( benchmark::benchmark PROPERTIES
  12. MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
  13. MAP_IMPORTED_CONFIG_MINSIZEREL Release
  14. MAP_IMPORTED_CONFIG_DEBUG Release
  15. )
  16. endif ()
  17. if (TARGET benchmark::benchmark_main)
  18. set_target_properties ( benchmark::benchmark_main PROPERTIES
  19. MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
  20. MAP_IMPORTED_CONFIG_MINSIZEREL Release
  21. MAP_IMPORTED_CONFIG_DEBUG Release
  22. )
  23. endif ()
  24. if (TARGET benchmark::benchmark)
  25. return ()
  26. endif ()
  27. endmacro ()
  28. include ( update_bundle )
  29. # check pre-built gbenches
  30. find_package ( benchmark QUIET CONFIG )
  31. fixup_benches_and_return_if_found ()
  32. # not found. Populate and build cache package for now and future usage.
  33. MESSAGE ( STATUS "prebuilt googlebench wasn't found. Will build it right now..." )
  34. select_nearest_url ( GBENCH_PLACE "gbench" ${GBENCH_URL} ${GBENCH_GITHUB} )
  35. # build as external project and install into cache
  36. get_build ( GBENCH_BUILD benchmark )
  37. configure_file ( ${MANTICORE_SOURCE_DIR}/cmake/gbench-imported.cmake.in "${MANTICORE_BINARY_DIR}/gbench-build/CMakeLists.txt" )
  38. execute_process ( COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY "${MANTICORE_BINARY_DIR}/gbench-build" )
  39. execute_process ( COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY "${MANTICORE_BINARY_DIR}/gbench-build" )
  40. # now it should find
  41. find_package ( benchmark CONFIG )
  42. fixup_benches_and_return_if_found ()