CMakeLists.txt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. cmake_minimum_required (VERSION 2.8)
  2. project(HPL2)
  3. set(HPL2_VERSION_MAJOR 2)
  4. set(HPL2_VERSION_MINOR 0)
  5. set(HPL2_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
  6. set(DEP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/include" PARENT_SCOPE)
  7. set(DEP_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/lib/${BIN_LIBROOT}")
  8. set(DEP_LIB_DIR ${DEP_LIB_DIR} PARENT_SCOPE)
  9. IF(APPLE)
  10. SET(PRIVATE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../dependencies)
  11. SET(PRIVATE_LIB_SUFFIX "lib/macosx")
  12. ELSEIF(LINUX)
  13. SET(PRIVATE_LIB_SUFFIX "lib/${BIN_LIBROOT}")
  14. SET(PRIVATE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../dependencies)
  15. ENDIF()
  16. OPTION(USE_SDL2 "Use SDL2 instead of SDL1.2" ON)
  17. add_subdirectory(../dependencies/OALWrapper OALWrapper)
  18. IF(USE_SDL2)
  19. add_definitions(-DUSE_SDL2)
  20. SET(HPL2_DEFINES USE_SDL2 PARENT_SCOPE)
  21. ENDIF()
  22. add_definitions(
  23. -DUSE_OALWRAPPER
  24. )
  25. include_directories(
  26. include
  27. #Important that this is before dependencies so the correct OpenAL headers are used
  28. ${OALWRAPPER_INCLUDE_DIR}
  29. ../dependencies/include
  30. )
  31. IF(LINUX)
  32. add_library(binreloc STATIC ../dependencies/sources/binreloc/binreloc.c)
  33. set_target_properties(binreloc PROPERTIES COMPILE_DEFINITIONS "ENABLE_BINRELOC")
  34. include_directories(
  35. ../dependencies/sources/binreloc/
  36. )
  37. ENDIF()
  38. # common shared source
  39. file(GLOB common_sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  40. sources/ai/*
  41. sources/engine/*
  42. sources/generate/*
  43. sources/graphics/*
  44. sources/gui/*
  45. sources/haptic/*
  46. sources/input/*
  47. sources/math/*
  48. sources/physics/*
  49. sources/resources/*
  50. sources/scene/*
  51. sources/sound/*
  52. sources/system/*
  53. include/ai/*
  54. include/engine/*
  55. include/generate/*
  56. include/graphics/*
  57. include/gui/*
  58. include/haptic/*
  59. include/input/*
  60. include/math/*
  61. include/physics/*
  62. include/resources/*
  63. include/scene/*
  64. include/sound/*
  65. include/system/*
  66. include/*.*
  67. )
  68. list(APPEND common_sources include/BuildID_HPL2_0.h)
  69. list(REMOVE_DUPLICATES common_sources)
  70. #setup various IMPL sources
  71. file(GLOB impl_sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  72. include/impl/tinyXML/*
  73. include/impl/*.*
  74. # tinyXML
  75. sources/impl/tinyXml/*
  76. sources/impl/XmlDocumentTiny.cpp
  77. # scripting
  78. sources/impl/SqScript.cpp
  79. sources/impl/scriptarray.cpp
  80. sources/impl/scripthelper.cpp
  81. sources/impl/scriptstdstring.cpp
  82. sources/impl/scriptstdstring_utils.cpp
  83. # Image loading
  84. sources/impl/BitmapLoader*
  85. # theora video
  86. sources/impl/VideoStreamTheora.cpp
  87. # Newton
  88. sources/impl/*Newton.cpp
  89. # GL
  90. sources/impl/FrameBufferGL.cpp
  91. sources/impl/GLSL*
  92. sources/impl/OcclusionQueryOGL.cpp
  93. sources/impl/VertexBufferOGL_Array.cpp
  94. sources/impl/VertexBufferOGL_VBO.cpp
  95. sources/impl/VertexBufferOpenGL.cpp
  96. # SDL
  97. sources/impl/GamepadSDL.cpp
  98. sources/impl/GamepadSDL2.cpp
  99. sources/impl/KeyboardSDL.cpp
  100. sources/impl/MouseSDL.cpp
  101. sources/impl/MutexSDL.cpp
  102. sources/impl/ThreadSDL.cpp
  103. sources/impl/TimerSDL.cpp
  104. sources/impl/LowLevelGraphicsSDL.cpp
  105. sources/impl/LowLevelInputSDL.cpp
  106. sources/impl/LowLevelResourcesSDL.cpp
  107. sources/impl/LowLevelSystemSDL.cpp
  108. sources/impl/SDLEngineSetup.cpp
  109. sources/impl/SDLFontData.cpp
  110. sources/impl/SDLTexture.cpp
  111. # OpenAL
  112. sources/impl/LowLevelSoundOpenAL.cpp
  113. sources/impl/OpenAL*
  114. # mesh loader
  115. sources/impl/MeshLoaderCollada.cpp
  116. sources/impl/MeshLoaderColladaHelpers.cpp
  117. sources/impl/MeshLoaderColladaLoader.cpp
  118. sources/impl/MeshLoaderMSH.cpp
  119. sources/impl/MeshLoaderFBX.cpp
  120. )
  121. IF(APPLE)
  122. LIST(APPEND impl_sources
  123. sources/impl/PlatformMacOSX.mm
  124. sources/impl/PlatformUnix.cpp
  125. sources/impl/PlatformSDL.cpp
  126. )
  127. IF(NOT USE_SDL2)
  128. LIST(APPEND impl_sources
  129. SDLMain.m
  130. SDLMain.h
  131. )
  132. ENDIF()
  133. ELSEIF(LINUX)
  134. LIST(APPEND impl_sources
  135. sources/impl/PlatformUnix.cpp
  136. sources/impl/PlatformSDL.cpp
  137. )
  138. ENDIF()
  139. # Setup buildID source
  140. IF(APPLE)
  141. SET(VERSION_SUFFIX MacOSX)
  142. ELSEIF(LINUX)
  143. SET(VERSION_SUFFIX Linux)
  144. ENDIF()
  145. SET(version_source
  146. sources/BuildID_HPL2_0_${VERSION_SUFFIX}.cpp
  147. )
  148. set_property(
  149. SOURCE
  150. sources/BuildID_HPL2_0_${VERSION_SUFFIX}.cpp
  151. include/BuildID_HPL2_0.h
  152. PROPERTY
  153. GENERATED)
  154. set(BUILDCOUNTER_BIN "${CMAKE_CURRENT_SOURCE_DIR}/buildcounter.pl")
  155. set(BUILDCOUNTER_BIN ${BUILDCOUNTER_BIN} PARENT_SCOPE)
  156. add_custom_command(
  157. OUTPUT
  158. sources/BuildID_HPL2_0_${VERSION_SUFFIX}.cpp
  159. include/BuildID_HPL2_0.h
  160. COMMAND
  161. ${BUILDCOUNTER_BIN}
  162. ARGS
  163. HPL2_0 ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/sources
  164. )
  165. # setup source groups
  166. source_group("Implementation Specific" REGULAR_EXPRESSION "\\/impl\\/.+")
  167. source_group("TinyXML" REGULAR_EXPRESSION "\\/impl\\/tiny.+")
  168. source_group("SDL Specific" REGULAR_EXPRESSION "\\/impl\\/.*SDL.+")
  169. source_group("OpenGL Specific" REGULAR_EXPRESSION "\\/impl\\/.*GL.+")
  170. source_group("HaptX Specific" REGULAR_EXPRESSION "\\/impl\\/.+HaptX.+")
  171. source_group("Newton Specific" REGULAR_EXPRESSION "\\/impl\\/.+Newton.+")
  172. source_group("Mesh Loaders" REGULAR_EXPRESSION "\\/impl\\/Mesh.+")
  173. source_group("OpenAL Specific" REGULAR_EXPRESSION "\\/impl\\/.*OpenAL.+")
  174. source_group("Win32" REGULAR_EXPRESSION "\\/impl\\/.+Win32.+")
  175. source_group("Platform" REGULAR_EXPRESSION "\\/impl\\/Platform.+")
  176. # setup libs
  177. add_library(Newton STATIC IMPORTED)
  178. set_target_properties(Newton PROPERTIES IMPORTED_LOCATION ${DEP_LIB_DIR}/libNewton.a)
  179. add_library(angelscript STATIC IMPORTED)
  180. set_target_properties(angelscript PROPERTIES IMPORTED_LOCATION ${DEP_LIB_DIR}/libangelscript.a)
  181. add_library(FBX STATIC IMPORTED)
  182. set_target_properties(FBX PROPERTIES IMPORTED_LOCATION ${DEP_LIB_DIR}/libfbxsdk-2012.2-static.a)
  183. # setup HPL2 compile target
  184. add_library(HPL2 STATIC
  185. ${common_sources}
  186. ${version_sources}
  187. ${impl_sources}
  188. )
  189. if (LINUX)
  190. target_link_libraries(HPL2
  191. OALWrapper # also pulls in ogg,vorbis,SDL
  192. Newton angelscript binreloc
  193. GL GLU GLEW
  194. theora
  195. IL
  196. z
  197. pthread dl
  198. FBX
  199. )
  200. ELSEIF(APPLE)
  201. FIND_LIBRARY(OPENGL_LIBRARY OpenGL)
  202. FIND_LIBRARY(SC_LIBRARY SystemConfiguration)
  203. FIND_LIBRARY(THEORA_LIBRARY Theora PATHS ${DEP_LIB_DIR} NO_DEFAULT_PATH)
  204. FIND_LIBRARY(COCOA_LIBRARY Cocoa)
  205. target_link_libraries(HPL2
  206. OALWrapper
  207. GLEW
  208. z
  209. Newton
  210. angelscript
  211. IL
  212. FBX iconv ${SC_LIBRARY}
  213. ${THEORA_LIBRARY}
  214. ${OPENGL_LIBRARY}
  215. ${COCOA_LIBRARY}
  216. )
  217. # helper function to copy the needed frameworks in at build time
  218. SET(HPL2_LIBRARIES libSDL2.dylib libIL.1.dylib)
  219. SET(HPL2_LIBRARIES ${HPL2_LIBRARIES} PARENT_SCOPE)
  220. FUNCTION(PostBuildMacBundle APP_TARGET framework_list lib_list)
  221. INCLUDE(BundleUtilities)
  222. GET_TARGET_PROPERTY(_BIN_NAME ${APP_TARGET} LOCATION)
  223. GET_DOTAPP_DIR(${_BIN_NAME} _BUNDLE_DIR)
  224. set(_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${APP_TARGET}_prep.cmake)
  225. file(WRITE ${_SCRIPT_FILE}
  226. "# Generated Script file\n"
  227. "include(BundleUtilities)\n"
  228. "get_bundle_and_executable(\"\${BUNDLE_APP}\" bundle executable valid)\n"
  229. "if(valid)\n"
  230. " set(framework_path \"\${bundle}/Contents/Frameworks\")\n"
  231. " foreach(framework ${framework_list})\n"
  232. " file(MAKE_DIRECTORY \"\${framework_path}/\${framework}.framework/Versions/A/\")\n"
  233. " copy_resolved_framework_into_bundle(\${DEP_LIB_DIR}/\${framework}.framework/Versions/A/\${framework} \${framework_path}/\${framework}.framework/Versions/A/\${framework})\n"
  234. " endforeach()\n"
  235. " foreach(lib ${lib_list})\n"
  236. " copy_resolved_item_into_bundle(\${DEP_LIB_DIR}/\${lib} \${framework_path}/\${lib})\n"
  237. " endforeach()\n"
  238. "else()\n"
  239. " message(ERROR \"App Not found? \${BUNDLE_APP}\")\n"
  240. "endif()\n"
  241. "#fixup_bundle(\"\${BUNDLE_APP}\" \"\" \"\${DEP_LIB_DIR}\")\n"
  242. )
  243. ADD_CUSTOM_COMMAND(TARGET ${APP_TARGET}
  244. POST_BUILD
  245. COMMAND ${CMAKE_COMMAND} -DBUNDLE_APP="${_BUNDLE_DIR}" -DDEP_LIB_DIR="${DEP_LIB_DIR}" -P "${_SCRIPT_FILE}"
  246. )
  247. ENDFUNCTION()
  248. ENDIF()
  249. FUNCTION(AddTestTarget target_name)
  250. add_executable(${target_name} EXCLUDE_FROM_ALL
  251. ${ARGN}
  252. )
  253. target_link_libraries(${target_name} HPL2)
  254. set_target_properties(${target_name} PROPERTIES
  255. XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "${DEP_LIB_DIR}"
  256. INSTALL_RPATH "${DEP_LIB_DIR}"
  257. )
  258. ENDFUNCTION()
  259. add_subdirectory(../tools/editors editors)
  260. add_subdirectory(../tools/mshconverter mshconverter)