Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CMakeLists.txt 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. cmake_minimum_required (VERSION 2.8.8)
  2. project (OpenRaider)
  3. # Version Number
  4. set (OpenRaider_VERSION_MAJOR 0)
  5. set (OpenRaider_VERSION_MINOR 1)
  6. set (OpenRaider_VERSION_MICRO 4)
  7. set (OpenRaider_VERSION_RELEASE -git)
  8. # Build Host
  9. set (OpenRaider_BUILD_HOST ${CMAKE_HOST_SYSTEM})
  10. site_name (OpenRaider_HOSTNAME)
  11. #################################################################
  12. # Set a default build type if none was specified
  13. if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  14. message (STATUS "Setting build type to 'Debug' as none was specified.")
  15. set (CMAKE_BUILD_TYPE Debug)
  16. endif()
  17. #################################################################
  18. # Include directories
  19. include_directories ("${PROJECT_SOURCE_DIR}/include")
  20. include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/src/deps")
  21. include_directories ("${PROJECT_BINARY_DIR}")
  22. # Include External Modules
  23. set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
  24. #################################################################
  25. # Compiler specific flags
  26. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  27. set (WARNINGS "${WARNINGS} -Weverything")
  28. set (WARNINGS "${WARNINGS} -Wno-padded -Wno-packed")
  29. set (WARNINGS "${WARNINGS} -Wno-global-constructors -Wno-exit-time-destructors")
  30. set (WARNINGS "${WARNINGS} -Wno-documentation-unknown-command -Wno-c++98-compat-pedantic")
  31. set (WARNINGS "${WARNINGS} -Wno-date-time -Wno-unused-variable")
  32. set (WARNINGS "${WARNINGS} -Wno-shorten-64-to-32 -Wno-sign-compare -Wno-sign-conversion")
  33. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
  34. set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0")
  35. set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2")
  36. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  37. set (WARNINGS "${WARNINGS} -Wall -Wextra -Wpedantic")
  38. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
  39. set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0")
  40. set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2")
  41. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  42. # TODO Visual C++ compiler flags?
  43. endif()
  44. # Flags for all builds
  45. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} ${WARNINGS}")
  46. # Flags for Debug build
  47. set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -DDEBUG")
  48. # Flags for Releasae builds
  49. set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -DNODEBUG")
  50. #################################################################
  51. include (GetGitRevisionDescription)
  52. get_git_head_revision (GIT_REFSPEC GIT_SHA1)
  53. if (NOT ${GIT_SHA1} STREQUAL "GITDIR-NOTFOUND")
  54. string (SUBSTRING "-${GIT_SHA1}" 0 8 OpenRaider_VERSION_RELEASE)
  55. endif (NOT ${GIT_SHA1} STREQUAL "GITDIR-NOTFOUND")
  56. #################################################################
  57. enable_testing ()
  58. #################################################################
  59. # Add subdirectories
  60. add_subdirectory (src)
  61. add_subdirectory (test)
  62. #################################################################
  63. # CPack packaging
  64. include (InstallRequiredSystemLibraries)
  65. set (CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
  66. set (CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/COPYING")
  67. set (CPACK_MONOLITHIC_INSTALL YES)
  68. include (CPack)
  69. #################################################################
  70. if (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles")
  71. # Target for running the setup
  72. add_custom_target (setup "${PROJECT_SOURCE_DIR}/cmake/setup_win.bat"
  73. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  74. )
  75. endif (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles")
  76. if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
  77. # Target for running the setup
  78. add_custom_target (setup "${PROJECT_SOURCE_DIR}/cmake/setup.sh"
  79. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  80. )
  81. #################################################################
  82. # Target for running cppcheck
  83. set (CHECK_STD "--std=c++11" "--std=posix")
  84. set (CHECK_FLAGS "--quiet" "--force" "-I${PROJECT_SOURCE_DIR}/include")
  85. set (CHECK_FLAGS ${CHECK_FLAGS} "-i${PROJECT_SOURCE_DIR}/src/deps")
  86. set (CHECK_NORMAL "--enable=information,warning,performance,portability")
  87. set (CHECK_FULL "--enable=all")
  88. set (CHECK_CONFIG "--check-config")
  89. add_custom_target (cppcheck echo "Running cppcheck..."
  90. COMMAND cppcheck ${CHECK_FLAGS} ${CHECK_STD} ${CHECK_NORMAL} ${PROJECT_SOURCE_DIR}
  91. )
  92. add_custom_target (cppcheckFull echo "Running full cppcheck..."
  93. COMMAND cppcheck ${CHECK_FLAGS} ${CHECK_STD} ${CHECK_FULL} ${PROJECT_SOURCE_DIR}
  94. )
  95. add_custom_target (cppcheckConfig echo "Checking cppcheck config..."
  96. COMMAND cppcheck ${CHECK_FLAGS} ${CHECK_CONFIG} ${PROJECT_SOURCE_DIR}
  97. )
  98. #################################################################
  99. # Generate Doxygen Documentation
  100. find_package (Doxygen)
  101. if (DOXYGEN_FOUND)
  102. # Configure the Template Doxyfile for our specific project
  103. configure_file (cmake/Doxyfile.in
  104. ${PROJECT_BINARY_DIR}/Doxyfile @ONLY IMMEDIATE)
  105. # Add a custom target to run Doxygen when ever the project is built
  106. add_custom_target (doc
  107. COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
  108. SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
  109. # Add custom target to create local documentation without graphs
  110. add_custom_target (docLocal
  111. COMMAND sed -i '' "s/HAVE_DOT = YES/HAVE_DOT = NO/g" Doxyfile
  112. COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
  113. COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
  114. COMMAND sed -i '' "s/HAVE_DOT = NO/HAVE_DOT = YES/g" Doxyfile
  115. SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
  116. # Add custom target to create local documentation with call and caller graphs
  117. add_custom_target (docLocalFull
  118. COMMAND sed -i '' "s/CALL_GRAPH = NO/CALL_GRAPH = YES/g" Doxyfile
  119. COMMAND sed -i '' "s/CALLER_GRAPH = NO/CALLER_GRAPH = YES/g" Doxyfile
  120. COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
  121. COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
  122. COMMAND sed -i '' "s/CALL_GRAPH = YES/CALL_GRAPH = NO/g" Doxyfile
  123. COMMAND sed -i '' "s/CALLER_GRAPH = YES/CALLER_GRAPH = NO/g" Doxyfile
  124. SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
  125. # Clean doc files
  126. set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "doc")
  127. endif (DOXYGEN_FOUND)
  128. #################################################################
  129. # Auto-format code
  130. add_custom_target (format
  131. COMMAND astyle -A14s4pHUk1OocxC100z2SKNLm1Qxynr "include/*.h"
  132. COMMAND astyle -A14s4pHUk1OocxC100z2SKNLm1Qxynr "src/*.cpp" --exclude=src/deps
  133. COMMAND astyle -A14s4pHUk1OocxC100z2SKNLm1Qxynr "test/*.cpp" "test/*.h"
  134. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  135. COMMENT "Auto-Formatting code..." VERBATIM
  136. )
  137. #################################################################
  138. # Count source code lines
  139. add_custom_target (count
  140. COMMAND cloc --exclude-dir=deps,cmake,data,build ${PROJECT_SOURCE_DIR}
  141. COMMENT "Counting lines of source code..." VERBATIM
  142. )
  143. add_custom_target (countFull
  144. COMMAND cloc --exclude-dir=build ${PROJECT_SOURCE_DIR}
  145. COMMENT "Counting lines of source code..." VERBATIM
  146. )
  147. endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")