🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

305 lines
10 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. # Prevent in-source builds
  2. if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
  3. message(FATAL_ERROR "In-source builds prohibited. Call CMake from a build/<platform> directory.")
  4. endif()
  5. cmake_minimum_required(VERSION 3.7)
  6. # Create superbuild project
  7. project(antkeeper-superbuild VERSION "0.0.1")
  8. # Setup package variables
  9. set(PACKAGE_NAME ${PROJECT_NAME})
  10. set(PACKAGE_VERSION ${PROJECT_VERSION})
  11. set(PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
  12. set(PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
  13. set(PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
  14. get_filename_component(PACKAGE_PLATFORM ${CMAKE_BINARY_DIR} NAME CACHE)
  15. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  16. set(PACKAGE_BUILD_TYPE debug)
  17. else()
  18. set(PACKAGE_BUILD_TYPE release)
  19. endif()
  20. set(PACKAGE_FILENAME ${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_PLATFORM})
  21. set(PACKAGE_INSTALL_DIR ${CMAKE_SOURCE_DIR}/bin/${PACKAGE_BUILD_TYPE}/${PACKAGE_FILENAME})
  22. set(PACKAGE_DIST_DIR ${CMAKE_SOURCE_DIR}/dist/${PACKAGE_BUILD_TYPE})
  23. # Create output directories
  24. file(MAKE_DIRECTORY ${PACKAGE_INSTALL_DIR})
  25. file(MAKE_DIRECTORY ${PACKAGE_DIST_DIR})
  26. # Check for architecture mismatches
  27. if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  28. if (PACKAGE_PLATFORM MATCHES "64$")
  29. message(FATAL_ERROR "Compiler architecture is 32-bit but target architecture is 64-bit.")
  30. endif()
  31. else()
  32. if (PACKAGE_PLATFORM MATCHES "32$")
  33. message(FATAL_ERROR "Compiler architecture is 64-bit but target architecture is 32-bit.")
  34. endif()
  35. endif()
  36. # Options
  37. set(BLENDER "blender" CACHE FILEPATH "Path to Blender executable")
  38. set(INKSCAPE "inkscape" CACHE FILEPATH "Path to Inkscape executable")
  39. # Set C++ compiler flags
  40. if(CMAKE_COMPILER_IS_GNUCC)
  41. set(CMAKE_CXX_FLAGS "-Wall -Wextra")
  42. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g")
  43. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
  44. elseif(MSVC)
  45. set(CMAKE_CXX_FLAGS "/W3 /MP /MT")
  46. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS}")
  47. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /Ox")
  48. endif()
  49. # Set C compiler flags
  50. set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
  51. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
  52. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
  53. # Setup module directories
  54. set(MODULE_SOURCE_DIR "${PROJECT_SOURCE_DIR}/modules")
  55. set(MODULE_BUILD_DIR "${PROJECT_BINARY_DIR}/modules/build")
  56. set(MODULE_INSTALL_DIR "${CMAKE_BINARY_DIR}/modules/install")
  57. # Include ExternalProject_Add macro
  58. include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
  59. # Build SDL2 module
  60. ExternalProject_Add(SDL2
  61. SOURCE_DIR ${MODULE_SOURCE_DIR}/SDL2
  62. BINARY_DIR ${MODULE_BUILD_DIR}/SDL2
  63. INSTALL_DIR ${MODULE_INSTALL_DIR}
  64. CMAKE_ARGS
  65. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  66. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  67. "-DSDL_SHARED=OFF"
  68. "-DSDL_STATIC=ON"
  69. "-LIBC=ON"
  70. "-DHAVE_LIBC=ON"
  71. "-DFORCE_STATIC_VCRT=ON"
  72. BUILD_ALWAYS 0)
  73. # Build OpenAL Soft module
  74. ExternalProject_Add(openal-soft
  75. SOURCE_DIR ${MODULE_SOURCE_DIR}/openal-soft
  76. BINARY_DIR ${MODULE_BUILD_DIR}/openal-soft
  77. INSTALL_DIR ${MODULE_INSTALL_DIR}
  78. CMAKE_ARGS
  79. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  80. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  81. "-DLIBTYPE=STATIC"
  82. "-DFORCE_STATIC_VCRT=ON"
  83. "-DALSOFT_UTILS=OFF"
  84. "-DALSOFT_EXAMPLES=OFF"
  85. "-DALSOFT_TESTS=OFF"
  86. BUILD_ALWAYS 0)
  87. # Build VMQ module
  88. ExternalProject_Add(vmq
  89. SOURCE_DIR ${MODULE_SOURCE_DIR}/vmq
  90. BINARY_DIR ${MODULE_BUILD_DIR}/vmq
  91. INSTALL_DIR ${MODULE_INSTALL_DIR}
  92. CMAKE_ARGS
  93. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  94. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  95. "-DBUILD_EXAMPLES=OFF"
  96. BUILD_ALWAYS 0)
  97. # Build EnTT module
  98. ExternalProject_Add(entt
  99. SOURCE_DIR ${MODULE_SOURCE_DIR}/entt
  100. BINARY_DIR ${MODULE_BUILD_DIR}/entt
  101. INSTALL_DIR ${MODULE_INSTALL_DIR}
  102. CMAKE_ARGS
  103. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  104. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  105. BUILD_ALWAYS 0)
  106. # Build nlohmann-json module
  107. ExternalProject_Add(nlohmann-json
  108. SOURCE_DIR ${MODULE_SOURCE_DIR}/nlohmann
  109. BINARY_DIR ${MODULE_BUILD_DIR}/nlohmann
  110. INSTALL_DIR ${MODULE_INSTALL_DIR}
  111. CMAKE_ARGS
  112. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  113. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  114. BUILD_ALWAYS 0)
  115. # Build dr_wav module
  116. ExternalProject_Add(dr_wav
  117. SOURCE_DIR ${MODULE_SOURCE_DIR}/dr_wav
  118. BINARY_DIR ${MODULE_BUILD_DIR}/dr_wav
  119. INSTALL_DIR ${MODULE_INSTALL_DIR}
  120. CMAKE_ARGS
  121. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  122. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  123. "-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}'"
  124. "-DCMAKE_C_FLAGS_DEBUG='${CMAKE_C_FLAGS_DEBUG}'"
  125. "-DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}'"
  126. BUILD_ALWAYS 0)
  127. # Build stb module
  128. ExternalProject_Add(stb
  129. SOURCE_DIR ${MODULE_SOURCE_DIR}/stb
  130. BINARY_DIR ${MODULE_BUILD_DIR}/stb
  131. INSTALL_DIR ${MODULE_INSTALL_DIR}
  132. CMAKE_ARGS
  133. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  134. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  135. "-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}'"
  136. "-DCMAKE_C_FLAGS_DEBUG='${CMAKE_C_FLAGS_DEBUG}'"
  137. "-DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}'"
  138. BUILD_ALWAYS 0)
  139. # Build glad module
  140. ExternalProject_Add(glad
  141. SOURCE_DIR ${MODULE_SOURCE_DIR}/glad
  142. BINARY_DIR ${MODULE_BUILD_DIR}/glad
  143. INSTALL_DIR ${MODULE_INSTALL_DIR}
  144. CMAKE_ARGS
  145. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  146. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  147. "-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}'"
  148. "-DCMAKE_C_FLAGS_DEBUG='${CMAKE_C_FLAGS_DEBUG}'"
  149. "-DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}'"
  150. BUILD_ALWAYS 0)
  151. # Build dirent module
  152. ExternalProject_Add(dirent
  153. SOURCE_DIR ${MODULE_SOURCE_DIR}/dirent
  154. BINARY_DIR ${MODULE_BUILD_DIR}/dirent
  155. INSTALL_DIR ${MODULE_INSTALL_DIR}
  156. CMAKE_ARGS
  157. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  158. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  159. "-DDIRENT_BUILD_TESTS=OFF"
  160. BUILD_ALWAYS 0)
  161. # Build PhysicsFS module
  162. ExternalProject_Add(physfs
  163. SOURCE_DIR ${MODULE_SOURCE_DIR}/physfs
  164. BINARY_DIR ${MODULE_BUILD_DIR}/physfs
  165. INSTALL_DIR ${MODULE_INSTALL_DIR}
  166. CMAKE_ARGS
  167. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  168. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  169. "-DPHYSFS_ARCHIVE_ZIP=ON"
  170. "-DPHYSFS_ARCHIVE_7Z=OFF"
  171. "-DPHYSFS_ARCHIVE_GRP=OFF"
  172. "-DPHYSFS_ARCHIVE_WAD=OFF"
  173. "-DPHYSFS_ARCHIVE_HOG=OFF"
  174. "-DPHYSFS_ARCHIVE_MVL=OFF"
  175. "-DPHYSFS_ARCHIVE_QPAK=OFF"
  176. "-DPHYSFS_ARCHIVE_SLB=OFF"
  177. "-DPHYSFS_ARCHIVE_ISO9660=OFF"
  178. "-DPHYSFS_ARCHIVE_VDF=OFF"
  179. "-DPHYSFS_BUILD_STATIC=ON"
  180. "-DPHYSFS_BUILD_SHARED=OFF"
  181. "-DPHYSFS_BUILD_TEST=OFF"
  182. "-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}'"
  183. "-DCMAKE_C_FLAGS_DEBUG='${CMAKE_C_FLAGS_DEBUG}'"
  184. "-DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}'"
  185. BUILD_ALWAYS 0)
  186. # Build antkeeper-source module
  187. ExternalProject_Add(antkeeper-source
  188. DEPENDS SDL2 openal-soft vmq entt nlohmann-json dr_wav stb glad physfs dirent
  189. SOURCE_DIR ${MODULE_SOURCE_DIR}/antkeeper-source
  190. BINARY_DIR ${MODULE_BUILD_DIR}/antkeeper-source
  191. INSTALL_DIR ${PACKAGE_INSTALL_DIR}
  192. CMAKE_ARGS
  193. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  194. "-DCMAKE_INSTALL_PREFIX=${PACKAGE_INSTALL_DIR}"
  195. "-DPACKAGE_PLATFORM=${PACKAGE_PLATFORM}"
  196. "-DCMAKE_PREFIX_PATH=${MODULE_INSTALL_DIR}"
  197. "-DVERSION_STRING=${PROJECT_VERSION}"
  198. "-DCMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}'"
  199. "-DCMAKE_CXX_FLAGS_DEBUG='${CMAKE_CXX_FLAGS_DEBUG}'"
  200. "-DCMAKE_CXX_FLAGS_RELEASE='${CMAKE_CXX_FLAGS_RELEASE}'"
  201. BUILD_ALWAYS 1)
  202. # Build antkeeper-data module
  203. ExternalProject_Add(antkeeper-data
  204. DEPENDS antkeeper-source
  205. SOURCE_DIR ${MODULE_SOURCE_DIR}/antkeeper-data
  206. BINARY_DIR ${MODULE_BUILD_DIR}/antkeeper-data
  207. INSTALL_DIR ${PACKAGE_INSTALL_DIR}
  208. CMAKE_ARGS
  209. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  210. "-DCMAKE_INSTALL_PREFIX=${PACKAGE_INSTALL_DIR}"
  211. "-DPACKAGE_PLATFORM=${PACKAGE_PLATFORM}"
  212. "-DCMAKE_PREFIX_PATH=${MODULE_INSTALL_DIR}"
  213. "-DBLENDER=${BLENDER}"
  214. "-DINKSCAPE=${INKSCAPE}"
  215. BUILD_ALWAYS 1)
  216. # Create install target
  217. install(DIRECTORY "${PACKAGE_INSTALL_DIR}/" DESTINATION . COMPONENT "package" USE_SOURCE_PERMISSIONS FILES_MATCHING PATTERN "*")
  218. # Create clean-build target
  219. add_custom_target(clean-build
  220. COMMAND git clean -fdX
  221. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
  222. # Create cpack target
  223. add_custom_target(cpack
  224. COMMAND "${CMAKE_COMMAND}" --build . --target package
  225. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  226. DEPENDS antkeeper-source
  227. VERBATIM)
  228. # Create dist target
  229. add_custom_target(dist DEPENDS cpack)
  230. # Configure CPack variables
  231. set(CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
  232. set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
  233. set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
  234. set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
  235. set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_PLATFORM}")
  236. set(CPACK_PACKAGE_DESCRIPTION "")
  237. set(CPACK_PACKAGE_CONTACT "Christopher J. Howard <cjhoward@cjhoward.org>")
  238. set(CPACK_COMPONENTS_ALL "package")
  239. # Configure .tgz and .zip distribution packages
  240. set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
  241. #set(CPACK_ARCHIVE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.zip")
  242. #set(CPACK_ARCHIVE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.zip")
  243. # Configure .deb distribution package
  244. set(CPACK_DEB_COMPONENT_INSTALL ON)
  245. set(CPACK_DEBIAN_PACKAGE_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
  246. set(CPACK_DEBIAN_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.deb")
  247. set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
  248. # Configure NSIS installer package
  249. #set(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/data/icons/app-icon.ico")
  250. #set(CPACK_PACKAGE_INSTALL_DIRECTORY "App")
  251. # Build distribution packages according to target platform
  252. set(CPACK_GENERATOR "")
  253. if(PACKAGE_PLATFORM MATCHES "linux")
  254. set(CPACK_GENERATOR "TGZ;DEB")
  255. add_custom_command(TARGET dist
  256. COMMAND ${CMAKE_COMMAND} -E make_directory ${PACKAGE_DIST_DIR}
  257. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}-package.tar.gz" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.tar.gz"
  258. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_DEBIAN_PACKAGE_FILE_NAME}" "${PACKAGE_DIST_DIR}")
  259. elseif(PACKAGE_PLATFORM MATCHES "win")
  260. set(CPACK_GENERATOR "ZIP;NSIS")
  261. add_custom_command(TARGET dist
  262. COMMAND ${CMAKE_COMMAND} -E make_directory ${PACKAGE_DIST_DIR}
  263. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}-package.zip" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.zip"
  264. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}.exe" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.exe")
  265. elseif(PACKAGE_PLATFORM MATCHES "osx")
  266. set(CPACK_GENERATOR "ZIP;NSIS")
  267. add_custom_command(TARGET dist
  268. COMMAND ${CMAKE_COMMAND} -E make_directory ${PACKAGE_DIST_DIR}
  269. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}-package.zip" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.zip")
  270. endif()
  271. # Include CPack macro
  272. include(CPack)