1 cmake_minimum_required(VERSION 3.6)
2 project(doom2d C)
4 string(COMPARE EQUAL "${CMAKE_SYSTEM_NAME}" "Emscripten" D2D_FOR_EMSCRIPTEN)
5 string(COMPARE EQUAL "${CMAKE_SYSTEM_NAME}" "Darwin" D2D_FOR_DARWIN)
6 string(COMPARE EQUAL "${CMAKE_SYSTEM_PROCESSOR}" "powerpc" D2D_FOR_POWERPC)
8 option(SYSTEM_DRIVER "Build with selected system driver" "SDL")
9 option(RENDER_DRIVER "Build with selected render driver" "OpenGL")
10 option(SOUND_DRIVER "Build with selected sound driver" "OpenAL")
12 string(TOUPPER "${SYSTEM_DRIVER}" SYSTEM_DRIVER)
13 string(COMPARE EQUAL "${SYSTEM_DRIVER}" "SDL" WITH_SDL)
14 string(COMPARE EQUAL "${SYSTEM_DRIVER}" "SDL2" WITH_SDL2)
15 string(COMPARE EQUAL "${SYSTEM_DRIVER}" "KOS32" WITH_KOS32)
16 string(TOUPPER "${RENDER_DRIVER}" RENDER_DRIVER)
17 string(COMPARE EQUAL "${RENDER_DRIVER}" "OPENGL" WITH_OPENGL)
18 string(COMPARE EQUAL "${RENDER_DRIVER}" "SOFTWARE" WITH_SOFTWARE)
19 string(COMPARE EQUAL "${RENDER_DRIVER}" "STUB" WITH_STUBRENDER)
20 string(TOUPPER "${SOUND_DRIVER}" SOUND_DRIVER)
21 string(COMPARE EQUAL "${SOUND_DRIVER}" "OPENAL" WITH_OPENAL)
22 string(COMPARE EQUAL "${SOUND_DRIVER}" "SDLMIXER" WITH_SDLMIXER)
23 string(COMPARE EQUAL "${SOUND_DRIVER}" "STUB" WITH_STUBSOUND)
25 set(D2D_GAME_ROOT .)
26 set(D2D_SDL_ROOT ${D2D_GAME_ROOT}/sdl)
27 set(D2D_SDL2_ROOT ${D2D_GAME_ROOT}/sdl2)
28 set(D2D_KOS32_ROOT ${D2D_GAME_ROOT}/kos32)
29 set(D2D_OPENGL_ROOT ${D2D_GAME_ROOT}/gl)
30 set(D2D_SOFTWARE_ROOT ${D2D_GAME_ROOT}/soft)
31 set(D2D_STUBRENDER_ROOT ${D2D_GAME_ROOT}/stubren)
32 set(D2D_SDL_ROOT ${D2D_GAME_ROOT}/sdl)
33 set(D2D_SDLMIXER_ROOT ${D2D_GAME_ROOT}/sdlmixer)
34 set(D2D_OPENAL_ROOT ${D2D_GAME_ROOT}/openal)
35 set(D2D_STUBSOUND_ROOT ${D2D_GAME_ROOT}/stubsnd)
36 set(D2D_COMMON_ROOT ${D2D_GAME_ROOT}/common)
38 aux_source_directory(${D2D_GAME_ROOT} D2D_GAME_SRC)
39 aux_source_directory(${D2D_SDL_ROOT} D2D_SDL_SRC)
40 aux_source_directory(${D2D_SDL2_ROOT} D2D_SDL2_SRC)
41 aux_source_directory(${D2D_KOS32_ROOT} D2D_KOS32_SRC)
42 aux_source_directory(${D2D_OPENGL_ROOT} D2D_OPENGL_SRC)
43 aux_source_directory(${D2D_SOFTWARE_ROOT} D2D_SOFTWARE_SRC)
44 aux_source_directory(${D2D_STUBRENDER_ROOT} D2D_STUBRENDER_SRC)
45 aux_source_directory(${D2D_SDL_ROOT} D2D_SDL_SRC)
46 aux_source_directory(${D2D_SDLMIXER_ROOT} D2D_SDLMIXER_SRC)
47 aux_source_directory(${D2D_OPENAL_ROOT} D2D_OPENAL_SRC)
48 aux_source_directory(${D2D_STUBSOUND_ROOT} D2D_STUBSOUND_SRC)
49 aux_source_directory(${D2D_COMMON_ROOT} D2D_COMMON_SRC)
51 if(WITH_SDL)
52 if(D2D_FOR_EMSCRIPTEN)
53 set(D2D_SYSTEM_SRC "${D2D_SDL_SRC}")
54 set(D2D_SYSTEM_INCLUDE_DIR "")
55 set(D2D_SYSTEM_LIBRARY "-lSDL")
56 set(D2D_SYSTEM_LINKFLAGS "-s USE_SDL=1")
57 else()
58 find_package(SDL REQUIRED)
59 set(D2D_SYSTEM_SRC "${D2D_SDL_SRC}")
60 set(D2D_SYSTEM_INCLUDE_DIR "${SDL_INCLUDE_DIR}")
61 set(D2D_SYSTEM_LIBRARY "${SDL_LIBRARY}")
62 endif()
63 elseif(WITH_SDL2)
64 if(D2D_FOR_EMSCRIPTEN)
65 set(D2D_SYSTEM_SRC "${D2D_SDL2_SRC}")
66 set(D2D_SYSTEM_INCLUDE_DIR "")
67 set(D2D_SYSTEM_LIBRARY "-lSDL2")
68 set(D2D_SYSTEM_LINKFLAGS "-s USE_SDL=2")
69 else()
70 if(D2D_FOR_DARWIN AND D2D_FOR_POWERPC)
71 # tigerbrew did not provide sdl2 module for cmake
72 find_package(SDL2)
73 if(NOT SDL2_FOUND)
74 set(SDL2_INCLUDE_DIRS "/usr/local/include/SDL2")
75 set(SDL2_LIBRARIES "-lSDL2")
76 endif(NOT SDL2_FOUND)
77 else()
78 find_package(SDL2 REQUIRED)
79 endif()
80 set(D2D_SYSTEM_SRC "${D2D_SDL2_SRC}")
81 set(D2D_SYSTEM_INCLUDE_DIR "${SDL2_INCLUDE_DIRS}")
82 set(D2D_SYSTEM_LIBRARY "${SDL2_LIBRARIES}")
83 endif()
84 elseif(WITH_KOS32)
85 set(D2D_SYSTEM_SRC "${D2D_KOS32_SRC}")
86 set(D2D_SYSTEM_INCLUDE_DIR "")
87 set(D2D_SYSTEM_LIBRARY "-lck")
88 set(D2D_SYSTEM_LINKFLAGS "")
89 else()
90 message(FATAL_ERROR "Select SYSTEM_DRIVER as 'SDL' or 'SDL2' or 'KOS32'")
91 endif()
93 if(WITH_STUBRENDER)
94 set(D2D_RENDER_SRC "${D2D_STUBRENDER_SRC}")
95 set(D2D_RENDER_INCLUDE_DIR "")
96 set(D2D_RENDER_LIBRARY "")
97 elseif(WITH_OPENGL)
98 if(D2D_FOR_EMSCRIPTEN)
99 set(D2D_RENDER_SRC "${D2D_OPENGL_SRC}")
100 set(D2D_RENDER_INCLUDE_DIR "")
101 set(D2D_RENDER_LIBRARY "-lGL")
102 set(D2D_RENDER_LINKFLAGS "-s LEGACY_GL_EMULATION=1")
103 else()
104 find_package(OpenGL REQUIRED)
105 set(D2D_RENDER_SRC "${D2D_OPENGL_SRC}")
106 set(D2D_RENDER_INCLUDE_DIR "${OPENGL_INCLUDE_DIR}")
107 set(D2D_RENDER_LIBRARY "${OPENGL_LIBRARY}")
108 endif()
109 elseif(WITH_SOFTWARE)
110 set(D2D_RENDER_SRC "${D2D_SOFTWARE_SRC}")
111 set(D2D_RENDER_INCLUDE_DIR "")
112 set(D2D_RENDER_LIBRARY "")
113 else()
114 message(FATAL_ERROR "Select RENDER_DRIVER as 'OPENGL' or 'SOFTWARE' or 'STUB'")
115 endif()
117 if(WITH_STUBSOUND)
118 set(D2D_SOUND_SRC "${D2D_STUBSOUND_SRC}")
119 set(D2D_SOUND_INCLUDE_DIR "")
120 set(D2D_SOUND_LIBRARY "")
121 elseif(WITH_OPENAL)
122 find_package(OpenAL REQUIRED)
123 set(D2D_SOUND_SRC "${D2D_OPENAL_SRC}")
124 set(D2D_SOUND_INCLUDE_DIR "${OPENAL_INCLUDE_DIR}")
125 set(D2D_SOUND_LIBRARY "${OPENAL_LIBRARY}")
126 elseif(WITH_SDLMIXER)
127 find_package(SDL_mixer REQUIRED)
128 set(D2D_SOUND_SRC "${D2D_SDLMIXER_SRC}")
129 set(D2D_SOUND_INCLUDE_DIR "${SDLMIXER_INCLUDE_DIR}")
130 set(D2D_SOUND_LIBRARY "${SDLMIXER_LIBRARY}")
131 else()
132 message(FATAL_ERROR "Select SOUND_DRIVER as 'OPENAL' or 'SDLMIXER' or 'STUB'")
133 endif()
135 if (NOT CMAKE_BUILD_TYPE)
136 set(CMAKE_BUILD_TYPE Release)
137 endif()
138 set(CMAKE_C_FLAGS "")
139 set(CMAKE_C_FLAGS_DEBUG "-g -O0 -Wall")
140 set(CMAKE_C_FLAGS_RELEASE "-O3") # -DNDEBUG
141 set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
142 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
143 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
145 message(STATUS "=== BUILD OPTIONS ===")
146 message(STATUS "BUILD: " "${CMAKE_BUILD_TYPE}")
147 message(STATUS "CFLAGS: " "${CMAKE_C_FLAGS}")
148 message(STATUS "SYSTEM: " "${SYSTEM_DRIVER}")
149 message(STATUS "RENDER: " "${RENDER_DRIVER}")
150 message(STATUS "SOUND: " "${SOUND_DRIVER}")
152 set(D2D_USED_SRC ${D2D_GAME_SRC} ${D2D_SYSTEM_SRC} ${D2D_RENDER_SRC} ${D2D_SOUND_SRC} ${D2D_COMMON_SRC})
153 set(D2D_USED_INCLUDE_DIR "${D2D_GAME_ROOT}" "${D2D_SYSTEM_INCLUDE_DIR}" "${D2D_RENDER_INCLUDE_DIR}" "${D2D_SOUND_INCLUDE_DIR}" "${D2D_LIBCP866_ROOT}")
154 set(D2D_USED_LIBRARY "${D2D_SYSTEM_LIBRARY}" "${D2D_RENDER_LIBRARY}" "${D2D_SOUND_LIBRARY}")
155 #message(STATUS "USED SRC: ${D2D_USED_SRC}")
156 #message(STATUS "USED INC: ${D2D_USED_INCLUDE_DIR}")
157 #message(STATUS "USED LIB: ${D2D_USED_LIBRARY}")
158 add_executable(doom2d ${D2D_USED_SRC})
159 target_include_directories(doom2d PRIVATE ${D2D_USED_INCLUDE_DIR})
160 if(D2D_FOR_EMSCRIPTEN)
161 set(CMAKE_EXECUTABLE_SUFFIX ".html")
162 configure_file(${D2D_GAME_ROOT}/doom2d.wad doom2d.wad COPYONLY)
163 set(D2D_DOOM2D_WAD doom2d.wad)
164 configure_file(${D2D_GAME_ROOT}/default.cfg default.cfg COPYONLY)
165 set(D2D_DEFAULT_CFG default.cfg)
166 set(D2D_USED_LINKFLAGS "${D2D_SYSTEM_LINKFLAGS} ${D2D_RENDER_LINKFLAGS} ${D2D_SOUND_LINKFLAGS}")
167 set_target_properties(doom2d PROPERTIES LINK_FLAGS "-s WASM=0 -s MINIFY_HTML=0 -s DISABLE_EXCEPTION_CATCHING=1 -s SAFE_HEAP=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=0 ${D2D_USED_LINKFLAGS} --preload-file ${D2D_DOOM2D_WAD} --preload-file ${D2D_DEFAULT_CFG}")
168 else()
169 target_link_libraries(doom2d ${D2D_USED_LIBRARY})
170 endif()