2024-07-08 00:44:20 +00:00
|
|
|
cmake_minimum_required(VERSION 3.21)
|
|
|
|
|
2024-07-29 10:06:23 +00:00
|
|
|
project(townengine LANGUAGES C)
|
2024-07-08 00:44:20 +00:00
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
|
|
|
|
2024-07-08 00:56:00 +00:00
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
# dependencies
|
|
|
|
find_package(SDL2 REQUIRED)
|
|
|
|
find_package(SDL2_image REQUIRED)
|
|
|
|
find_package(SDL2_ttf REQUIRED)
|
|
|
|
|
2024-07-08 16:13:53 +00:00
|
|
|
if (NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE Debug)
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
set(PHYSFS_BUILD_SHARED FALSE)
|
|
|
|
set(PHYSFS_DISABLE_INSTALL TRUE)
|
|
|
|
set(PHYSFS_TARGETNAME_UNINSTALL "physfs_uninstall")
|
|
|
|
add_subdirectory(third-party/physfs)
|
2024-07-08 13:58:23 +00:00
|
|
|
add_subdirectory(third-party/libxm)
|
2024-07-08 00:44:20 +00:00
|
|
|
|
|
|
|
|
2024-07-27 22:44:39 +00:00
|
|
|
if(UNIX)
|
|
|
|
set(SYSTEM_SOURCE_FILES
|
|
|
|
src/system/linux/elf.c
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
set(SYSTEM_SOURCE_FILES)
|
|
|
|
endif()
|
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
set(SOURCE_FILES
|
|
|
|
third-party/physfs/extras/physfsrwops.c
|
2024-07-08 06:46:12 +00:00
|
|
|
third-party/stb/stb_vorbis.c
|
2024-07-09 12:35:54 +00:00
|
|
|
third-party/glad/src/glad.c
|
2024-07-08 06:46:12 +00:00
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
src/config.h
|
|
|
|
src/context.h
|
|
|
|
src/context.c
|
|
|
|
src/main.c
|
2024-07-08 06:46:12 +00:00
|
|
|
src/audio.c
|
2024-07-08 00:44:20 +00:00
|
|
|
src/util.c src/util.h
|
|
|
|
src/rendering.c src/rendering.h
|
|
|
|
src/textures.c src/textures.h
|
|
|
|
src/input.c src/input.h
|
|
|
|
src/text.c src/text.h
|
|
|
|
src/game_api.h
|
|
|
|
|
|
|
|
src/game/game.c src/game/game.h
|
|
|
|
src/game/state.h
|
|
|
|
|
|
|
|
src/game/player.c src/game/player.h
|
|
|
|
src/game/world.c src/game/world.h
|
|
|
|
|
|
|
|
src/game/scenes/scene.c src/game/scenes/scene.h
|
|
|
|
src/game/scenes/title.c src/game/scenes/title.h
|
|
|
|
src/game/scenes/ingame.c src/game/scenes/ingame.h
|
2024-07-27 22:44:39 +00:00
|
|
|
|
|
|
|
${SYSTEM_SOURCE_FILES}
|
2024-07-08 00:44:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# target
|
|
|
|
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
|
|
|
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES})
|
|
|
|
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
|
|
C_STANDARD 11
|
|
|
|
C_STANDARD_REQUIRED ON
|
2024-07-14 13:04:12 +00:00
|
|
|
C_EXTENSIONS ON) # extensions are required by stb_ds.h
|
2024-07-08 00:44:20 +00:00
|
|
|
|
|
|
|
# distribution definitions
|
|
|
|
set(ORGANIZATION_NAME "wanp" CACHE STRING
|
|
|
|
"App developer/publisher's identifier")
|
2024-07-29 10:06:23 +00:00
|
|
|
set(APP_NAME "townengine" CACHE STRING
|
2024-07-08 00:44:20 +00:00
|
|
|
"App identifier")
|
|
|
|
set(PACKAGE_EXTENSION "btw" CACHE STRING
|
|
|
|
"File extension used to look for data archives")
|
|
|
|
|
|
|
|
# build options
|
|
|
|
# LTO will be used on release builds
|
|
|
|
if(MSVC)
|
|
|
|
# close enough i say
|
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
|
|
/W4
|
|
|
|
$<$<CONFIG:Release>:/GL>)
|
2024-07-28 18:47:57 +00:00
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
target_link_options(${PROJECT_NAME} PRIVATE
|
|
|
|
$<$<CONFIG:Release>:/LTCG>)
|
2024-07-28 18:47:57 +00:00
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
else()
|
2024-07-28 18:47:57 +00:00
|
|
|
set(WARNING_FLAGS_CLANG
|
|
|
|
-Weverything
|
|
|
|
-Wno-padded
|
|
|
|
-Wno-declaration-after-statement
|
|
|
|
-Wno-unsafe-buffer-usage
|
|
|
|
-Wno-unused-command-line-argument)
|
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
set(WARNING_FLAGS
|
|
|
|
-Wall
|
|
|
|
-Wextra
|
2024-07-09 12:35:54 +00:00
|
|
|
-Wpedantic
|
2024-07-08 00:44:20 +00:00
|
|
|
-Wshadow
|
|
|
|
-Wdouble-promotion
|
|
|
|
-Wconversion -Wno-sign-conversion
|
2024-07-28 18:47:57 +00:00
|
|
|
-Werror=vla
|
2024-07-28 19:17:53 +00:00
|
|
|
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Gnu>:-Wcast-align=strict>
|
2024-07-28 18:47:57 +00:00
|
|
|
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:${WARNING_FLAGS_CLANG}>)
|
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
set(BUILD_FLAGS
|
|
|
|
# these SHOULDN'T break anything...
|
|
|
|
-fno-math-errno
|
|
|
|
-ffp-contract=fast
|
2024-07-28 10:33:29 +00:00
|
|
|
-fno-signed-zeros
|
|
|
|
-fno-trapping-math
|
|
|
|
-freciprocal-math)
|
2024-07-28 18:47:57 +00:00
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
set(BUILD_FLAGS_RELEASE
|
2024-07-27 22:44:39 +00:00
|
|
|
-O3
|
2024-07-19 20:37:28 +00:00
|
|
|
-flto
|
2024-07-28 18:47:57 +00:00
|
|
|
-mavx -mavx2
|
|
|
|
-Wl,--gc-sections
|
2024-07-19 20:37:28 +00:00
|
|
|
-fdata-sections
|
2024-07-27 22:44:39 +00:00
|
|
|
-ffunction-sections
|
|
|
|
-funroll-loops
|
|
|
|
-fomit-frame-pointer
|
2024-07-28 18:47:57 +00:00
|
|
|
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Gnu>:-fallow-store-data-races>)
|
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
set(BUILD_FLAGS_DEBUG
|
2024-07-27 22:44:39 +00:00
|
|
|
-O0
|
2024-07-08 00:44:20 +00:00
|
|
|
-g3
|
2024-07-08 06:46:12 +00:00
|
|
|
-gdwarf
|
2024-07-27 22:44:39 +00:00
|
|
|
-fno-omit-frame-pointer
|
|
|
|
-fstack-protector-all
|
2024-07-27 12:12:17 +00:00
|
|
|
-fsanitize=undefined
|
2024-07-27 22:44:39 +00:00
|
|
|
-fsanitize=address)
|
2024-07-28 18:47:57 +00:00
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
|
|
${WARNING_FLAGS}
|
|
|
|
${BUILD_FLAGS}
|
|
|
|
$<$<CONFIG:Release>:${BUILD_FLAGS_RELEASE}>
|
|
|
|
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>)
|
2024-07-28 18:47:57 +00:00
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
target_link_options(${PROJECT_NAME} PRIVATE
|
|
|
|
${BUILD_FLAGS}
|
|
|
|
$<$<CONFIG:Release>:${BUILD_FLAGS_RELEASE}>
|
|
|
|
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>)
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
|
|
|
ORGANIZATION_NAME="${ORGANIZATION_NAME}"
|
|
|
|
APP_NAME="${APP_NAME}"
|
|
|
|
PACKAGE_EXTENSION="${PACKAGE_EXTENSION}")
|
|
|
|
|
2024-07-28 18:47:57 +00:00
|
|
|
# header-only libraries should be marked as "system includes"
|
|
|
|
# to suppress compiler warnings in their code (it's not my problem after all)
|
2024-07-08 00:44:20 +00:00
|
|
|
target_include_directories(${PROJECT_NAME}
|
2024-07-28 18:47:57 +00:00
|
|
|
SYSTEM
|
2024-07-08 00:44:20 +00:00
|
|
|
PRIVATE
|
|
|
|
third-party/physfs/src
|
|
|
|
third-party/physfs/extras
|
2024-07-08 13:58:23 +00:00
|
|
|
third-party/libxm/include
|
2024-07-09 12:35:54 +00:00
|
|
|
third-party/glad/include
|
2024-07-08 00:44:20 +00:00
|
|
|
third-party/stb
|
|
|
|
)
|
|
|
|
|
|
|
|
# system libraries
|
|
|
|
find_library(MATH_LIBRARY m)
|
|
|
|
if(MATH_LIBRARY)
|
|
|
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${MATH_LIBRARY})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# third-party libraries
|
|
|
|
target_link_libraries(${PROJECT_NAME} PUBLIC
|
|
|
|
SDL2::SDL2
|
|
|
|
SDL2::SDL2main
|
|
|
|
SDL2_image::SDL2_image
|
|
|
|
SDL2_ttf::SDL2_ttf
|
|
|
|
physfs-static
|
2024-07-08 13:58:23 +00:00
|
|
|
xms
|
2024-07-08 00:44:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# copy dlls for baby windows
|
|
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:${PROJECT_NAME}>
|
|
|
|
$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}>
|
|
|
|
COMMAND_EXPAND_LISTS
|
|
|
|
)
|
|
|
|
|
|
|
|
# zip up assets
|
|
|
|
# currently, you must run cmake from the project root dir for this to work correctly
|
|
|
|
#file(ARCHIVE_CREATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/data.${PACKAGE_EXTENSION}
|
|
|
|
# PATHS ${PROJECT_SOURCE_DIR}/assets
|
|
|
|
# FORMAT zip
|
|
|
|
#)
|