FindRapidjson.cmake 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Copyright (c) 2011 Milo Yip ([email protected])
  2. # Copyright (c) 2013 Rafal Jeczalik ([email protected])
  3. # Distributed under the MIT License (see license.txt file)
  4. # -----------------------------------------------------------------------------------
  5. #
  6. # Finds the rapidjson library
  7. #
  8. # -----------------------------------------------------------------------------------
  9. #
  10. # Variables used by this module, they can change the default behaviour.
  11. # Those variables need to be either set before calling find_package
  12. # or exported as environment variables before running CMake:
  13. #
  14. # RAPIDJSON_INCLUDEDIR - Set custom include path, useful when rapidjson headers are
  15. # outside system paths
  16. # RAPIDJSON_USE_SSE2 - Configure rapidjson to take advantage of SSE2 capabilities
  17. # RAPIDJSON_USE_SSE42 - Configure rapidjson to take advantage of SSE4.2 capabilities
  18. #
  19. # -----------------------------------------------------------------------------------
  20. #
  21. # Variables defined by this module:
  22. #
  23. # RAPIDJSON_FOUND - True if rapidjson was found
  24. # RAPIDJSON_INCLUDE_DIRS - Path to rapidjson include directory
  25. # RAPIDJSON_CXX_FLAGS - Extra C++ flags required for compilation with rapidjson
  26. #
  27. # -----------------------------------------------------------------------------------
  28. #
  29. # Example usage:
  30. #
  31. # set(RAPIDJSON_USE_SSE2 ON)
  32. # set(RAPIDJSON_INCLUDEDIR "/opt/github.com/rjeczalik/rapidjson/include")
  33. #
  34. # find_package(rapidjson REQUIRED)
  35. #
  36. # include_directories("${RAPIDJSON_INCLUDE_DIRS}")
  37. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RAPIDJSON_CXX_FLAGS}")
  38. # add_executable(foo foo.cc)
  39. #
  40. # -----------------------------------------------------------------------------------
  41. foreach(opt RAPIDJSON_INCLUDEDIR RAPIDJSON_USE_SSE2 RAPIDJSON_USE_SSE42)
  42. if(${opt} AND DEFINED ENV{${opt}} AND NOT ${opt} STREQUAL "$ENV{${opt}}")
  43. message(WARNING "Conflicting ${opt} values: ignoring environment variable and using CMake cache entry.")
  44. elseif(DEFINED ENV{${opt}} AND NOT ${opt})
  45. set(${opt} "$ENV{${opt}}")
  46. endif()
  47. endforeach()
  48. find_path(
  49. RAPIDJSON_INCLUDE_DIRS
  50. NAMES rapidjson/rapidjson.h
  51. PATHS ${RAPIDJSON_INCLUDEDIR}
  52. DOC "Include directory for the rapidjson library."
  53. )
  54. mark_as_advanced(RAPIDJSON_INCLUDE_DIRS)
  55. if(RAPIDJSON_INCLUDE_DIRS)
  56. set(RAPIDJSON_FOUND TRUE)
  57. endif()
  58. mark_as_advanced(RAPIDJSON_FOUND)
  59. if(RAPIDJSON_USE_SSE42)
  60. set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE42")
  61. if(MSVC)
  62. set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE4.2")
  63. else()
  64. set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse4.2")
  65. endif()
  66. else()
  67. if(RAPIDJSON_USE_SSE2)
  68. set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE2")
  69. if(MSVC)
  70. set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE2")
  71. else()
  72. set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse2")
  73. endif()
  74. endif()
  75. endif()
  76. mark_as_advanced(RAPIDJSON_CXX_FLAGS)
  77. if(RAPIDJSON_FOUND)
  78. if(NOT rapidjson_FIND_QUIETLY)
  79. message(STATUS "Found rapidjson header files in ${RAPIDJSON_INCLUDE_DIRS}")
  80. if(DEFINED RAPIDJSON_CXX_FLAGS)
  81. message(STATUS "Found rapidjson C++ extra compilation flags: ${RAPIDJSON_CXX_FLAGS}")
  82. endif()
  83. endif()
  84. elseif(rapidjson_FIND_REQUIRED)
  85. message(FATAL_ERROR "Could not find rapidjson")
  86. else()
  87. message(STATUS "Optional package rapidjson was not found")
  88. endif()