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.
 
 
 
 
 

96 lines
3.0 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 0.9.4 LANGUAGES C CXX)
  9. set(DECAF_SO_VERSION "0")
  10. option(ENABLE_SHARED "Build shared library." ON)
  11. option(ENABLE_STATIC "Build static library." ON)
  12. option(ENABLE_STRICT "Build with strict compile options." YES)
  13. option(ENABLE_TESTS "Enable compilation of tests." YES)
  14. if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
  15. set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
  16. message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
  17. endif()
  18. include(GNUInstallDirs)
  19. include(CheckSymbolExists)
  20. include(CMakePushCheckState)
  21. include_directories(
  22. src/GENERATED/include/
  23. src/include/
  24. src/
  25. ${CMAKE_CURRENT_BINARY_DIR}
  26. )
  27. set(STRICT_OPTIONS_CPP )
  28. set(STRICT_OPTIONS_C )
  29. set(STRICT_OPTIONS_CXX )
  30. if(MSVC)
  31. if(ENABLE_STRICT)
  32. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} /WX")
  33. endif()
  34. else()
  35. set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -std=c++11 -O2 ")
  36. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wall -Wuninitialized -Wno-deprecated-declarations -Wno-missing-field-initializers ")
  37. 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 ")
  38. if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  39. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Qunused-arguments -Wno-array-bounds ")
  40. endif()
  41. if(APPLE)
  42. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Wno-error=unknown-warning-option -Qunused-arguments -Wno-tautological-compare -Wno-unused-function -Wno-array-bounds ")
  43. set(STRICT_OPTIONS_CXX "${STRICT_OPTIONS_CXX} -stdlib=libc++ ")
  44. endif()
  45. if(ENABLE_STRICT)
  46. set(STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP} -Werror -Wextra -Wno-unused-parameter -fno-strict-aliasing ")
  47. endif()
  48. endif()
  49. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STRICT_OPTIONS_C}")
  50. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRICT_OPTIONS_CXX}")
  51. add_subdirectory(src)
  52. if(ENABLE_TESTS)
  53. enable_testing()
  54. add_subdirectory(test)
  55. endif()
  56. include(CMakePackageConfigHelpers)
  57. export(EXPORT ${EXPORT_TARGETS_NAME}Targets
  58. FILE "${CMAKE_CURRENT_BINARY_DIR}/DecafTargets.cmake"
  59. )
  60. configure_file(cmake/DecafConfig.cmake.in
  61. "${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
  62. @ONLY
  63. )
  64. set(ConfigPackageLocation share/decaf/cmake)
  65. install(EXPORT ${EXPORT_TARGETS_NAME}Targets
  66. FILE DecafTargets.cmake
  67. DESTINATION ${ConfigPackageLocation}
  68. )
  69. install(FILES
  70. "${CMAKE_CURRENT_BINARY_DIR}/DecafConfig.cmake"
  71. DESTINATION ${ConfigPackageLocation}
  72. )
  73. # CPack settings
  74. set(CPACK_PACKAGE_NAME "decaf")
  75. set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
  76. set(CPACK_SOURCE_GENERATOR "TGZ")
  77. set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
  78. set(CPACK_SOURCE_IGNORE_FILES
  79. "^${CMAKE_BINARY_DIR}"
  80. "/\\\\..+"
  81. )
  82. include(CPack)