-
-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathCMakeLists.txt
218 lines (203 loc) · 7.02 KB
/
CMakeLists.txt
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
cmake_minimum_required(VERSION 2.8)
project(cdogs-sdl C)
SET(VERSION "0.5.1")
SET(VERSION_RC "0,5,1,0") # this must be 4 numbers
SET(VERSION_MAJOR "0")
SET(VERSION_MINOR "5")
SET(VERSION_PATCH "1")
SET(WEBSITE "http://cxong.github.io/cdogs-sdl/")
set(DEBUG 0) #set to 1 to enable debug build
set(DEBUG_PROFILE 0) # set to 1 to enable debug profile build
if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CLANG 1)
endif()
IF(UNIX AND NOT APPLE)
SET(CMAKE_INSTALL_PREFIX /opt/cdogs-sdl/bin)
ENDIF()
if(MINGW)
set(CMAKE_RC_COMPILER_INIT windres)
enable_language(RC)
SET(CMAKE_RC_COMPILE_OBJECT
"<CMAKE_RC_COMPILER> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif()
SET(LINKDIR /usr/games)
if(DEBUG)
set(CMAKE_BUILD_TYPE "Debug")
endif()
find_package(SDL REQUIRED)
find_package(SDL_mixer REQUIRED)
execute_process(
COMMAND "sdl-config" "--libs"
OUTPUT_VARIABLE SDL_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND "sdl-config" "--cflags"
OUTPUT_VARIABLE SDL_CFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Work-around for CMake SDL bug (need to link SDLmain before SDL)
set(SDLMAIN_INDEX 0)
set(SDL_INDEX 0)
set(SDLMAIN_LIBRARY "")
set(INDEX 0)
foreach(SDL_LIBRARY_ITEM ${SDL_LIBRARY})
string(FIND ${SDL_LIBRARY_ITEM} "libSDLmain" SDLMAIN_FIND_INDEX)
string(FIND ${SDL_LIBRARY_ITEM} "libSDL.dll" SDL_FIND_INDEX)
if(${SDLMAIN_FIND_INDEX} GREATER -1)
SET(SDLMAIN_INDEX ${INDEX})
set(SDLMAIN_LIBRARY ${SDL_LIBRARY_ITEM})
endif()
if(${SDL_FIND_INDEX} GREATER -1)
SET(SDL_INDEX ${INDEX})
endif()
math(EXPR INDEX "${INDEX} + 1")
endforeach()
if(${SDLMAIN_INDEX} GREATER ${SDL_INDEX})
list(REMOVE_AT SDL_LIBRARY ${SDLMAIN_INDEX})
list(INSERT SDL_LIBRARY ${SDL_INDEX} ${SDLMAIN_LIBRARY})
endif()
ADD_DEFINITIONS(${SDL_LDFLAGS} ${SDL_CFLAGS})
ADD_DEFINITIONS(-I${SDL_INCLUDE_DIR})
if(MSVC)
ADD_DEFINITIONS(-W4 -WX -wd"4996")
else()
add_definitions(
-fsigned-char
-Wall -W
-Wstrict-prototypes -Wpointer-arith -Wcast-qual)
if(DEBUG)
ADD_DEFINITIONS(-g)
if(DEBUG_PROFILE)
ADD_DEFINITIONS(-p)
endif(DEBUG_PROFILE)
else()
ADD_DEFINITIONS(-O2)
endif()
if(CLANG)
else()
# Probably GCC...
add_definitions(-freg-struct-return)
if(NOT APPLE AND NOT BEOS AND NOT HAIKU)
add_definitions(-Wshadow)
endif()
endif()
if(NOT BEOS AND NOT HAIKU)
add_definitions(-Winline -Werror)
set(EXTRA_LIBRARIES "m")
endif()
endif()
set(CDOGS_DATA_DIR "../")
set(CDOGS_CFG_DIR ".cdogs/")
SET(SOURCE_DIRECTORY ".")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ".")
IF(UNIX AND NOT APPLE)
CONFIGURE_FILE(${SOURCE_DIRECTORY}/build/linux/cdogs-sdl.cmake ${SOURCE_DIRECTORY}/build/linux/cdogs-sdl)
ENDIF()
IF(WIN32)
CONFIGURE_FILE(${SOURCE_DIRECTORY}/build/windows/cdogs.rc.cmake ${SOURCE_DIRECTORY}/build/windows/cdogs.rc)
ENDIF()
CONFIGURE_FILE(${SOURCE_DIRECTORY}/src/cdogs/sys_config.h.cmake ${SOURCE_DIRECTORY}/src/cdogs/sys_config.h)
CONFIGURE_FILE(${SOURCE_DIRECTORY}/README.md.cmake ${SOURCE_DIRECTORY}/README.md)
add_subdirectory(src)
# Build the shared library next to cdogs-sdl
set_target_properties(hqx PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/src
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/src
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/src
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/src
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src
)
set_target_properties(cdogs-sdl PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/src
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/src
)
set_target_properties(cdogs-sdl-editor PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/src
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/src
)
set(INSTALL_PREFIX ".")
if(WIN32)
set(EXE_EXTENSION ".exe")
set(LIB_EXTENSION ".dll")
elseif(APPLE)
set(EXE_EXTENSION "")
set(LIB_EXTENSION ".dylib")
set(INSTALL_PREFIX "cdogs-sdl")
else()
set(EXE_EXTENSION "")
set(LIB_EXTENSION ".so")
endif()
install(
PROGRAMS src/cdogs-sdl${EXE_EXTENSION} src/cdogs-sdl-editor${EXE_EXTENSION} src/libhqx${LIB_EXTENSION}
DESTINATION ${INSTALL_PREFIX}/bin)
# Installation
INSTALL(DIRECTORY
${SOURCE_DIRECTORY}/doc
${SOURCE_DIRECTORY}/missions
${SOURCE_DIRECTORY}/dogfights
${SOURCE_DIRECTORY}/graphics
${SOURCE_DIRECTORY}/music
${SOURCE_DIRECTORY}/sounds
DESTINATION ${INSTALL_PREFIX})
INSTALL(FILES ${SOURCE_DIRECTORY}/cdogs_icon.bmp ${SOURCE_DIRECTORY}/README.md DESTINATION ${INSTALL_PREFIX})
IF(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
INSTALL(
FILES ${SOURCE_DIRECTORY}/build/linux/cdogs-sdl
DESTINATION ${LINKDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
INSTALL(FILES
${SOURCE_DIRECTORY}/build/linux/cdogs-sdl.desktop
${SOURCE_DIRECTORY}/cdogs_icon.png
DESTINATION ${INSTALL_PREFIX}/bin)
elseif(MSVC)
# Package for Windows
FILE(GLOB DLLS "${SOURCE_DIRECTORY}/src/*.dll")
FOREACH(DLL ${DLLS})
INSTALL(FILES "${DLL}" DESTINATION ${INSTALL_PREFIX}/bin)
ENDFOREACH()
install(DIRECTORY ${SOURCE_DIRECTORY}/build/licenses DESTINATION ${INSTALL_PREFIX})
elseif(APPLE)
set(CMAKE_INSTALL_PREFIX "/Applications/cdogs-sdl")
install(
FILES "${SOURCE_DIRECTORY}/build/macosx/C-Dogs SDL"
DESTINATION ${INSTALL_PREFIX}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif()
# Packaging
SET(CPACK_PACKAGE_NAME "C-Dogs SDL")
SET(CPACK_PACKAGE_VENDOR "C-Dogs SDL Team")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C-Dogs SDL: Action/Arcade Game")
SET(CPACK_PACKAGE_VERSION ${VERSION})
SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
SET(CPACK_PACKAGE_EXECUTABLES "cdogs-sdl;C-Dogs SDL;cdogs-sdl-editor;Campaign Editor")
IF(WIN32)
SET(CPACK_GENERATOR NSIS)
SET(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/doc/COPYING.GPL)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "C-Dogs SDL")
SET(CPACK_NSIS_MUI_ICON ${CMAKE_CURRENT_BINARY_DIR}/cdogs-icon.ico)
set(CPACK_NSIS_CREATE_ICONS "SetOutPath '\$INSTDIR\\\\bin'
CreateShortCut '\$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\C-Dogs SDL.lnk' '\$INSTDIR\\\\bin\\\\cdogs-sdl.exe'
CreateShortCut '\$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Campaign Editor.lnk' '\$INSTDIR\\\\bin\\\\cdogs-sdl-editor.exe'")
SET(CPACK_NSIS_MUI_FINISHPAGE_RUN cdogs-sdl.exe)
SET(CPACK_NSIS_URL_INFO_ABOUT ${WEBSITE})
elseif(APPLE)
set(CMAKE_INSTALL_PREFIX "/Applications/cdogs-sdl")
set(CPACK_GENERATOR "DragNDrop")
set(CPACK_DMG_FORMAT "UDBZ")
set(CPACK_DMG_VOLUME_NAME "C-Dogs SDL")
set(CPACK_SYSTEM_NAME "OSX")
set(CPACK_PACKAGE_ICON
"${CMAKE_CURRENT_BINARY_DIR}/build/macosx/cdogs-icon.icns")
elseif(BEOS OR HAIKU)
set(CPACK_GENERATOR TGZ)
install(
FILES ${SOURCE_DIRECTORY}/build/haiku/cdogs-sdl.sh
DESTINATION ${INSTALL_PREFIX}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
ELSE()
SET(CPACK_GENERATOR TGZ)
ENDIF()
INCLUDE(CPack)