aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 4dfad29a3e2d590b08204e9e0f3d17ec143ea935 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
cmake_minimum_required(VERSION 3.13)

option(PS1_BUILD "Build for the original Sony Playstation" OFF)
option(HOST_BUILD "Build for host platform using SDL-1.2" OFF)
option(WIN9X_BUILD "Build for Win9x using SDL-1.2" OFF)

if(NOT PS1_BUILD AND NOT HOST_BUILD AND NOT WIN9X_BUILD)
    message(FATAL_ERROR "Please define target platform. Available options:
        PS1_BUILD
        HOST_BUILD
        WIN9X_BUILD
        Run CMake again using one of the available platforms e.g.: cmake .. -DPS1_BUILD=1")
endif()

if(PS1_BUILD)
    if("$ENV{PSXSDK_PATH}" STREQUAL "")
        message(FATAL_ERROR "Please set PSXSDK_PATH env variable first")
    endif()

    set(CMAKE_C_COMPILER psx-gcc)
    set(CMAKE_AR mipsel-unknown-elf-ar)
elseif(WIN9X_BUILD)
    set(CMAKE_C_COMPILER i386-mingw32-gcc)
endif()

project(rts)

add_executable(${PROJECT_NAME} "src/main.c")
set(cdroot ${CMAKE_BINARY_DIR}/cdimg)
# 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
    mouse
    pad
    player
    resource
    sfx
    system
    terrain
    unit
    util
)

set(interfaces
    tech
)

target_compile_options(${PROJECT_NAME} PUBLIC ${cflags})

foreach(c ${components})
    add_subdirectory("src/${c}")
    target_compile_options(${c} PUBLIC ${cflags})
    target_link_libraries(${PROJECT_NAME} PRIVATE ${c})
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)