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.
 
 
 
 
 

118 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." YES)
  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 will be 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 -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer ")
  46. if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  47. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Qunused-arguments -Wno-array-bounds ")
  48. endif()
  49. if(APPLE)
  50. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wno-error=unknown-warning-option -Qunused-arguments -Wno-tautological-compare -Wno-unused-function -Wno-array-bounds ")
  51. set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -stdlib=libc++ ")
  52. endif()
  53. if(ENABLE_STRICT)
  54. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Werror -Wextra -Wno-unused-parameter -fno-strict-aliasing ")
  55. endif()
  56. endif()
  57. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STRICT_OPTIONS_C}")
  58. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRICT_OPTIONS_CXX}")
  59. add_subdirectory(src)
  60. if(ENABLE_TESTS)
  61. enable_testing()
  62. add_subdirectory(test)
  63. endif()
  64. include(CMakePackageConfigHelpers)
  65. export(EXPORT ${EXPORT_TARGETS_NAME}Targets
  66. FILE "${CMAKE_CURRENT_BINARY_DIR}/DecafTargets.cmake"
  67. )
  68. configure_file(cmake/DecafConfig.cmake.in
  69. "${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
  70. @ONLY
  71. )
  72. set(ConfigPackageLocation share/decaf/cmake)
  73. install(EXPORT ${EXPORT_TARGETS_NAME}Targets
  74. FILE DecafTargets.cmake
  75. DESTINATION ${ConfigPackageLocation}
  76. )
  77. install(FILES
  78. "${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
  79. DESTINATION ${ConfigPackageLocation}
  80. )
  81. # Doxygen
  82. find_package(Doxygen)
  83. if (DOXYGEN_FOUND)
  84. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  85. add_custom_target(doc
  86. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  87. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  88. DEPENDS generatedCode
  89. COMMENT "Generating API documentation with Doxygen" VERBATIM
  90. )
  91. endif()
  92. # CPack settings
  93. set(CPACK_PACKAGE_NAME "decaf")
  94. set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
  95. set(CPACK_SOURCE_GENERATOR "TGZ")
  96. set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
  97. set(CPACK_SOURCE_IGNORE_FILES
  98. "^${CMAKE_BINARY_DIR}"
  99. "/\\\\..+"
  100. )
  101. include(CPack)