116 lines
3.4 KiB
CMake
116 lines
3.4 KiB
CMake
cmake_minimum_required(VERSION 3.18)
|
|
set(NAME "GameOfLifeEditor")
|
|
project(${NAME} CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
if(WIN32)
|
|
set(IMGUI_BACKEND "imgui_impl_dx11.cpp") # DirectX 11 for Windows
|
|
elseif(APPLE)
|
|
set(IMGUI_BACKEND "imgui_impl_metal.mm") # Metal for macOS
|
|
elseif(UNIX)
|
|
set(IMGUI_BACKEND "imgui_impl_opengl3.cpp") # OpenGL for Linux
|
|
endif()
|
|
|
|
# includes
|
|
include_directories(./includes)
|
|
|
|
# raylib
|
|
include(FetchContent)
|
|
FetchContent_Declare(
|
|
raylib
|
|
GIT_REPOSITORY https://github.com/raysan5/raylib.git
|
|
GIT_TAG 5.5
|
|
GIT_SHALLOW 1
|
|
)
|
|
FetchContent_GetProperties(raylib)
|
|
if (NOT raylib_POPULATED)
|
|
set(FETCHCONTENT_QUIET NO)
|
|
FetchContent_Populate(raylib)
|
|
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
|
set(BUILD_GAMES OFF CACHE BOOL "" FORCE)
|
|
add_subdirectory(${raylib_SOURCE_DIR} ${raylib_BINARY_DIR})
|
|
endif()
|
|
|
|
# imgui
|
|
FetchContent_Declare(
|
|
imgui
|
|
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
|
GIT_TAG docking
|
|
)
|
|
|
|
FetchContent_MakeAvailable(imgui)
|
|
|
|
set(imgui_SOURCE_DIR ${CMAKE_BINARY_DIR}/_deps/imgui-src)
|
|
|
|
# rlimgui
|
|
FetchContent_Declare(
|
|
rlImGui
|
|
GIT_REPOSITORY https://github.com/raylib-extras/rlImGui.git
|
|
GIT_TAG main
|
|
)
|
|
FetchContent_MakeAvailable(rlImGui)
|
|
set(rlImGui_SOURCE_DIR ${CMAKE_BINARY_DIR}/_deps/rlimgui-src)
|
|
|
|
|
|
# nlohmann::json
|
|
FetchContent_Declare(
|
|
json
|
|
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
|
GIT_TAG v3.11.3
|
|
)
|
|
FetchContent_MakeAvailable(json)
|
|
|
|
include_directories(${imgui_SOURCE_DIR} ${rlImGui_SOURCE_DIR})
|
|
|
|
set(SRC_CXX_FILES "./src/main.cpp"
|
|
"./src/rules.cpp"
|
|
"./src/world.cpp"
|
|
"./src/grid.cpp"
|
|
"./src/render.cpp"
|
|
"./src/control_menu.cpp"
|
|
"./src/settings_menu.cpp"
|
|
"./src/selection_menu.cpp"
|
|
"./src/selection.cpp"
|
|
"./src/paterns_menu.cpp"
|
|
"./src/patern_preview.cpp"
|
|
"./src/snapping.cpp"
|
|
"${rlImGui_SOURCE_DIR}/rlImGui.cpp"
|
|
"${imgui_SOURCE_DIR}/imgui.cpp"
|
|
"${imgui_SOURCE_DIR}/imgui_draw.cpp"
|
|
"${imgui_SOURCE_DIR}/imgui_widgets.cpp"
|
|
"${imgui_SOURCE_DIR}/imgui_tables.cpp"
|
|
"${imgui_SOURCE_DIR}/backends/${IMGUI_BACKEND}"
|
|
)
|
|
|
|
# Setup the example
|
|
add_executable(${NAME} ${SRC_CXX_FILES})
|
|
|
|
# Link raylib and raylib-cpp
|
|
target_link_libraries(${NAME} PUBLIC raylib nlohmann_json::nlohmann_json)
|
|
|
|
# Windows cross-compilation rule
|
|
|
|
if (NOT DEFINED CMAKE_CROSSCOMPILE_WINDOWS_HELPER_ADDED)
|
|
set(CMAKE_CROSSCOMPILE_WINDOWS_HELPER_ADDED TRUE)
|
|
|
|
set(WIN_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/toolchain-mingw-w64-x86_64.cmake" CACHE PATH "Toolchain for Win x86_64")
|
|
|
|
add_custom_target(cmake-win
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Configuring Windows x86_64 build in: ${CMAKE_SOURCE_DIR}/build-win-x86_64"
|
|
COMMAND ${CMAKE_COMMAND}
|
|
-S ${CMAKE_SOURCE_DIR}
|
|
-B ${CMAKE_SOURCE_DIR}/build-win-x86_64
|
|
-G "Ninja"
|
|
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
|
-DCMAKE_TOOLCHAIN_FILE=${WIN_TOOLCHAIN_FILE}
|
|
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_SOURCE_DIR}/build-win-x86_64 -- -v
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
COMMENT "Configure & build for Windows x86_64 (MinGW-w64)"
|
|
VERBATIM
|
|
)
|
|
endif()
|