🛠️🐜 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.

308 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
  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 EnTT module
  88. ExternalProject_Add(entt
  89. SOURCE_DIR ${MODULE_SOURCE_DIR}/entt
  90. BINARY_DIR ${MODULE_BUILD_DIR}/entt
  91. INSTALL_DIR ${MODULE_INSTALL_DIR}
  92. CMAKE_ARGS
  93. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  94. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  95. BUILD_ALWAYS 0)
  96. # Build nlohmann-json module
  97. ExternalProject_Add(nlohmann-json
  98. SOURCE_DIR ${MODULE_SOURCE_DIR}/nlohmann
  99. BINARY_DIR ${MODULE_BUILD_DIR}/nlohmann
  100. INSTALL_DIR ${MODULE_INSTALL_DIR}
  101. CMAKE_ARGS
  102. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  103. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  104. BUILD_ALWAYS 0)
  105. # Build dr_wav module
  106. ExternalProject_Add(dr_wav
  107. SOURCE_DIR ${MODULE_SOURCE_DIR}/dr_wav
  108. BINARY_DIR ${MODULE_BUILD_DIR}/dr_wav
  109. INSTALL_DIR ${MODULE_INSTALL_DIR}
  110. CMAKE_ARGS
  111. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  112. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  113. "-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}'"
  114. "-DCMAKE_C_FLAGS_DEBUG='${CMAKE_C_FLAGS_DEBUG}'"
  115. "-DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}'"
  116. BUILD_ALWAYS 0)
  117. # Build stb module
  118. ExternalProject_Add(stb
  119. SOURCE_DIR ${MODULE_SOURCE_DIR}/stb
  120. BINARY_DIR ${MODULE_BUILD_DIR}/stb
  121. INSTALL_DIR ${MODULE_INSTALL_DIR}
  122. CMAKE_ARGS
  123. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  124. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  125. "-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}'"
  126. "-DCMAKE_C_FLAGS_DEBUG='${CMAKE_C_FLAGS_DEBUG}'"
  127. "-DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}'"
  128. BUILD_ALWAYS 0)
  129. # Build glad module
  130. ExternalProject_Add(glad
  131. SOURCE_DIR ${MODULE_SOURCE_DIR}/glad
  132. BINARY_DIR ${MODULE_BUILD_DIR}/glad
  133. INSTALL_DIR ${MODULE_INSTALL_DIR}
  134. CMAKE_ARGS
  135. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  136. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  137. "-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}'"
  138. "-DCMAKE_C_FLAGS_DEBUG='${CMAKE_C_FLAGS_DEBUG}'"
  139. "-DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}'"
  140. BUILD_ALWAYS 0)
  141. # Build dirent module
  142. ExternalProject_Add(dirent
  143. SOURCE_DIR ${MODULE_SOURCE_DIR}/dirent
  144. BINARY_DIR ${MODULE_BUILD_DIR}/dirent
  145. INSTALL_DIR ${MODULE_INSTALL_DIR}
  146. CMAKE_ARGS
  147. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  148. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  149. "-DDIRENT_BUILD_TESTS=OFF"
  150. BUILD_ALWAYS 0)
  151. # Build cxxopts module
  152. ExternalProject_Add(cxxopts
  153. SOURCE_DIR ${MODULE_SOURCE_DIR}/cxxopts
  154. BINARY_DIR ${MODULE_BUILD_DIR}/cxxopts
  155. INSTALL_DIR ${MODULE_INSTALL_DIR}
  156. CMAKE_ARGS
  157. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  158. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  159. "-DCXXOPTS_BUILD_EXAMPLES=OFF"
  160. "-DCXXOPTS_BUILD_TESTS=OFF"
  161. BUILD_ALWAYS 0)
  162. # Build PhysicsFS module
  163. ExternalProject_Add(physfs
  164. SOURCE_DIR ${MODULE_SOURCE_DIR}/physfs
  165. BINARY_DIR ${MODULE_BUILD_DIR}/physfs
  166. INSTALL_DIR ${MODULE_INSTALL_DIR}
  167. CMAKE_ARGS
  168. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  169. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  170. "-DPHYSFS_ARCHIVE_ZIP=ON"
  171. "-DPHYSFS_ARCHIVE_7Z=OFF"
  172. "-DPHYSFS_ARCHIVE_GRP=OFF"
  173. "-DPHYSFS_ARCHIVE_WAD=OFF"
  174. "-DPHYSFS_ARCHIVE_HOG=OFF"
  175. "-DPHYSFS_ARCHIVE_MVL=OFF"
  176. "-DPHYSFS_ARCHIVE_QPAK=OFF"
  177. "-DPHYSFS_ARCHIVE_SLB=OFF"
  178. "-DPHYSFS_ARCHIVE_ISO9660=OFF"
  179. "-DPHYSFS_ARCHIVE_VDF=OFF"
  180. "-DPHYSFS_BUILD_STATIC=ON"
  181. "-DPHYSFS_BUILD_SHARED=OFF"
  182. "-DPHYSFS_BUILD_TEST=OFF"
  183. "-DCMAKE_C_FLAGS='${CMAKE_C_FLAGS}'"
  184. "-DCMAKE_C_FLAGS_DEBUG='${CMAKE_C_FLAGS_DEBUG}'"
  185. "-DCMAKE_C_FLAGS_RELEASE='${CMAKE_C_FLAGS_RELEASE}'"
  186. BUILD_ALWAYS 0)
  187. # Build antkeeper-source module
  188. ExternalProject_Add(antkeeper-source
  189. DEPENDS SDL2 openal-soft entt nlohmann-json dr_wav stb glad physfs dirent
  190. SOURCE_DIR ${MODULE_SOURCE_DIR}/antkeeper-source
  191. BINARY_DIR ${MODULE_BUILD_DIR}/antkeeper-source
  192. INSTALL_DIR ${PACKAGE_INSTALL_DIR}
  193. CMAKE_ARGS
  194. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  195. "-DCMAKE_INSTALL_PREFIX=${PACKAGE_INSTALL_DIR}"
  196. "-DPACKAGE_PLATFORM=${PACKAGE_PLATFORM}"
  197. "-DCMAKE_PREFIX_PATH=${MODULE_INSTALL_DIR}"
  198. "-DVERSION_STRING=${PROJECT_VERSION}"
  199. "-DCMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}'"
  200. "-DCMAKE_CXX_FLAGS_DEBUG='${CMAKE_CXX_FLAGS_DEBUG}'"
  201. "-DCMAKE_CXX_FLAGS_RELEASE='${CMAKE_CXX_FLAGS_RELEASE}'"
  202. BUILD_ALWAYS 1)
  203. # Build antkeeper-data module (if exists)
  204. if(EXISTS ${MODULE_SOURCE_DIR}/antkeeper-data/CMakeLists.txt)
  205. ExternalProject_Add(antkeeper-data
  206. DEPENDS antkeeper-source
  207. SOURCE_DIR ${MODULE_SOURCE_DIR}/antkeeper-data
  208. BINARY_DIR ${MODULE_BUILD_DIR}/antkeeper-data
  209. INSTALL_DIR ${PACKAGE_INSTALL_DIR}
  210. CMAKE_ARGS
  211. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  212. "-DCMAKE_INSTALL_PREFIX=${PACKAGE_INSTALL_DIR}"
  213. "-DPACKAGE_PLATFORM=${PACKAGE_PLATFORM}"
  214. "-DCMAKE_PREFIX_PATH=${MODULE_INSTALL_DIR}"
  215. "-DBLENDER=${BLENDER}"
  216. "-DINKSCAPE=${INKSCAPE}"
  217. BUILD_ALWAYS 1)
  218. endif()
  219. # Create install target
  220. install(DIRECTORY "${PACKAGE_INSTALL_DIR}/" DESTINATION . COMPONENT "package" USE_SOURCE_PERMISSIONS FILES_MATCHING PATTERN "*")
  221. # Create clean-build target
  222. add_custom_target(clean-build
  223. COMMAND git clean -fdX
  224. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
  225. # Create cpack target
  226. add_custom_target(cpack
  227. COMMAND "${CMAKE_COMMAND}" --build . --target package
  228. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  229. DEPENDS antkeeper-source
  230. VERBATIM)
  231. # Create dist target
  232. add_custom_target(dist DEPENDS cpack)
  233. # Configure CPack variables
  234. set(CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
  235. set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
  236. set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
  237. set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
  238. set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_PLATFORM}")
  239. set(CPACK_PACKAGE_DESCRIPTION "")
  240. set(CPACK_PACKAGE_CONTACT "Christopher J. Howard <cjhoward@cjhoward.org>")
  241. set(CPACK_COMPONENTS_ALL "package")
  242. # Configure .tgz and .zip distribution packages
  243. set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
  244. #set(CPACK_ARCHIVE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.zip")
  245. #set(CPACK_ARCHIVE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.zip")
  246. # Configure .deb distribution package
  247. set(CPACK_DEB_COMPONENT_INSTALL ON)
  248. set(CPACK_DEBIAN_PACKAGE_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
  249. set(CPACK_DEBIAN_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.deb")
  250. set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
  251. # Configure NSIS installer package
  252. #set(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/data/icons/app-icon.ico")
  253. #set(CPACK_PACKAGE_INSTALL_DIRECTORY "App")
  254. # Build distribution packages according to target platform
  255. set(CPACK_GENERATOR "")
  256. if(PACKAGE_PLATFORM MATCHES "linux")
  257. set(CPACK_GENERATOR "TGZ;DEB")
  258. add_custom_command(TARGET dist
  259. COMMAND ${CMAKE_COMMAND} -E make_directory ${PACKAGE_DIST_DIR}
  260. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}-package.tar.gz" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.tar.gz"
  261. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_DEBIAN_PACKAGE_FILE_NAME}" "${PACKAGE_DIST_DIR}")
  262. elseif(PACKAGE_PLATFORM MATCHES "win")
  263. set(CPACK_GENERATOR "ZIP;NSIS")
  264. add_custom_command(TARGET dist
  265. COMMAND ${CMAKE_COMMAND} -E make_directory ${PACKAGE_DIST_DIR}
  266. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}-package.zip" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.zip"
  267. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}.exe" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.exe")
  268. elseif(PACKAGE_PLATFORM MATCHES "osx")
  269. set(CPACK_GENERATOR "ZIP;NSIS")
  270. add_custom_command(TARGET dist
  271. COMMAND ${CMAKE_COMMAND} -E make_directory ${PACKAGE_DIST_DIR}
  272. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}-package.zip" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.zip")
  273. endif()
  274. # Include CPack macro
  275. include(CPack)