97 lines
2.2 KiB
CMake
97 lines
2.2 KiB
CMake
# SDL::SDL was defined on 3.20.
|
|
cmake_minimum_required(VERSION 3.20)
|
|
|
|
set(TOOLS_PREFIX ${CMAKE_BINARY_DIR}/tools)
|
|
include(ExternalProject)
|
|
ExternalProject_Add(tools
|
|
SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools
|
|
CMAKE_ARGS
|
|
-D CMAKE_INSTALL_PREFIX=${TOOLS_PREFIX})
|
|
|
|
project(rts C)
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
|
|
|
if(CMAKE_TOOLCHAIN_FILE MATCHES "ps1")
|
|
set(PS1_BUILD 1)
|
|
elseif(CMAKE_TOOLCHAIN_FILE MATCHES "win9x")
|
|
set(WIN9X_BUILD 1)
|
|
set(SDL1_2_BUILD 1)
|
|
else()
|
|
set(HOST_BUILD 1)
|
|
set(SDL1_2_BUILD 1)
|
|
endif()
|
|
|
|
add_executable(${PROJECT_NAME} "src/main.c")
|
|
|
|
if(SDL1_2_BUILD)
|
|
find_package(SDL 1.2 REQUIRED)
|
|
find_package(SDL_gfx 2.0 REQUIRED)
|
|
find_package(SDL_mixer 1.2 REQUIRED)
|
|
# FindSDL_mixer.cmake does not export any target, so do it here instead.
|
|
add_library(SDL::SDL_mixer STATIC IMPORTED)
|
|
set_property(TARGET SDL::SDL_mixer PROPERTY
|
|
IMPORTED_LOCATION ${SDL_MIXER_LIBRARIES})
|
|
target_include_directories(SDL::SDL_mixer INTERFACE ${SDL_MIXER_INCLUDE_DIRS})
|
|
target_link_libraries(SDL::SDL_mixer INTERFACE SDL::SDL)
|
|
endif()
|
|
|
|
set(cdroot ${CMAKE_BINARY_DIR}/cdimg)
|
|
file(MAKE_DIRECTORY ${cdroot})
|
|
# Avoid C11 since it is not supported by the i386-mingw32 toolchain.
|
|
set(cflags -Wall -g3 -ffunction-sections -fdata-sections -pedantic -std=c99)
|
|
|
|
if(PS1_BUILD)
|
|
include("cmake/ps1.cmake")
|
|
elseif(WIN9X_BUILD)
|
|
include("cmake/win9x.cmake")
|
|
elseif(HOST_BUILD)
|
|
include("cmake/host.cmake")
|
|
endif()
|
|
|
|
add_subdirectory("res")
|
|
|
|
set(components
|
|
building
|
|
camera
|
|
container
|
|
font
|
|
game
|
|
gfx
|
|
gui
|
|
header
|
|
instance
|
|
keyboard
|
|
menu
|
|
mouse
|
|
pad
|
|
peripheral
|
|
player
|
|
resource
|
|
sfx
|
|
system
|
|
terrain
|
|
unit
|
|
util
|
|
)
|
|
|
|
set(interfaces
|
|
tech
|
|
)
|
|
|
|
target_compile_options(${PROJECT_NAME} PUBLIC ${cflags})
|
|
# Dependencies for main.c
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE system menu)
|
|
|
|
foreach(c ${components})
|
|
add_subdirectory("src/${c}")
|
|
target_compile_options(${c} PUBLIC ${cflags})
|
|
endforeach()
|
|
|
|
foreach(i ${interfaces})
|
|
add_subdirectory("src/${i}")
|
|
target_compile_options(${i} INTERFACE ${cflags})
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE ${c})
|
|
endforeach()
|
|
|
|
target_link_options(${PROJECT_NAME} PRIVATE -Wl,--gc-sections)
|