You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

117 lines
3.7 KiB

  1. ############################################################################
  2. # CMakeLists.txt
  3. #
  4. # Released under the MIT License. See LICENSE.txt for license information.
  5. #
  6. ############################################################################
  7. cmake_minimum_required(VERSION 3.0)
  8. project(DECAF VERSION 1.0 LANGUAGES C CXX)
  9. set(DECAF_SO_VERSION "0")
  10. find_package( PythonInterp 2.7 REQUIRED )
  11. option(ENABLE_SHARED "Build shared library." ON)
  12. option(ENABLE_STATIC "Build static library." ON)
  13. option(ENABLE_STRICT "Build with strict compile options." YES)
  14. option(ENABLE_TESTS "Enable compilation of tests." OFF)
  15. option(GENERATED_SOURCE_PATH "Where the generated source code is stored, default in the building tree" OFF)
  16. if (GENERATED_SOURCE_PATH)
  17. set(GSOURCE_PATH ${GENERATED_SOURCE_PATH})
  18. else()
  19. set(GSOURCE_PATH ${PROJECT_BINARY_DIR}/src/GENERATED)
  20. endif()
  21. message("Generated source code in ${GSOURCE_PATH}")
  22. if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
  23. set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
  24. message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
  25. endif()
  26. include(GNUInstallDirs)
  27. include(CheckSymbolExists)
  28. include(CMakePushCheckState)
  29. include_directories(
  30. ${GSOURCE_PATH}/include/
  31. src/include/
  32. src/
  33. ${CMAKE_CURRENT_BINARY_DIR}
  34. )
  35. set(STRICT_OPTIONS_CPP )
  36. set(STRICT_OPTIONS_C )
  37. set(STRICT_OPTIONS_CXX )
  38. if(MSVC)
  39. if(ENABLE_STRICT)
  40. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} /WX")
  41. endif()
  42. else()
  43. set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -std=c++11 -O2")
  44. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wall -Wuninitialized -Wno-deprecated-declarations -Wno-missing-field-initializers")
  45. set(STRICT_OPTIONS_C "${STRICT_OPTIONS_C} -std=c99 -O2 -Wstrict-prototypes -Wno-error=strict-prototypes -fvisibility=hidden")
  46. if(CMAKE_C_COMPILER_ID MATCHES "Clang")
  47. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wno-error=unknown-warning-option -Qunused-arguments -Wno-tautological-compare")
  48. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wno-unused-function -Wno-pass-failed")
  49. endif()
  50. if(ENABLE_STRICT)
  51. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Werror -Wextra -Wno-unused-parameter -fno-strict-aliasing")
  52. endif()
  53. endif()
  54. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STRICT_OPTIONS_C} ${STRICT_OPTIONS_CPP}")
  55. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRICT_OPTIONS_CXX} ${STRICT_OPTIONS_CPP}")
  56. add_subdirectory(src)
  57. if(ENABLE_TESTS)
  58. enable_testing()
  59. add_subdirectory(test)
  60. endif()
  61. include(CMakePackageConfigHelpers)
  62. set(ConfigPackageLocation share/decaf/cmake)
  63. export(EXPORT ${EXPORT_TARGETS_NAME}Targets
  64. FILE "${CMAKE_CURRENT_BINARY_DIR}/DecafTargets.cmake"
  65. )
  66. configure_package_config_file(cmake/DecafConfig.cmake.in
  67. "${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
  68. INSTALL_DESTINATION ${ConfigPackageLocation}
  69. NO_SET_AND_CHECK_MACRO
  70. )
  71. install(EXPORT ${EXPORT_TARGETS_NAME}Targets
  72. FILE DecafTargets.cmake
  73. DESTINATION ${ConfigPackageLocation}
  74. )
  75. install(FILES
  76. "${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
  77. DESTINATION ${ConfigPackageLocation}
  78. )
  79. # Doxygen
  80. find_package(Doxygen)
  81. if (DOXYGEN_FOUND)
  82. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  83. add_custom_target(doc
  84. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  85. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  86. DEPENDS generatedCode
  87. COMMENT "Generating API documentation with Doxygen" VERBATIM
  88. )
  89. endif()
  90. # CPack settings
  91. set(CPACK_PACKAGE_NAME "decaf")
  92. set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
  93. set(CPACK_SOURCE_GENERATOR "TGZ")
  94. set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
  95. set(CPACK_SOURCE_IGnore_FILES
  96. "^${CMAKE_BINARY_DIR}"
  97. "/\\\\..+"
  98. )
  99. include(CPack)