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

230 lines
7.9 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
  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 the build 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. # Check for architecture mismatches
  24. if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  25. if (PACKAGE_PLATFORM MATCHES "64$")
  26. message(FATAL_ERROR "Compiler architecture is 32-bit but target architecture is 64-bit.")
  27. endif()
  28. else()
  29. if (PACKAGE_PLATFORM MATCHES "32$")
  30. message(FATAL_ERROR "Compiler architecture is 64-bit but target architecture is 32-bit.")
  31. endif()
  32. endif()
  33. # Options
  34. set(BLENDER "blender" CACHE FILEPATH "Path to Blender executable")
  35. set(INKSCAPE "inkscape" CACHE FILEPATH "Path to Inkscape executable")
  36. # Setup module directories
  37. set(MODULE_SOURCE_DIR "${PROJECT_SOURCE_DIR}/modules")
  38. set(MODULE_BUILD_DIR "${PROJECT_BINARY_DIR}/modules/build")
  39. set(MODULE_INSTALL_DIR "${CMAKE_BINARY_DIR}/modules/install")
  40. # Include ExternalProject_Add macro
  41. include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
  42. # Build SDL2 module
  43. ExternalProject_Add(SDL2
  44. SOURCE_DIR ${MODULE_SOURCE_DIR}/SDL2
  45. BINARY_DIR ${MODULE_BUILD_DIR}/SDL2
  46. INSTALL_DIR ${MODULE_INSTALL_DIR}
  47. CMAKE_ARGS
  48. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  49. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  50. BUILD_ALWAYS 0)
  51. # Build OpenAL Soft module
  52. ExternalProject_Add(openal-soft
  53. SOURCE_DIR ${MODULE_SOURCE_DIR}/openal-soft
  54. BINARY_DIR ${MODULE_BUILD_DIR}/openal-soft
  55. INSTALL_DIR ${MODULE_INSTALL_DIR}
  56. CMAKE_ARGS
  57. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  58. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  59. "-DLIBTYPE=SHARED"
  60. "-DALSOFT_UTILS=OFF"
  61. "-DALSOFT_EXAMPLES=OFF"
  62. "-DALSOFT_TESTS=OFF"
  63. BUILD_ALWAYS 0)
  64. # Build VMQ module
  65. ExternalProject_Add(vmq
  66. SOURCE_DIR ${MODULE_SOURCE_DIR}/vmq
  67. BINARY_DIR ${MODULE_BUILD_DIR}/vmq
  68. INSTALL_DIR ${MODULE_INSTALL_DIR}
  69. CMAKE_ARGS
  70. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  71. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  72. "-DBUILD_EXAMPLES=OFF"
  73. BUILD_ALWAYS 0)
  74. # Build EnTT module
  75. ExternalProject_Add(entt
  76. SOURCE_DIR ${MODULE_SOURCE_DIR}/entt
  77. BINARY_DIR ${MODULE_BUILD_DIR}/entt
  78. INSTALL_DIR ${MODULE_INSTALL_DIR}
  79. CMAKE_ARGS
  80. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  81. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  82. BUILD_ALWAYS 0)
  83. # Build nlohmann-json module
  84. ExternalProject_Add(nlohmann-json
  85. SOURCE_DIR ${MODULE_SOURCE_DIR}/nlohmann
  86. BINARY_DIR ${MODULE_BUILD_DIR}/nlohmann
  87. INSTALL_DIR ${MODULE_INSTALL_DIR}
  88. CMAKE_ARGS
  89. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  90. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  91. BUILD_ALWAYS 0)
  92. # Build dr_wav module
  93. ExternalProject_Add(dr_wav
  94. SOURCE_DIR ${MODULE_SOURCE_DIR}/dr_wav
  95. BINARY_DIR ${MODULE_BUILD_DIR}/dr_wav
  96. INSTALL_DIR ${MODULE_INSTALL_DIR}
  97. CMAKE_ARGS
  98. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  99. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  100. BUILD_ALWAYS 0)
  101. # Build stb module
  102. ExternalProject_Add(stb
  103. SOURCE_DIR ${MODULE_SOURCE_DIR}/stb
  104. BINARY_DIR ${MODULE_BUILD_DIR}/stb
  105. INSTALL_DIR ${MODULE_INSTALL_DIR}
  106. CMAKE_ARGS
  107. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  108. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  109. BUILD_ALWAYS 0)
  110. # Build glad module
  111. ExternalProject_Add(glad
  112. SOURCE_DIR ${MODULE_SOURCE_DIR}/glad
  113. BINARY_DIR ${MODULE_BUILD_DIR}/glad
  114. INSTALL_DIR ${MODULE_INSTALL_DIR}
  115. CMAKE_ARGS
  116. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  117. "-DCMAKE_INSTALL_PREFIX=${MODULE_INSTALL_DIR}"
  118. BUILD_ALWAYS 0)
  119. # Build antkeeper-source module
  120. ExternalProject_Add(antkeeper-source
  121. DEPENDS SDL2 openal-soft vmq entt nlohmann-json dr_wav stb glad
  122. SOURCE_DIR ${MODULE_SOURCE_DIR}/antkeeper-source
  123. BINARY_DIR ${MODULE_BUILD_DIR}/antkeeper-source
  124. INSTALL_DIR ${PACKAGE_INSTALL_DIR}
  125. CMAKE_ARGS
  126. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  127. "-DCMAKE_INSTALL_PREFIX=${PACKAGE_INSTALL_DIR}"
  128. "-DPACKAGE_PLATFORM=${PACKAGE_PLATFORM}"
  129. "-DCMAKE_PREFIX_PATH=${MODULE_INSTALL_DIR}"
  130. "-DVERSION_STRING=${PROJECT_VERSION}"
  131. BUILD_ALWAYS 1)
  132. # Build antkeeper-data module
  133. ExternalProject_Add(antkeeper-data
  134. DEPENDS antkeeper-source
  135. SOURCE_DIR ${MODULE_SOURCE_DIR}/antkeeper-data
  136. BINARY_DIR ${MODULE_BUILD_DIR}/antkeeper-data
  137. INSTALL_DIR ${PACKAGE_INSTALL_DIR}
  138. CMAKE_ARGS
  139. "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  140. "-DCMAKE_INSTALL_PREFIX=${PACKAGE_INSTALL_DIR}"
  141. "-DPACKAGE_PLATFORM=${PACKAGE_PLATFORM}"
  142. "-DCMAKE_PREFIX_PATH=${MODULE_INSTALL_DIR}"
  143. "-DBLENDER=${BLENDER}"
  144. "-DINKSCAPE=${INKSCAPE}"
  145. BUILD_ALWAYS 1)
  146. # Create install target
  147. install(DIRECTORY "${PACKAGE_INSTALL_DIR}/" DESTINATION . COMPONENT "package" USE_SOURCE_PERMISSIONS FILES_MATCHING PATTERN "*")
  148. # Create clean-build target
  149. add_custom_target(clean-build
  150. COMMAND git clean -fdX
  151. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
  152. # Create cpack target
  153. add_custom_target(cpack
  154. COMMAND "${CMAKE_COMMAND}" --build . --target package
  155. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  156. DEPENDS antkeeper-source
  157. VERBATIM)
  158. # Create dist target
  159. add_custom_target(dist DEPENDS cpack)
  160. # Configure CPack variables
  161. set(CPACK_PACKAGE_NAME "${PACKAGE_NAME}")
  162. set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
  163. set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
  164. set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
  165. set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_PLATFORM}")
  166. set(CPACK_PACKAGE_DESCRIPTION "")
  167. set(CPACK_PACKAGE_CONTACT "Christopher J. Howard <cjhoward@cjhoward.org>")
  168. set(CPACK_COMPONENTS_ALL "package")
  169. # Configure .tgz and .zip distribution packages
  170. set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
  171. #set(CPACK_ARCHIVE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.zip")
  172. #set(CPACK_ARCHIVE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.zip")
  173. # Configure .deb distribution package
  174. set(CPACK_DEB_COMPONENT_INSTALL ON)
  175. set(CPACK_DEBIAN_PACKAGE_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
  176. set(CPACK_DEBIAN_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.deb")
  177. set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
  178. # Configure NSIS installer package
  179. #set(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/data/icons/app-icon.ico")
  180. #set(CPACK_PACKAGE_INSTALL_DIRECTORY "App")
  181. # Build distribution packages according to target platform
  182. set(CPACK_GENERATOR "")
  183. if(PACKAGE_PLATFORM MATCHES "linux")
  184. set(CPACK_GENERATOR "TGZ;DEB")
  185. add_custom_command(TARGET dist
  186. COMMAND ${CMAKE_COMMAND} -E make_directory ${PACKAGE_DIST_DIR}
  187. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}-package.tar.gz" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.tar.gz"
  188. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_DEBIAN_PACKAGE_FILE_NAME}" "${PACKAGE_DIST_DIR}")
  189. elseif(PACKAGE_PLATFORM MATCHES "win")
  190. set(CPACK_GENERATOR "ZIP;NSIS")
  191. add_custom_command(TARGET dist
  192. COMMAND ${CMAKE_COMMAND} -E make_directory ${PACKAGE_DIST_DIR}
  193. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}-package.zip" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.zip"
  194. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}.exe" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.exe")
  195. elseif(PACKAGE_PLATFORM MATCHES "osx")
  196. set(CPACK_GENERATOR "ZIP;NSIS")
  197. add_custom_command(TARGET dist
  198. COMMAND ${CMAKE_COMMAND} -E make_directory ${PACKAGE_DIST_DIR}
  199. COMMAND ${CMAKE_COMMAND} -E copy "${CPACK_PACKAGE_FILE_NAME}-package.zip" "${PACKAGE_DIST_DIR}/${PACKAGE_FILENAME}.zip")
  200. endif()
  201. # Include CPack macro
  202. include(CPack)