awesome!!!
This commit is contained in:
148
CMakeLists.txt
Normal file
148
CMakeLists.txt
Normal file
@ -0,0 +1,148 @@
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
|
||||
project(emerald LANGUAGES C)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
# dependencies
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(SDL2_image REQUIRED)
|
||||
find_package(SDL2_ttf REQUIRED)
|
||||
|
||||
set(PHYSFS_BUILD_SHARED FALSE)
|
||||
set(PHYSFS_DISABLE_INSTALL TRUE)
|
||||
set(PHYSFS_TARGETNAME_UNINSTALL "physfs_uninstall")
|
||||
add_subdirectory(third-party/physfs)
|
||||
|
||||
|
||||
set(SOURCE_FILES
|
||||
third-party/physfs/extras/physfsrwops.c
|
||||
src/config.h
|
||||
src/context.h
|
||||
src/context.c
|
||||
src/main.c
|
||||
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
|
||||
)
|
||||
|
||||
# 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
|
||||
C_EXTENSIONS OFF)
|
||||
|
||||
# distribution definitions
|
||||
set(ORGANIZATION_NAME "wanp" CACHE STRING
|
||||
"App developer/publisher's identifier")
|
||||
set(APP_NAME "baron" CACHE STRING
|
||||
"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>)
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
$<$<CONFIG:Release>:/LTCG>)
|
||||
else()
|
||||
set(WARNING_FLAGS
|
||||
-Wall
|
||||
-Wextra
|
||||
-pedantic-errors
|
||||
-Wshadow
|
||||
-Wdouble-promotion
|
||||
-Wconversion -Wno-sign-conversion
|
||||
-Werror=vla
|
||||
-Werror=alloca)
|
||||
set(BUILD_FLAGS
|
||||
# these SHOULDN'T break anything...
|
||||
-fno-math-errno
|
||||
-ffp-contract=fast
|
||||
-fno-signed-zeros
|
||||
-fno-trapping-math
|
||||
-freciprocal-math)
|
||||
set(BUILD_FLAGS_RELEASE
|
||||
-flto)
|
||||
set(BUILD_FLAGS_DEBUG
|
||||
-g3
|
||||
-fsanitize-trap=undefined)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
${WARNING_FLAGS}
|
||||
${BUILD_FLAGS}
|
||||
$<$<CONFIG:Release>:${BUILD_FLAGS_RELEASE}>
|
||||
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>)
|
||||
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}")
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
third-party/physfs/src
|
||||
third-party/physfs/extras
|
||||
)
|
||||
|
||||
# header-only libraries should be marked as "system includes"
|
||||
# to suppress compiler warnings in their code (it's not my problem after all)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
SYSTEM
|
||||
PRIVATE
|
||||
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
|
||||
)
|
||||
|
||||
# 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
|
||||
#)
|
Reference in New Issue
Block a user