aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorLeander Scherer <leander@schererleander.de>2026-03-18 13:44:51 +0100
committerLeander Scherer <leander@schererleander.de>2026-03-18 13:44:51 +0100
commit8b8afbe19983fc8f854b326b242308d402ee8f30 (patch)
tree6c34efb1888afb908f1f8ee756df9014f303ccf0 /CMakeLists.txt
parent0adca22d9e86130dfbcbfe2fc021710a8d45a927 (diff)
feat(build): change build system from make to cmakeHEADmain
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt78
1 files changed, 78 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..6779659
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,78 @@
+cmake_minimum_required(VERSION 3.10)
+project(dungeon_crawler VERSION 0.1.0 LANGUAGES C)
+
+set(CMAKE_C_STANDARD 99)
+set(CMAKE_C_STANDARD_REQUIRED ON)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+
+option(USE_NIX "Use Nix-provided dependencies instead of FetchContent" OFF)
+
+if(USE_NIX)
+ find_package(raylib 5.5 REQUIRED)
+else()
+ include(FetchContent)
+ FetchContent_Declare(
+ raylib
+ GIT_REPOSITORY https://github.com/raysan5/raylib.git
+ GIT_TAG 5.5.0
+ GIT_SHALLOW TRUE
+ )
+ FetchContent_Declare(
+ raytmx
+ GIT_REPOSITORY https://github.com/luphi/raytmx.git
+ GIT_TAG d4e09bc
+ )
+ FetchContent_Declare(
+ hoxml
+ GIT_REPOSITORY https://github.com/luphi/hoxml.git
+ GIT_TAG 12938da
+ )
+
+ set(RAYLIB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
+ set(RAYLIB_BUILD_TESTS OFF CACHE BOOL "" FORCE)
+ set(RAYLIB_INSTALL OFF CACHE BOOL "" FORCE)
+ set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
+ set(HOXML_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
+
+ FetchContent_MakeAvailable(raylib raytmx hoxml)
+endif()
+
+file(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/*.c)
+
+file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.h)
+list(FILTER HEADERS EXCLUDE REGEX "raylib|raymath|rlgl|raytmx|hoxml")
+
+add_executable(dungeon_game ${SOURCES} ${HEADERS})
+
+target_include_directories(dungeon_game PRIVATE ${CMAKE_SOURCE_DIR}/include)
+
+if(USE_NIX)
+ target_link_libraries(dungeon_game PRIVATE raylib m)
+else()
+ target_include_directories(dungeon_game PRIVATE
+ ${raylib_SOURCE_DIR}/src
+ ${raytmx_SOURCE_DIR}
+ ${hoxml_SOURCE_DIR}/external
+ )
+ target_link_libraries(dungeon_game PRIVATE raylib hoxml raytmx m)
+endif()
+
+if(WIN32)
+ target_link_libraries(dungeon_game PRIVATE gdi32 winmm)
+elseif(APPLE)
+ target_link_libraries(dungeon_game PRIVATE "-framework Cocoa")
+endif()
+
+# Copy assets
+add_custom_command(TARGET dungeon_game POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_directory
+ ${CMAKE_SOURCE_DIR}/assets
+ $<TARGET_FILE_DIR:dungeon_game>/assets
+)
+
+if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
+ target_compile_options(dungeon_game PRIVATE -Wall -Wextra -O2)
+endif()
+
+install(TARGETS dungeon_game DESTINATION bin)
+install(DIRECTORY ${CMAKE_SOURCE_DIR}/assets/ DESTINATION bin/assets)