-
Notifications
You must be signed in to change notification settings - Fork 45
/
CMakeLists.txt
277 lines (233 loc) · 9.09 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
cmake_minimum_required (VERSION 2.8.8)
cmake_policy(SET CMP0043 NEW)
Project(ktools CXX)
set(PACKAGE_VERSION_MAJOR 4)
set(PACKAGE_VERSION_MINOR 4)
set(PACKAGE_VERSION_PATCH 0)
set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}")
OPTION(DISABLE_CPU_EXTENSIONS "Disable CPU extensions (portable build)." OFF)
OPTION(BUNDLED_DEPENDENCIES "Build under the assumption dependencies will be bundled with the executable." OFF)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/out_of_source_build.cmake)
ENSURE_OUT_OF_SOURCE_BUILD( "${PROJECT_SOURCE_DIR}/build" )
ENABLE_LANGUAGE(C)
set( COMMON_INCLUDE_DIRS "" )
set( LINK_DIRS "" )
set( COMMON_LIBS "ktool_common" "squish" "pugixml" )
set( ktech_LIBS "" )
set( krane_LIBS "" )
list( APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" )
list( APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/thirdparty" )
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(CheckStructHasMember)
include(LibFindMacros)
include(integer_types)
include(warnings)
include(compiler_specific)
include(OptimizeForArchitecture)
set(CMAKE_BUILD_TYPE Release)
if(NOT DISABLE_CPU_EXTENSIONS)
OptimizeForArchitecture()
endif()
if(BUNDLED_DEPENDENCIES)
add_definitions(-DBUNDLED_DEPENDENCIES=1)
endif()
add_subdirectory(lib)
FIND_PACKAGE(ImageMagick COMPONENTS Magick++ MagickWand MagickCore REQUIRED)
LIBFIND_PKG_CHECK_MODULES(Magick++_PKGCONF Magick++)
if("${Magick++_PKGCONF_CFLAGS}" STREQUAL "")
if("${ImageMagick_LIBRARIES}" MATCHES "HDRI")
add_definitions( "-DMAGICKCORE_HDRI_ENABLE=1" )
else()
add_definitions( "-DMAGICKCORE_HDRI_ENABLE=0" )
endif()
if("${ImageMagick_LIBRARIES}" MATCHES "Q16")
add_definitions( "-DMAGICKCORE_QUANTUM_DEPTH=16" )
else()
add_definitions( "-DMAGICKCORE_QUANTUM_DEPTH=8" )
endif()
else()
foreach(f ${Magick++_PKGCONF_CFLAGS})
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${f}" )
endforeach()
endif()
foreach(f ${Magick++_PKGCONF_LDFLAGS})
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${f}" )
endforeach()
list( APPEND COMMON_INCLUDE_DIRS "${ImageMagick_INCLUDE_DIRS}" )
list( APPEND COMMON_LIBS "${ImageMagick_LIBRARIES}" )
FIND_PACKAGE(LibZip)
if(LIBZIP_FOUND)
list( APPEND COMMON_INCLUDE_DIRS "${LIBZIP_INCLUDE_DIR}" )
list( APPEND COMMON_LIBS "${LIBZIP_LIBRARY}" )
set(HAVE_LIBZIP 1)
FIND_PACKAGE(ZLIB)
if(ZLIB_FOUND)
#list( APPEND COMMON_INCLUDE_DIRS "${ZLIB_INCLUDE_DIR}" )
list( APPEND COMMON_LIBS "${ZLIB_LIBRARY}" )
endif(ZLIB_FOUND)
endif(LIBZIP_FOUND)
CHECK_LIBRARY_EXISTS(m floor "" HAVE_MATH_LIB)
if(HAVE_MATH_LIB)
list( APPEND COMMON_LIBS "m" )
endif(HAVE_MATH_LIB)
list( APPEND ktech_LIBS "${COMMON_LIBS}" )
list( APPEND krane_LIBS "${COMMON_LIBS}" )
CHECK_INCLUDE_FILE_CXX (cstddef HAVE_CSTDDEF)
if(NOT HAVE_CSTDDEF)
CHECK_INCLUDE_FILE (stddef.h HAVE_STDDEF_H)
if(NOT HAVE_STDDEF_H)
message(FATAL_ERROR "Failed to find cstddef or stddef.h header.")
endif()
endif()
#
CHECK_INCLUDE_FILE (stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILE (inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE (sys/types.h HAVE_SYS_TYPES_H)
if(NOT HAVE_STDINT_H AND NOT HAVE_INTTYPES_H AND NOT HAVE_SYS_TYPES_H)
message(FATAL_ERROR "Failed to find a standard header defining integral types.")
endif()
#
CHECK_INCLUDE_FILE_CXX (sstream HAVE_SSTREAM)
if(NOT HAVE_SSTREAM)
CHECK_INCLUDE_FILE_CXX (strstream HAVE_STRSTREAM)
if(NOT HAVE_STRSTREAM)
CHECK_INCLUDE_FILE_CXX (strstream.h HAVE_STRSTREAM_H)
if(NOT HAVE_STRSTREAM_H)
message(FATAL_ERROR "Failed to find a sstream or strstream header.")
endif()
endif()
endif()
#
if(HAVE_STRSTREAM OR HAVE_STRSTREAM_H)
set(HAVE_CLASS_STRSTREAM TRUE)
endif()
if(HAVE_SSTREAM)
set(HAVE_CLASS_STRINGSTREAM TRUE)
endif()
#
#if(HAVE_STRSTREAM)
# set(CMAKE_EXTRA_INCLUDE_FILES "strstream")
#elseif(HAVE_STRSTREAM_H)
# set(CMAKE_EXTRA_INCLUDE_FILES "strstream.h")
#endif()
#CHECK_TYPE_SIZE("std::ostrstream" CLASS_STRSTREAM LANGUAGE CXX)
#set(CMAKE_EXTRA_INCLUDE_FILES)
#
#set(CMAKE_EXTRA_INCLUDE_FILES "sstream")
#CHECK_TYPE_SIZE("std::stringstream" SSTREAM LANGUAGE CXX)
#set(CMAKE_EXTRA_INCLUDE_FILES)
#
CHECK_TYPE_SIZE("long long" LONG_LONG)
#
CHECK_SYMBOL_EXISTS("snprintf" "stdio.h" HAVE_SNPRINTF)
if(NOT HAVE_SNPRINTF)
CHECK_SYMBOL_EXISTS("_snprintf" "stdio.h" HAVE__SNPRINTF)
endif()
#
set(CMAKE_EXTRA_INCLUDE_FILES "sys/stat.h")
CHECK_TYPE_SIZE("mode_t" MODE_T)
set(CMAKE_EXTRA_INCLUDE_FILES)
#
CHECK_CXX_SOURCE_COMPILES (
"int test (void *restrict x); int main (void) {return 0;}"
HAVE_RESTRICT)
if(NOT HAVE_RESTRICT)
CHECK_CXX_SOURCE_COMPILES (
"int test (void *__restrict x); int main (void) {return 0;}"
HAVE___RESTRICT)
if(NOT HAVE___RESTRICT)
CHECK_CXX_SOURCE_COMPILES (
"int test (void *__restrict__ x); int main (void) {return 0;}"
HAVE___RESTRICT__)
endif()
endif()
#
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
list( APPEND COMMON_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} )
add_subdirectory(src)
list( APPEND COMMON_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/common ${PROJECT_SOURCE_DIR}/lib )
set( KTECH_INCLUDE_DIRS ${COMMON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src/ktech )
set( KRANE_INCLUDE_DIRS ${COMMON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src/krane )
set( LIBKTOOL_INCLUDE_DIRS ${COMMON_INCLUDE_DIRS} )
link_directories( ${LINK_DIRS} )
# add_executable(<name> [WIN32] [MACOSX_BUNDLE] ...
if(NOT WIN32)
add_executable(ktech ${ktech_SOURCES} ${ktech_HEADERS})
add_executable(krane ${krane_SOURCES} ${krane_HEADERS})
else()
add_executable(ktech WIN32 ${ktech_SOURCES} ${ktech_HEADERS})
add_executable(krane WIN32 ${krane_SOURCES} ${krane_HEADERS})
endif()
add_library(ktool_common STATIC ${ktool_common_SOURCES} ${ktool_common_HEADERS})
target_link_libraries( ktech ${ktech_LIBS} )
target_link_libraries( krane ${krane_LIBS} )
set_property( TARGET ktech PROPERTY INCLUDE_DIRECTORIES "${KTECH_INCLUDE_DIRS}" )
set_property( TARGET krane PROPERTY INCLUDE_DIRECTORIES "${KRANE_INCLUDE_DIRS}" )
set_property( TARGET ktool_common PROPERTY INCLUDE_DIRECTORIES "${LIBKTOOL_INCLUDE_DIRS}" )
if(MSVC)
set_target_properties(ktech PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
set_target_properties(ktech PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE")
set_target_properties(ktech PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE")
set_target_properties(ktech PROPERTIES COMPILE_DEFINITIONS_RELWITHDEBINFO "_CONSOLE")
set_target_properties(ktech PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:CONSOLE")
set_target_properties(ktech PROPERTIES COMPILE_DEFINITIONS_RELEASE "_CONSOLE")
set_target_properties(ktech PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:CONSOLE")
set_target_properties(ktech PROPERTIES COMPILE_DEFINITIONS_MINSIZEREL "_CONSOLE")
set_target_properties(krane PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
set_target_properties(krane PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE")
set_target_properties(krane PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE")
set_target_properties(krane PROPERTIES COMPILE_DEFINITIONS_RELWITHDEBINFO "_CONSOLE")
set_target_properties(krane PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:CONSOLE")
set_target_properties(krane PROPERTIES COMPILE_DEFINITIONS_RELEASE "_CONSOLE")
set_target_properties(krane PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:CONSOLE")
set_target_properties(krane PROPERTIES COMPILE_DEFINITIONS_MINSIZEREL "_CONSOLE")
endif(MSVC)
INSTALL(TARGETS ktech RUNTIME DESTINATION bin)
INSTALL(TARGETS krane RUNTIME DESTINATION bin)
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
#
# Packing stuff
#
set(CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Cross platform Don't Starve modding tools.")
set(CPACK_PACKAGE_VENDOR "simplex")
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PACKAGE_VERSION}")
set(CPACK_SOURCE_GENERATOR "TGZ")
# The following components are regex's to match anywhere (unless anchored)
# in absolute path + filename to find files or directories to be excluded
# from source tarball.
set(CPACK_SOURCE_IGNORE_FILES
"~$"
"/[.].+$"
"^${CMAKE_CURRENT_SOURCE_DIR}/local/"
"^${CMAKE_CURRENT_SOURCE_DIR}/deps/"
"^${CMAKE_CURRENT_SOURCE_DIR}/build/"
"^${CMAKE_CURRENT_SOURCE_DIR}/config.h$"
"/cmake_install.cmake$"
"/CMakeFiles/"
"/Makefile$"
"^${CMAKE_BINARY_DIR}/.*"
)
include(CPack)
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
#add_custom_target(bindist COMMAND ${CMAKE_MAKE_PROGRAM} package)
add_custom_target(distclean
COMMAND rm -rf CMakeCache.txt CPackConfig.cmake CPackSourceConfig.cmake config.h
COMMAND -find . '\(' -name CMakeFiles -o -name cmake_install.cmake -o -name Makefile '\)' -exec rm -rf {} '\;'
COMMAND rm -rf build/*
)