Open Source Tomb Raider Engine
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. cmake_minimum_required (VERSION 2.8)
  2. project (OpenRaider)
  3. # Version Number
  4. set (OpenRaider_VERSION_MAJOR 0)
  5. set (OpenRaider_VERSION_MINOR 1)
  6. set (OpenRaider_VERSION_MICRO 3)
  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 ("${PROJECT_BINARY_DIR}")
  21. # Include External Modules
  22. set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
  23. #################################################################
  24. # Compiler specific flags
  25. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  26. set (WARNINGS "${WARNINGS} -Weverything")
  27. set (WARNINGS "${WARNINGS} -Wno-padded -Wno-packed")
  28. set (WARNINGS "${WARNINGS} -Wno-global-constructors -Wno-exit-time-destructors")
  29. set (WARNINGS "${WARNINGS} -Wno-documentation-unknown-command -Wno-c++98-compat-pedantic")
  30. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
  31. set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0 -ftrapv")
  32. set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2 -fomit-frame-pointer")
  33. set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -ffast-math -funroll-loops")
  34. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  35. set (WARNINGS "${WARNINGS} -Wall -Wextra -Wpedantic")
  36. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
  37. set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0 -ftrapv")
  38. set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2 -fomit-frame-pointer")
  39. set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -ffast-math -funroll-loops")
  40. elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  41. # TODO Visual C++ compiler flags?
  42. endif()
  43. # Flags for all builds
  44. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} ${WARNINGS}")
  45. # Flags for Debug build
  46. set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -DDEBUG")
  47. set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -DEXPERIMENTAL")
  48. set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -DMULTITEXTURE")
  49. # Flags for Releasae builds
  50. set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -DNDEBUG")
  51. #################################################################
  52. include (GetGitRevisionDescription)
  53. get_git_head_revision (GIT_REFSPEC GIT_SHA1)
  54. if (NOT ${GIT_SHA1} STREQUAL "GITDIR-NOTFOUND")
  55. string (SUBSTRING "-${GIT_SHA1}" 0 8 OpenRaider_VERSION_RELEASE)
  56. endif (NOT ${GIT_SHA1} STREQUAL "GITDIR-NOTFOUND")
  57. #################################################################
  58. # Add subdirectories
  59. add_subdirectory (src)
  60. #################################################################
  61. if (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles")
  62. # Target for running the setup
  63. add_custom_target (setup "${PROJECT_SOURCE_DIR}/cmake/setup_win.bat"
  64. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  65. )
  66. endif (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles")
  67. if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
  68. # Target for running the setup
  69. add_custom_target (setup "${PROJECT_SOURCE_DIR}/cmake/setup.sh"
  70. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  71. )
  72. #################################################################
  73. # Target for running cppcheck
  74. set (CHECK_STD "--std=c++11" "--std=posix")
  75. set (CHECK_FLAGS "--quiet" "--force")
  76. set (CHECK_NORMAL "--enable=information,warning,performance,portability")
  77. set (CHECK_FULL "--enable=all")
  78. set (CHECK_CONFIG "--check-config")
  79. add_custom_target (check echo "Running cppcheck..."
  80. COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_STD} ${CHECK_NORMAL} ${PROJECT_SOURCE_DIR}
  81. )
  82. add_custom_target (checkFull echo "Running full cppcheck..."
  83. COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_STD} ${CHECK_FULL} ${PROJECT_SOURCE_DIR}
  84. )
  85. add_custom_target (checkConfig echo "Checking cppcheck config..."
  86. COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_CONFIG} ${PROJECT_SOURCE_DIR}
  87. )
  88. #################################################################
  89. # Generate Doxygen Documentation
  90. find_package (Doxygen)
  91. if (DOXYGEN_FOUND)
  92. # Configure the Template Doxyfile for our specific project
  93. configure_file (cmake/Doxyfile.in
  94. ${PROJECT_BINARY_DIR}/Doxyfile @ONLY IMMEDIATE)
  95. # Add a custom target to run Doxygen when ever the project is built
  96. add_custom_target (doc
  97. COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
  98. SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
  99. # Add custom target to create local documentation without graphs
  100. add_custom_target (docLocal
  101. COMMAND sed -i '' "s/HAVE_DOT = YES/HAVE_DOT = NO/g" Doxyfile
  102. COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
  103. COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
  104. COMMAND sed -i '' "s/HAVE_DOT = NO/HAVE_DOT = YES/g" Doxyfile
  105. SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
  106. # Add custom target to create local documentation with call and caller graphs
  107. add_custom_target (docLocalFull
  108. COMMAND sed -i '' "s/CALL_GRAPH = NO/CALL_GRAPH = YES/g" Doxyfile
  109. COMMAND sed -i '' "s/CALLER_GRAPH = NO/CALLER_GRAPH = YES/g" Doxyfile
  110. COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
  111. COMMAND cp -R doc/html/* ${PROJECT_SOURCE_DIR}/../apache/
  112. COMMAND sed -i '' "s/CALL_GRAPH = YES/CALL_GRAPH = NO/g" Doxyfile
  113. COMMAND sed -i '' "s/CALLER_GRAPH = YES/CALLER_GRAPH = NO/g" Doxyfile
  114. SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
  115. # Clean doc files
  116. set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "doc")
  117. endif (DOXYGEN_FOUND)
  118. endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")