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

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