💿🐜 Antkeeper source code 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.

198 lines
6.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. cmake_minimum_required(VERSION 3.7)
  2. project(antkeeper
  3. VERSION "0.0.0"
  4. )
  5. set(PLATFORM "" CACHE STRING "")
  6. set(LANGUAGE "en-us" CACHE STRING "")
  7. # Setup configuration strings
  8. set(ANTKEEPER_VERSION ${PROJECT_VERSION})
  9. set(ANTKEEPER_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
  10. set(ANTKEEPER_VERSION_MINOR ${PROJECT_VERSION_MINOR})
  11. set(ANTKEEPER_VERSION_PATCH ${PROJECT_VERSION_PATCH})
  12. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  13. set(ANTKEEPER_BUILD_TYPE debug)
  14. set(ANTKEEPER_DEBUG ON)
  15. else()
  16. set(ANTKEEPER_BUILD_TYPE release)
  17. set(ANTKEEPER_DEBUG OFF)
  18. endif()
  19. # Setup build type paths
  20. set(BUILD_DIR ${PROJECT_SOURCE_DIR}/build)
  21. set(BUILD_DEBUG_DIR ${BUILD_DIR}/debug)
  22. set(BUILD_RELEASE_DIR ${BUILD_DIR}/release)
  23. # Set package name
  24. set(PACKAGE_NAME ${PROJECT_NAME}-${PROJECT_VERSION}-${PLATFORM})
  25. set(PACKAGE_BUILD_NAME ${PACKAGE_NAME}-${ANTKEEPER_BUILD_TYPE})
  26. # Set package directory
  27. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  28. set(PLATFORM_PACKAGE_DIR ${BUILD_DEBUG_DIR}/${PACKAGE_NAME})
  29. else()
  30. set(PLATFORM_PACKAGE_DIR ${BUILD_RELEASE_DIR}/${PACKAGE_NAME})
  31. endif()
  32. # Add Emergent library
  33. add_subdirectory(${PROJECT_SOURCE_DIR}/lib/emergent)
  34. set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${PROJECT_SOURCE_DIR}/lib/emergent)
  35. # Find dependencies
  36. set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
  37. find_package(SDL2 REQUIRED)
  38. find_package(OpenGL REQUIRED)
  39. # Set C++ compiler flags for debug and release build types
  40. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  41. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g")
  42. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -s -DNDEBUG -mwindows")
  43. # Set C and C++ compiler flags for the target architecture
  44. if(${PLATFORM} STREQUAL "win32" OR ${PLATFORM} STREQUAL "linux32")
  45. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
  46. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  47. elseif(${PLATFORM} STREQUAL "win64" OR ${PLATFORM} STREQUAL "linux64")
  48. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
  49. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
  50. elseif(${PLATFORM} STREQUAL "osx" AND CMAKE_OSX_ARCHITECTURES STREQUAL "")
  51. # 32-bit
  52. #set(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "" FORCE)
  53. # 64-bit
  54. #set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "" FORCE)
  55. # 96-bit universal
  56. set(CMAKE_OSX_ARCHITECTURES "x86_64;i386" CACHE STRING "" FORCE)
  57. endif()
  58. # Set C++ version
  59. set(CMAKE_CXX_STANDARD 11)
  60. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  61. set(CMAKE_CXX_EXTENSIONS OFF)
  62. # Find executable source directory
  63. set(EXECUTABLE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
  64. # Generate C++ configuration file
  65. configure_file(${EXECUTABLE_SOURCE_DIR}/configuration.hpp.in ${EXECUTABLE_SOURCE_DIR}/configuration.hpp)
  66. # Collect executable source files
  67. set(EXECUTABLE_SOURCES
  68. ${EXECUTABLE_SOURCE_DIR}/configuration.hpp
  69. ${EXECUTABLE_SOURCE_DIR}/windows-dirent.h
  70. ${EXECUTABLE_SOURCE_DIR}/controls.cpp
  71. ${EXECUTABLE_SOURCE_DIR}/render-passes.hpp
  72. ${EXECUTABLE_SOURCE_DIR}/settings.cpp
  73. ${EXECUTABLE_SOURCE_DIR}/settings.hpp
  74. ${EXECUTABLE_SOURCE_DIR}/game/terrain.cpp
  75. ${EXECUTABLE_SOURCE_DIR}/game/terrain.hpp
  76. ${EXECUTABLE_SOURCE_DIR}/controls.hpp
  77. ${EXECUTABLE_SOURCE_DIR}/input.cpp
  78. ${EXECUTABLE_SOURCE_DIR}/input.hpp
  79. ${EXECUTABLE_SOURCE_DIR}/main.cpp
  80. ${EXECUTABLE_SOURCE_DIR}/mesh.cpp
  81. ${EXECUTABLE_SOURCE_DIR}/mesh.hpp
  82. ${EXECUTABLE_SOURCE_DIR}/application-state.hpp
  83. ${EXECUTABLE_SOURCE_DIR}/application-state.cpp
  84. ${EXECUTABLE_SOURCE_DIR}/application.hpp
  85. ${EXECUTABLE_SOURCE_DIR}/application.cpp
  86. ${EXECUTABLE_SOURCE_DIR}/states/loading-state.hpp
  87. ${EXECUTABLE_SOURCE_DIR}/states/loading-state.cpp
  88. ${EXECUTABLE_SOURCE_DIR}/states/splash-state.hpp
  89. ${EXECUTABLE_SOURCE_DIR}/states/splash-state.cpp
  90. ${EXECUTABLE_SOURCE_DIR}/states/title-state.hpp
  91. ${EXECUTABLE_SOURCE_DIR}/states/title-state.cpp
  92. ${EXECUTABLE_SOURCE_DIR}/states/main-menu-state.hpp
  93. ${EXECUTABLE_SOURCE_DIR}/states/main-menu-state.cpp
  94. ${EXECUTABLE_SOURCE_DIR}/states/play-state.hpp
  95. ${EXECUTABLE_SOURCE_DIR}/states/play-state.cpp
  96. ${EXECUTABLE_SOURCE_DIR}/ui/ui.hpp
  97. ${EXECUTABLE_SOURCE_DIR}/ui/ui.cpp
  98. ${EXECUTABLE_SOURCE_DIR}/ui/tween.hpp
  99. ${EXECUTABLE_SOURCE_DIR}/ui/tween.cpp
  100. ${EXECUTABLE_SOURCE_DIR}/render-passes.cpp
  101. ${EXECUTABLE_SOURCE_DIR}/game/ant.hpp
  102. ${EXECUTABLE_SOURCE_DIR}/game/ant.cpp
  103. ${EXECUTABLE_SOURCE_DIR}/game/agent.hpp
  104. ${EXECUTABLE_SOURCE_DIR}/game/agent.cpp
  105. ${EXECUTABLE_SOURCE_DIR}/game/colony.hpp
  106. ${EXECUTABLE_SOURCE_DIR}/game/colony.cpp
  107. ${EXECUTABLE_SOURCE_DIR}/game/habitat.hpp
  108. ${EXECUTABLE_SOURCE_DIR}/game/habitat.cpp
  109. ${EXECUTABLE_SOURCE_DIR}/game/nest.hpp
  110. ${EXECUTABLE_SOURCE_DIR}/game/nest.cpp
  111. ${EXECUTABLE_SOURCE_DIR}/game/navmesh.hpp
  112. ${EXECUTABLE_SOURCE_DIR}/game/navmesh.cpp
  113. ${EXECUTABLE_SOURCE_DIR}/game/pheromone.hpp
  114. ${EXECUTABLE_SOURCE_DIR}/game/pheromone.cpp
  115. ${EXECUTABLE_SOURCE_DIR}/game/level.hpp
  116. ${EXECUTABLE_SOURCE_DIR}/game/level.cpp
  117. ${EXECUTABLE_SOURCE_DIR}/game/biome.hpp
  118. ${EXECUTABLE_SOURCE_DIR}/game/biome.cpp
  119. ${EXECUTABLE_SOURCE_DIR}/debug.hpp
  120. ${EXECUTABLE_SOURCE_DIR}/debug.cpp
  121. ${EXECUTABLE_SOURCE_DIR}/camera-controller.hpp
  122. ${EXECUTABLE_SOURCE_DIR}/camera-controller.cpp
  123. ${EXECUTABLE_SOURCE_DIR}/model-loader.hpp
  124. ${EXECUTABLE_SOURCE_DIR}/model-loader.cpp
  125. ${EXECUTABLE_SOURCE_DIR}/material-loader.hpp
  126. ${EXECUTABLE_SOURCE_DIR}/material-loader.cpp
  127. )
  128. # Setup exe icon for windows
  129. if(${PLATFORM} STREQUAL "win32" OR ${PLATFORM} STREQUAL "win64")
  130. if(EXISTS ${PROJECT_SOURCE_DIR}/data)
  131. set(RC_FILES "${PROJECT_SOURCE_DIR}/data/icons/icon.rc")
  132. set(CMAKE_RC_COMPILER_INIT windres)
  133. enable_language(RC)
  134. set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
  135. set(EXECUTABLE_SOURCES "${EXECUTABLE_SOURCES};${RC_FILES}")
  136. endif()
  137. endif()
  138. # Set executable and library output directories
  139. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PLATFORM_PACKAGE_DIR})
  140. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PLATFORM_PACKAGE_DIR})
  141. # Add executable
  142. set(EXECUTABLE_NAME antkeeper)
  143. set(EXECUTABLE_TARGET ${PACKAGE_BUILD_NAME}-executable)
  144. add_executable(${EXECUTABLE_TARGET} ${EXECUTABLE_SOURCES})
  145. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${EXECUTABLE_NAME})
  146. # Set include directories
  147. target_include_directories(${EXECUTABLE_TARGET} PUBLIC
  148. ${PROJECT_SOURCE_DIR}/lib/emergent/include
  149. ${SDL2_INCLUDE_DIRS}
  150. ${OPENGL_INCLUDE_DIRS}
  151. )
  152. message("SDL: ${SDL2_LIBRARIES}")
  153. # Build library list
  154. list(APPEND EXECUTABLE_LIBRARIES
  155. m
  156. #dl
  157. mingw32
  158. #PROBLEM IS LINKING TO STDC++!!!!!!!!!!!!!!!!
  159. #stdc++
  160. emergent
  161. ${SDL2_LIBRARIES}
  162. ${OPENGL_gl_LIBRARY}
  163. )
  164. # Link libraries
  165. target_link_libraries(${EXECUTABLE_TARGET} ${EXECUTABLE_LIBRARIES})
  166. # Add run target
  167. add_custom_target(run
  168. COMMAND ${EXECUTABLE_TARGET}
  169. DEPENDS ${EXECUTABLE_TARGET}
  170. WORKING_DIRECTORY ${PLATFORM_PACKAGE_DIR}
  171. )
  172. # Add data subdirectory (if it exists)
  173. if(EXISTS ${PROJECT_SOURCE_DIR}/data)
  174. add_subdirectory(${PROJECT_SOURCE_DIR}/data)
  175. endif()