aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: bb3c8265a3e58ff2f51783e27cee7f236ab9be26 (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
# wnix, a Unix-like operating system for WebAssembly applications.
# Copyright (C) 2025  Xavier Del Campo Romero
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# 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
    BUILD_ALWAYS ON
    CMAKE_ARGS
        -D CMAKE_EXPORT_COMPILE_COMMANDS=ON
        -D CMAKE_INSTALL_PREFIX=${TOOLS_PREFIX})

project(wnix C ASM)
option(WNIX_BUILD_PROGRAMS "Build userspace programs" ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

add_compile_options(-mno-gpopt -ffunction-sections -fdata-sections)

if(CMAKE_TOOLCHAIN_FILE MATCHES "ps1")
    set(PS1_BUILD 1)
    option(WNIX_VIRT_CD "Virtualise CD driver through SIO")
elseif(CMAKE_TOOLCHAIN_FILE MATCHES "win9x")
    set(WIN9X_BUILD 1)
    set(SDL1_2_BUILD 1)
    set(exec_flags WIN32)
else()
    set(HOST_BUILD 1)
    set(SDL1_2_BUILD 1)
endif()

add_executable(${PROJECT_NAME} ${exec_flags} 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()

if(NOT PS1_BUILD)
    find_package(ENET 1.3 REQUIRED)
endif()

set(cdroot ${CMAKE_BINARY_DIR})

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)
add_subdirectory(src)

if(WNIX_BUILD_PROGRAMS)
    add_subdirectory(programs)
endif()