DetermineGflagsNamespace.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. macro(determine_gflags_namespace VARIABLE)
  2. if (NOT DEFINED "${VARIABLE}")
  3. if (CMAKE_REQUIRED_INCLUDES)
  4. set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
  5. else ()
  6. set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
  7. endif ()
  8. set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
  9. set(_NAMESPACES gflags google)
  10. set(_check_code
  11. "
  12. #include <gflags/gflags.h>
  13. int main(int argc, char**argv)
  14. {
  15. GLOG_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
  16. }
  17. ")
  18. if (NOT CMAKE_REQUIRED_QUIET)
  19. message (STATUS "Looking for gflags namespace")
  20. endif ()
  21. if (${ARGC} EQUAL 3)
  22. set (CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
  23. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
  24. endif ()
  25. set (_check_file
  26. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/DetermineGflagsNamespace.cxx)
  27. foreach (_namespace ${_NAMESPACES})
  28. file (WRITE "${_check_file}" "${_check_code}")
  29. try_compile (${VARIABLE}
  30. "${CMAKE_BINARY_DIR}" "${_check_file}"
  31. COMPILE_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}" -DGLOG_GFLAGS_NAMESPACE=${_namespace}
  32. LINK_LIBRARIES gflags
  33. CMAKE_FLAGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  34. OUTPUT_VARIABLE OUTPUT)
  35. if (${VARIABLE})
  36. set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace" FORCE)
  37. break ()
  38. else ()
  39. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  40. "Determining the gflags namespace ${_namespace} failed with the following output:\n"
  41. "${OUTPUT}\n\n")
  42. endif ()
  43. endforeach (_namespace)
  44. if (${ARGC} EQUAL 3)
  45. set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
  46. endif ()
  47. if (${VARIABLE})
  48. if (NOT CMAKE_REQUIRED_QUIET)
  49. message (STATUS "Looking for gflags namespace - ${${VARIABLE}}")
  50. endif ()
  51. file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  52. "Determining the gflags namespace passed with the following output:\n"
  53. "${OUTPUT}\n\n")
  54. else ()
  55. if (NOT CMAKE_REQUIRED_QUIET)
  56. message (STATUS "Looking for gflags namespace - failed")
  57. endif ()
  58. set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace")
  59. endif ()
  60. endif ()
  61. endmacro ()