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 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. # Add OpenGL Library
  2. find_package (OpenGL REQUIRED)
  3. include_directories (SYSTEM ${OPENGL_INCLUDE_DIRS})
  4. set (LIBS ${LIBS} ${OPENGL_LIBRARIES})
  5. # Add Z Library
  6. find_package (ZLIB REQUIRED)
  7. include_directories (SYSTEM ${ZLIB_INCLUDE_DIRS})
  8. set (LIBS ${LIBS} ${ZLIB_LIBRARIES})
  9. # Add SDL2 Library
  10. find_package (SDL2)
  11. if (SDL2_FOUND)
  12. include_directories (SYSTEM ${SDL2_INCLUDE_DIR})
  13. set (LIBS ${LIBS} ${SDL2_LIBRARY})
  14. # Add SDL2_ttf Library
  15. find_package (SDL2TTF)
  16. if (SDL2TTF_FOUND)
  17. include_directories (SYSTEM ${SDL2TTF_INCLUDE_DIR})
  18. set (LIBS ${LIBS} ${SDL2TTF_LIBRARY})
  19. endif (SDL2TTF_FOUND)
  20. endif (SDL2_FOUND)
  21. # Add OpenAL Library
  22. find_package (OpenAL)
  23. if (OPENAL_FOUND)
  24. include_directories (SYSTEM ${OPENAL_INCLUDE_DIRS})
  25. set (LIBS ${LIBS} ${OPENAL_LIBRARIES})
  26. # Add ALUT Library
  27. find_package (ALUT)
  28. if (ALUT_FOUND)
  29. include_directories (SYSTEM ${ALUT_INCLUDE_DIRS})
  30. set (LIBS ${LIBS} ${ALUT_LIBRARIES})
  31. endif (ALUT_FOUND)
  32. endif (OPENAL_FOUND)
  33. # Add PNG Library
  34. find_package (PNG)
  35. if (PNG_FOUND)
  36. include_directories (SYSTEM ${PNG_INCLUDE_DIRS})
  37. set (LIBS ${LIBS} ${PNG_LIBRARIES})
  38. add_definitions (${PNG_DEFINITIONS})
  39. endif (PNG_FOUND)
  40. #################################################################
  41. # Set Source files
  42. set (SRCS ${SRCS} "Camera.cpp")
  43. set (SRCS ${SRCS} "Command.cpp")
  44. set (SRCS ${SRCS} "Console.cpp")
  45. set (SRCS ${SRCS} "Entity.cpp")
  46. set (SRCS ${SRCS} "Font.cpp")
  47. set (SRCS ${SRCS} "FontManager.cpp")
  48. set (SRCS ${SRCS} "FontTRLE.cpp")
  49. set (SRCS ${SRCS} "Game.cpp")
  50. set (SRCS ${SRCS} "main.cpp")
  51. set (SRCS ${SRCS} "Menu.cpp")
  52. set (SRCS ${SRCS} "Mesh.cpp")
  53. set (SRCS ${SRCS} "OpenRaider.cpp")
  54. set (SRCS ${SRCS} "Render.cpp")
  55. set (SRCS ${SRCS} "Room.cpp")
  56. set (SRCS ${SRCS} "RoomData.cpp")
  57. set (SRCS ${SRCS} "SkeletalModel.cpp")
  58. set (SRCS ${SRCS} "Sound.cpp")
  59. set (SRCS ${SRCS} "Sprite.cpp")
  60. set (SRCS ${SRCS} "StaticMesh.cpp")
  61. set (SRCS ${SRCS} "TextureManager.cpp")
  62. set (SRCS ${SRCS} "TombRaider.cpp")
  63. set (SRCS ${SRCS} "ViewVolume.cpp")
  64. set (SRCS ${SRCS} "Window.cpp")
  65. set (SRCS ${SRCS} "World.cpp")
  66. # Select available Sound library
  67. option (ENABLE_AUDIO "Enable Sound Output" YES)
  68. if (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
  69. set (SRCS ${SRCS} "SoundAL.cpp")
  70. set (USING_AL TRUE)
  71. else (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
  72. set (SRCS ${SRCS} "SoundNull.cpp")
  73. set (USING_AL FALSE)
  74. message (STATUS "Disabled Sound support (no OpenAL and ALUT)!")
  75. endif (OPENAL_FOUND AND ALUT_FOUND AND ENABLE_AUDIO)
  76. # Select available Windowing library
  77. if (SDL2_FOUND)
  78. set (SRCS ${SRCS} "WindowSDL.cpp")
  79. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL")
  80. if (SDL2TTF_FOUND)
  81. set (SRCS ${SRCS} "FontSDL.cpp")
  82. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUSING_SDL_FONT")
  83. endif (SDL2TTF_FOUND)
  84. else (SDL2_FOUND)
  85. message (FATAL_ERROR "SDL2 is required at the moment!")
  86. endif (SDL2_FOUND)
  87. if (PNG_FOUND)
  88. set (USING_PNG TRUE)
  89. else (PNG_FOUND)
  90. set (USING_PNG FALSE)
  91. endif (PNG_FOUND)
  92. #################################################################
  93. # Check for header/function presence
  94. include (CheckIncludeFiles)
  95. include (CheckFunctionExists)
  96. include (CheckSymbolExists)
  97. # backtrace() for assert with call stack output
  98. check_include_files (execinfo.h HAVE_EXECINFO_H)
  99. check_function_exists (backtrace HAVE_BACKTRACE)
  100. check_function_exists (backtrace_symbols HAVE_BACKTRACE_SYMBOLS)
  101. # readdir() for recursive folder traversal
  102. check_include_files (dirent.h HAVE_DIRENT_H)
  103. check_function_exists (opendir HAVE_OPENDIR)
  104. check_function_exists (readdir_r HAVE_READDIR_R)
  105. check_function_exists (closedir HAVE_CLOSEDIR)
  106. check_symbol_exists (DT_DIR "dirent.h" HAVE_DT_DIR)
  107. # gettimeofday() for timing
  108. check_include_files (sys/time.h HAVE_SYS_TIME_H)
  109. check_function_exists (gettimeofday HAVE_GETTIMEOFDAY)
  110. #################################################################
  111. # Configuration Header file
  112. configure_file (
  113. "${PROJECT_SOURCE_DIR}/include/config.h.in"
  114. "${PROJECT_BINARY_DIR}/config.h"
  115. )
  116. # Configuration Source file
  117. configure_file (
  118. "${PROJECT_SOURCE_DIR}/src/config.cpp.in"
  119. "${PROJECT_BINARY_DIR}/config.cpp"
  120. )
  121. set (SRCS ${SRCS} "${PROJECT_BINARY_DIR}/config.cpp")
  122. #################################################################
  123. # Apple specific bundling
  124. if (APPLE)
  125. # Mac Bundle Data
  126. set (MACOSX_BUNDLE_INFO_STRING "OpenSource TombRaider Game Engine")
  127. set (MACOSX_BUNDLE_ICON_FILE "AppIcon")
  128. set (MACOSX_BUNDLE_GUI_IDENTIFIER "de.xythobuz.OpenRaider")
  129. set (MACOSX_BUNDLE_BUNDLE_NAME "OpenRaider")
  130. set (MACOSX_BUNDLE_SHORT_VERSION_STRING "${OpenRaider_VERSION_MAJOR}.${OpenRaider_VERSION_MINOR}.${OpenRaider_VERSION_MICRO}${OpenRaider_VERSION_RELEASE}")
  131. set (MACOSX_BUNDLE_LONG_VERSION_STRING "${OpenRaider_VERSION_MAJOR}.${OpenRaider_VERSION_MINOR}.${OpenRaider_VERSION_MICRO}${OpenRaider_VERSION_RELEASE} (${CMAKE_BUILD_TYPE})")
  132. set (MACOSX_BUNDLE_BUNDLE_VERSION "${OpenRaider_VERSION_MAJOR}.${OpenRaider_VERSION_MINOR}.${OpenRaider_VERSION_MICRO}${OpenRaider_VERSION_RELEASE} (${CMAKE_BUILD_TYPE})")
  133. set (MACOSX_BUNDLE_COPYRIGHT "2001 - 2014")
  134. # Copy Icon
  135. set (MAC_ICON "../cmake/AppIcon.icns")
  136. set_source_files_properties (${MAC_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  137. set (RESRCS ${RESRCS} ${MAC_ICON})
  138. # Copy Data
  139. set (MAC_DATA "../data/font.pc" "../data/OpenRaider.ini" "../data/test.ttf" "../data/splash.tga")
  140. set_source_files_properties (${MAC_DATA} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/defaults)
  141. set (RESRCS ${RESRCS} ${MAC_DATA})
  142. endif (APPLE)
  143. #################################################################
  144. # Check for SSE, enable if available
  145. include (../cmake/FindSSE.cmake)
  146. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  147. if (SSE_FOUND)
  148. set (SSE_FOUND_MSG "${SSE_FOUND_MSG} SSE")
  149. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -msse")
  150. endif (SSE_FOUND)
  151. if (SSE2_FOUND)
  152. set (SSE_FOUND_MSG "${SSE_FOUND_MSG} SSE2")
  153. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -msse2")
  154. endif (SSE2_FOUND)
  155. if (SSE3_FOUND)
  156. set (SSE_FOUND_MSG "${SSE_FOUND_MSG} SSE3")
  157. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -msse3")
  158. endif (SSE3_FOUND)
  159. if (SSSE3_FOUND)
  160. set (SSE_FOUND_MSG "${SSE_FOUND_MSG} SSSE3")
  161. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -mssse3")
  162. endif (SSSE3_FOUND)
  163. if (SSE4_1_FOUND)
  164. set (SSE_FOUND_MSG "${SSE_FOUND_MSG} SSE4.1")
  165. set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -msse4.1")
  166. endif (SSE4_1_FOUND)
  167. # Display message if something is enabled
  168. if (NOT "${SSE_FOUND_MSG}" STREQUAL "")
  169. message (STATUS "Enabled${SSE_FOUND_MSG}...")
  170. endif (NOT "${SSE_FOUND_MSG}" STREQUAL "")
  171. endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  172. # Apply Flags
  173. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenRaider_CXX_FLAGS}")
  174. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OpenRaider_CXX_FLAGS} ${OpenRaider_CXX_FLAGS_DEBUG}")
  175. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OpenRaider_CXX_FLAGS} ${OpenRaider_CXX_FLAGS_RELEASE}")
  176. # Add subdirectories
  177. add_subdirectory ("deps")
  178. add_subdirectory ("math")
  179. add_subdirectory ("test")
  180. add_subdirectory ("utils")
  181. # Add Executable
  182. add_library (OpenRaider_all OBJECT ${SRCS})
  183. add_executable (OpenRaider MACOSX_BUNDLE ${RESRCS}
  184. $<TARGET_OBJECTS:OpenRaider_all> $<TARGET_OBJECTS:OpenRaider_deps>
  185. $<TARGET_OBJECTS:OpenRaider_math> $<TARGET_OBJECTS:OpenRaider_utils>
  186. )
  187. #################################################################
  188. if (APPLE)
  189. if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
  190. # Copy setup script
  191. add_custom_command (TARGET OpenRaider POST_BUILD
  192. COMMAND echo "Injecting setup script..."
  193. COMMAND cp "${PROJECT_SOURCE_DIR}/cmake/setup_mac.sh" "${PROJECT_BINARY_DIR}/src/OpenRaider.app/Contents/MacOS/OpenRaider.sh"
  194. COMMAND chmod "a+x" "${PROJECT_BINARY_DIR}/src/OpenRaider.app/Contents/MacOS/OpenRaider.sh"
  195. )
  196. # Fix executable name, so setup script will be called
  197. add_custom_command (TARGET OpenRaider POST_BUILD
  198. COMMAND echo "Changing executable name..."
  199. COMMAND /usr/libexec/PlistBuddy -c "Set :CFBundleExecutable OpenRaider.sh" Info.plist
  200. WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/OpenRaider.app/Contents
  201. )
  202. # Preparing the bundle on install
  203. # http://www.cmake.org/Wiki/BundleUtilitiesExample
  204. set (plugin_dest_dir OpenRaider.app/Contents/MacOS)
  205. set (APPS "${PROJECT_BINARY_DIR}/src/OpenRaider.app")
  206. install (CODE "
  207. file(GLOB_RECURSE PLUGINS
  208. \"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/plugins/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
  209. include(BundleUtilities)
  210. fixup_bundle(\"${APPS}\" \"\${PLUGINS}\" \"\")
  211. " COMPONENT Runtime
  212. )
  213. endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
  214. endif (APPLE)
  215. #################################################################
  216. if (NOT APPLE)
  217. # Install binary
  218. install (TARGETS OpenRaider
  219. RUNTIME DESTINATION bin
  220. )
  221. endif (NOT APPLE)
  222. #################################################################
  223. # Add Math Library
  224. if (UNIX)
  225. set (LIBS ${LIBS} m)
  226. endif (UNIX)
  227. # Link to all found libs
  228. target_link_libraries (OpenRaider ${LIBS})
  229. #################################################################
  230. # Add target to run executable
  231. if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles" OR ${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles")
  232. add_custom_target(run COMMAND OpenRaider DEPENDS OpenRaider WORKING_DIRECTORY ${CMAKE_PROJECT_DIR})
  233. endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles" OR ${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles")