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

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