1 cmake_minimum_required(VERSION 3.6)
2 project(doom2d C)
4 option(SYSTEM_DRIVER "Build with selected system driver" "SDL")
5 option(RENDER_DRIVER "Build with selected render driver" "OpenGL")
6 option(SOUND_DRIVER "Build with selected sound driver" "OpenAL")
8 string(TOUPPER "${SYSTEM_DRIVER}" SYSTEM_DRIVER)
9 string(COMPARE EQUAL "${SYSTEM_DRIVER}" "SDL" WITH_SDL)
10 string(COMPARE EQUAL "${SYSTEM_DRIVER}" "SDL2" WITH_SDL2)
11 string(TOUPPER "${RENDER_DRIVER}" RENDER_DRIVER)
12 string(COMPARE EQUAL "${RENDER_DRIVER}" "OPENGL" WITH_OPENGL)
13 string(COMPARE EQUAL "${RENDER_DRIVER}" "SOFTWARE" WITH_SOFTWARE)
14 string(COMPARE EQUAL "${RENDER_DRIVER}" "STUB" WITH_STUBRENDER)
15 string(TOUPPER "${SOUND_DRIVER}" SOUND_DRIVER)
16 string(COMPARE EQUAL "${SOUND_DRIVER}" "OPENAL" WITH_OPENAL)
17 string(COMPARE EQUAL "${SOUND_DRIVER}" "SDLMIXER" WITH_SDLMIXER)
18 string(COMPARE EQUAL "${SOUND_DRIVER}" "STUB" WITH_STUBSOUND)
20 set(D2D_GAME_ROOT .)
21 set(D2D_SDL_ROOT ${D2D_GAME_ROOT}/sdl)
22 set(D2D_SDL2_ROOT ${D2D_GAME_ROOT}/sdl2)
23 set(D2D_OPENGL_ROOT ${D2D_GAME_ROOT}/gl)
24 set(D2D_SOFTWARE_ROOT ${D2D_GAME_ROOT}/soft)
25 set(D2D_STUBRENDER_ROOT ${D2D_GAME_ROOT}/stubren)
26 set(D2D_SDL_ROOT ${D2D_GAME_ROOT}/sdl)
27 set(D2D_SDLMIXER_ROOT ${D2D_GAME_ROOT}/sdlmixer)
28 set(D2D_OPENAL_ROOT ${D2D_GAME_ROOT}/openal)
29 set(D2D_STUBSOUND_ROOT ${D2D_GAME_ROOT}/stubsnd)
31 aux_source_directory(${D2D_GAME_ROOT} D2D_GAME_SRC)
32 aux_source_directory(${D2D_SDL_ROOT} D2D_SDL_SRC)
33 aux_source_directory(${D2D_SDL2_ROOT} D2D_SDL2_SRC)
34 aux_source_directory(${D2D_OPENGL_ROOT} D2D_OPENGL_SRC)
35 aux_source_directory(${D2D_SOFTWARE_ROOT} D2D_SOFTWARE_SRC)
36 aux_source_directory(${D2D_STUBRENDER_ROOT} D2D_STUBRENDER_SRC)
37 aux_source_directory(${D2D_SDL_ROOT} D2D_SDL_SRC)
38 aux_source_directory(${D2D_SDLMIXER_ROOT} D2D_SDLMIXER_SRC)
39 aux_source_directory(${D2D_OPENAL_ROOT} D2D_OPENAL_SRC)
40 aux_source_directory(${D2D_STUBSOUND_ROOT} D2D_STUBSOUND_SRC)
42 if(WITH_SDL)
43 find_package(SDL REQUIRED)
44 set(D2D_SYSTEM_SRC "${D2D_SDL_SRC}")
45 set(D2D_SYSTEM_INCLUDE_DIR "${SDL_INCLUDE_DIR}")
46 set(D2D_SYSTEM_LIBRARY "${SDL_LIBRARY}")
47 elseif(WITH_SDL2)
48 # find_package(SDL2 REQUIRED)
49 set(SDL2_INCLUDE_DIR "/usr/local/include/SDL2")
50 set(SDL2_LIBRARY "-lSDL2")
51 set(D2D_SYSTEM_SRC "${D2D_SDL2_SRC}")
52 set(D2D_SYSTEM_INCLUDE_DIR "${SDL2_INCLUDE_DIR}")
53 set(D2D_SYSTEM_LIBRARY "${SDL2_LIBRARY}")
54 else(WITH_SDL)
55 message(FATAL_ERROR "Select SYSTEM_DRIVER as 'SDL' or 'SDL2'")
56 endif(WITH_SDL)
58 if(WITH_STUBRENDER)
59 set(D2D_RENDER_SRC "${D2D_STUBRENDER_SRC}")
60 set(D2D_RENDER_INCLUDE_DIR "")
61 set(D2D_RENDER_LIBRARY "")
62 elseif(WITH_OPENGL)
63 find_package(OpenGL REQUIRED)
64 set(D2D_RENDER_SRC "${D2D_OPENGL_SRC}")
65 set(D2D_RENDER_INCLUDE_DIR "${OPENGL_INCLUDE_DIR}")
66 set(D2D_RENDER_LIBRARY "${OPENGL_LIBRARY}")
67 elseif(WITH_SOFTWARE)
68 set(D2D_RENDER_SRC "${D2D_SOFTWARE_SRC}")
69 set(D2D_RENDER_INCLUDE_DIR "")
70 set(D2D_RENDER_LIBRARY "")
71 else(WITH_STUBRENDER)
72 message(FATAL_ERROR "Select RENDER_DRIVER as 'OPENGL' or 'SOFTWARE' or 'STUB'")
73 endif(WITH_STUBRENDER)
75 if(WITH_STUBSOUND)
76 set(D2D_SOUND_SRC "${D2D_STUBSOUND_SRC}")
77 set(D2D_SOUND_INCLUDE_DIR "")
78 set(D2D_SOUND_LIBRARY "")
79 elseif(WITH_OPENAL)
80 find_package(OpenAL REQUIRED)
81 set(D2D_SOUND_SRC "${D2D_OPENAL_SRC}")
82 set(D2D_SOUND_INCLUDE_DIR "${OPENAL_INCLUDE_DIR}")
83 set(D2D_SOUND_LIBRARY "${OPENAL_LIBRARY}")
84 elseif(WITH_SDLMIXER)
85 find_package(SDL_mixer REQUIRED)
86 set(D2D_SOUND_SRC "${D2D_SDLMIXER_SRC}")
87 set(D2D_SOUND_INCLUDE_DIR "${SDLMIXER_INCLUDE_DIR}")
88 set(D2D_SOUND_LIBRARY "${SDLMIXER_LIBRARY}")
89 else(WITH_STUBSOUND)
90 message(FATAL_ERROR "Select SOUND_DRIVER as 'OPENAL' or 'SDLMIXER' or 'STUB'")
91 endif(WITH_STUBSOUND)
93 if (NOT CMAKE_BUILD_TYPE)
94 set(CMAKE_BUILD_TYPE Release)
95 endif (NOT CMAKE_BUILD_TYPE)
96 set(CMAKE_C_FLAGS "")
97 set(CMAKE_C_FLAGS_DEBUG "-g -O0 -Wall")
98 set(CMAKE_C_FLAGS_RELEASE "-O3") # -DNDEBUG
99 set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
100 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
101 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
103 message(STATUS "=== BUILD OPTIONS ===")
104 message(STATUS "BUILD: " "${CMAKE_BUILD_TYPE}")
105 message(STATUS "CFLAGS: " "${CMAKE_C_FLAGS}")
106 message(STATUS "SYSTEM: " "${SYSTEM_DRIVER}")
107 message(STATUS "RENDER: " "${RENDER_DRIVER}")
108 message(STATUS "SOUND: " "${SOUND_DRIVER}")
110 add_executable(doom2d ${D2D_GAME_SRC} ${D2D_SYSTEM_SRC} ${D2D_RENDER_SRC} ${D2D_SOUND_SRC})
111 target_include_directories(doom2d PRIVATE "${D2D_GAME_ROOT}" "${D2D_SYSTEM_INCLUDE_DIR}" "${D2D_RENDER_INCLUDE_DIR}" "${D2D_SOUND_INCLUDE_DIR}")
112 target_link_libraries(doom2d "${D2D_SYSTEM_LIBRARY}" "${D2D_RENDER_LIBRARY}" "${D2D_SOUND_LIBRARY}")