forked from brechtsanders/xlsxio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
262 lines (236 loc) · 11.7 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.21)
PROJECT(xlsxio DESCRIPTION "C libraries for reading and writing .xlsx files")
# get version number
FILE(READ "include/xlsxio_version.h" VERFILE)
STRING(REGEX MATCH "#define XLSXIO_VERSION_MAJOR ([0-9]*)" DUMMYVAR ${VERFILE})
SET(XLSXIO_VER_MAJOR ${CMAKE_MATCH_1})
STRING(REGEX MATCH "#define XLSXIO_VERSION_MINOR ([0-9]*)" DUMMYVAR ${VERFILE})
SET(XLSXIO_VER_MINOR ${CMAKE_MATCH_1})
STRING(REGEX MATCH "#define XLSXIO_VERSION_MICRO ([0-9]*)" DUMMYVAR ${VERFILE})
SET(XLSXIO_VER_MICRO ${CMAKE_MATCH_1})
SET(XLSXIO_VER "${XLSXIO_VER_MAJOR}.${XLSXIO_VER_MINOR}.${XLSXIO_VER_MICRO}")
UNSET(DUMMYVAR)
UNSET(VERFILE)
MESSAGE(STATUS "XLSX I/O library version: ${XLSXIO_VER}")
# parameters
OPTION(XLSXIO_USE_DFHACK_LIBS "Use DFHack-provided dependencies" ON)
OPTION(XLSXIO_ENABLE_INSTALL "Install xlsxio" ON)
OPTION(XLSXIO_BUILD_STATIC "Build static libraries" ON)
OPTION(XLSXIO_BUILD_SHARED "Build shared libraries" ON)
OPTION(XLSXIO_BUILD_PC_FILES "Build pkg-config .pc" OFF)
OPTION(XLSXIO_BUILD_TOOLS "Build tools" ON)
OPTION(XLSXIO_BUILD_EXAMPLES "Build examples" ON)
OPTION(XLSXIO_WITH_LIBZIP "Use libzip instead of Minizip" OFF)
OPTION(XLSXIO_WITH_WIDE "Also build UTF-16 library (libxlsxio_readw)" OFF)
SET(XLSXIO_ZLIB_DIR "" CACHE PATH "Path to the zlib library")
IF(XLSXIO_WITH_LIBZIP)
SET(XLSXIO_LIBZIP_DIR "" CACHE PATH "Path to the libzip library")
ELSE()
SET(XLSXIO_MINIZIP_DIR "" CACHE PATH "Path to the Minizip library")
ENDIF()
SET(XLSXIO_EXPAT_DIR "" CACHE PATH "Path to the Expat library")
# check conditions
IF(NOT XLSXIO_BUILD_STATIC AND NOT XLSXIO_BUILD_SHARED)
MESSAGE(FATAL_ERROR "Cannot build with both XLSXIO_BUILD_STATIC and XLSXIO_BUILD_SHARED disabled")
ENDIF()
# dependancies
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
# dependancy: zlib (dependancy of libzip/Minizip, should be detected there)
IF(XLSXIO_ZLIB_DIR)
SET(ZLIB_ROOT ${XLSXIO_ZLIB_DIR})
ENDIF()
IF(XLSXIO_USE_DFHACK_LIBS)
SET(ANYZIP_INCLUDE_DIRS ${XLSXIO_LIBZIP_DIR}/include)
SET(ANYZIP_LIBRARIES zip)
SET(ANYZIP_DEF USE_LIBZIP)
SET(EXPAT_INCLUDE_DIRS ${XLSXIO_EXPAT_DIR}/expat/lib)
SET(EXPAT_LIBRARIES expat)
ELSE()
#FIND_PACKAGE(ZLIB REQUIRED)
# dependancy: libzip
IF(XLSXIO_WITH_LIBZIP)
FIND_PACKAGE(LibZip REQUIRED)
SET(ANYZIP_INCLUDE_DIRS ${LIBZIP_INCLUDE_DIRS})
SET(ANYZIP_LIBRARIES ${LIBZIP_LIBRARIES})
SET(ANYZIP_DEF USE_LIBZIP)
ELSE()
FIND_PACKAGE(Minizip REQUIRED)
SET(ANYZIP_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIRS})
SET(ANYZIP_LIBRARIES ${MINIZIP_LIBRARIES})
SET(ANYZIP_DEF USE_MINIZIP)
ENDIF()
# dependancy: expat
IF(XLSXIO_EXPAT_DIR)
#FIND_PACKAGE(EXPAT MODULE REQUIRED NO_DEFAULT_PATH PATHS ${XLSXIO_EXPAT_DIR})
FIND_PATH(EXPAT_INCLUDE_DIR NAMES expat.h NO_DEFAULT_PATH PATHS ${XLSXIO_EXPAT_DIR}/include ${XLSXIO_EXPAT_DIR})
FIND_LIBRARY(EXPAT_LIBRARIES NAMES expat libexpat NO_DEFAULT_PATH PATHS ${XLSXIO_EXPAT_DIR}/lib ${XLSXIO_EXPAT_DIR})
ELSE()
FIND_PACKAGE(EXPAT REQUIRED)
ENDIF()
# dependancy: expatw (if wide library was requested)
IF(XLSXIO_WITH_WIDE)
IF(XLSXIO_EXPAT_DIR)
FIND_LIBRARY(EXPATW_LIBRARIES NAMES expatw libexpatw NO_DEFAULT_PATH PATHS ${XLSXIO_EXPAT_DIR}/lib ${XLSXIO_EXPAT_DIR})
ELSE()
FIND_LIBRARY(EXPATW_LIBRARIES NAMES expatw)
ENDIF()
ENDIF()
ENDIF(XLSXIO_USE_DFHACK_LIBS)
# Doxygen
IF((DEFINED XLSXIO_BUILD_DOCUMENTATION) AND (NOT XLSXIO_BUILD_DOCUMENTATION))
SET(DOXYGEN_FOUND 0)
ELSE()
FIND_PACKAGE(Doxygen)
ENDIF()
OPTION(XLSXIO_BUILD_DOCUMENTATION "Create and install API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
# build parameters
#SET(CMAKE_CXX_FLAGS "-g -Wall")
#ADD_SUBDIRECTORY(src)
IF(NOT WIN32 AND NOT APPLE)
SET(THREADLIB "-pthread")
ENDIF()
INCLUDE_DIRECTORIES(include)
INCLUDE_DIRECTORIES(${ANYZIP_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIRS})
# build definitions
SET(ALLTARGETS)
SET(LINKTYPES)
IF(XLSXIO_BUILD_STATIC)
LIST(APPEND LINKTYPES "STATIC")
ENDIF()
IF(XLSXIO_BUILD_SHARED)
LIST(APPEND LINKTYPES "SHARED")
ENDIF()
FOREACH(LINKTYPE ${LINKTYPES})
ADD_LIBRARY(xlsxio_read_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF};BUILD_XLSXIO_${LINKTYPE}")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_read)
IF(MINGW AND LINKTYPE STREQUAL "SHARED")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_read.def")
SET_SOURCE_FILES_PROPERTIES(xlsxio_read.def PROPERTIES HEADER_FILE_ONLY TRUE)
ENDIF()
TARGET_INCLUDE_DIRECTORIES(xlsxio_read_${LINKTYPE} PRIVATE lib)
TARGET_LINK_LIBRARIES(xlsxio_read_${LINKTYPE} ${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_read_${LINKTYPE})
ADD_LIBRARY(xlsxio_write_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF};BUILD_XLSXIO_${LINKTYPE}")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write)
IF(MINGW AND LINKTYPE STREQUAL "SHARED")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_write.def")
ENDIF()
TARGET_LINK_LIBRARIES(xlsxio_write_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_write_${LINKTYPE})
IF(XLSXIO_WITH_WIDE)
ADD_LIBRARY(xlsxio_readw_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_readw)
IF(MINGW AND LINKTYPE STREQUAL "SHARED")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_readw.def")
ENDIF()
TARGET_INCLUDE_DIRECTORIES(xlsxio_readw_${LINKTYPE} PRIVATE lib)
TARGET_LINK_LIBRARIES(xlsxio_readw_${LINKTYPE} ${ANYZIP_LIBRARIES} ${EXPATW_LIBRARIES})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_readw_${LINKTYPE})
#ADD_LIBRARY(xlsxio_writew_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write_w)
#IF(MINGW AND LINKTYPE STREQUAL "SHARED")
# SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES LINK_FLAGS "-Wl,--output-def=libxlsxio_writew.def")
#ENDIF()
#TARGET_LINK_LIBRARIES(xlsxio_writew_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
#SET(ALLTARGETS ${ALLTARGETS} xlsxio_writew_${LINKTYPE})
ENDIF()
SET(EXELINKTYPE ${LINKTYPE})
ENDFOREACH()
#SET_TARGET_PROPERTIES(xlsxio_read_SHARED PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
#SET_TARGET_PROPERTIES(xlsxio_write_SHARED PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
IF(XLSXIO_BUILD_TOOLS)
ADD_EXECUTABLE(xlsxio_xlsx2csv src/xlsxio_xlsx2csv.c)
TARGET_LINK_LIBRARIES(xlsxio_xlsx2csv xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_xlsx2csv)
ADD_EXECUTABLE(xlsxio_csv2xlsx src/xlsxio_csv2xlsx.c)
TARGET_LINK_LIBRARIES(xlsxio_csv2xlsx xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_csv2xlsx)
ENDIF()
IF(XLSXIO_BUILD_EXAMPLES)
ADD_EXECUTABLE(example_xlsxio_write_getversion examples/example_xlsxio_write_getversion.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write_getversion xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write_getversion)
ADD_EXECUTABLE(example_xlsxio_write examples/example_xlsxio_write.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write)
ADD_EXECUTABLE(example_xlsxio_read examples/example_xlsxio_read.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read)
ADD_EXECUTABLE(example_xlsxio_read_advanced examples/example_xlsxio_read_advanced.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read_advanced xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read_advanced)
IF(XLSXIO_WITH_WIDE)
ADD_EXECUTABLE(example_xlsxio_readw examples/example_xlsxio_read.c)
SET_TARGET_PROPERTIES(example_xlsxio_readw PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE")
TARGET_LINK_LIBRARIES(example_xlsxio_readw xlsxio_readw_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_readw)
ENDIF()
ENDIF()
IF(XLSXIO_BUILD_DOCUMENTATION)
IF(NOT DOXYGEN_FOUND)
MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.")
ENDIF()
ADD_CUSTOM_TARGET(doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile
#WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/man
DESTINATION .
)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/html
DESTINATION share/xlsxio
)
ENDIF()
IF(XLSXIO_ENABLE_INSTALL)
# installation specifications
INSTALL(TARGETS ${ALLTARGETS}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
INSTALL(DIRECTORY include/
DESTINATION include
FILES_MATCHING PATTERN "xlsxio*.h"
)
IF(MINGW AND XLSXIO_BUILD_SHARED)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_read.def" DESTINATION lib)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_write.def" DESTINATION lib)
IF(XLSXIO_WITH_WIDE)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_readw.def" DESTINATION lib)
#INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_writew.def" DESTINATION lib)
ENDIF()
ENDIF()
ENDIF()
# generate .cmake and .pc files
MACRO(generate_and_install_config_files _NAME _DESC _LIBS _HEADER)
SET(XLSXIO_NAME "${_NAME}")
SET(XLSXIO_DESC "${_DESC}")
SET(XLSXIO_HEADER "${_HEADER}")
STRING(REGEX REPLACE "^lib\([^ ]*\)" "\\1" XLSXIO_LIB "${XLSXIO_NAME}")
STRING(REPLACE ";" " " XLSXIO_LDFLAGS "-l${XLSXIO_LIB} ${_LIBS}")
STRING(REGEX REPLACE "\([^ ]*\)[/\\]lib([^ /\\.]*).[^ ]*" "-L\\1 -l\\2" XLSXIO_LDFLAGS "${XLSXIO_LDFLAGS}")
CONFIGURE_FILE(templateConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}Config.cmake" @ONLY)
CONFIGURE_FILE(templateConfigVersion.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}ConfigVersion.cmake" @ONLY)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}ConfigVersion.cmake" DESTINATION cmake/)
IF (BUILD_PC_FILES)
CONFIGURE_FILE(template.pc.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}.pc" @ONLY)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}.pc" DESTINATION lib/pkgconfig)
ENDIF()
ENDMACRO()
IF(0)
generate_and_install_config_files("libxlsxio_write" "C library for writing .xlsx files" "${ANYZIP_LIBRARIES} ${THREADLIB}" "xlsxio_write.h")
generate_and_install_config_files("libxlsxio_read" "C library for writing .xlsx files" "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}" "xlsxio_read.h")
IF(WITH_WIDE)
generate_and_install_config_files("libxlsxio_readw" "C library for reading .xlsx files using wide characters" "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}" "xlsxio_read.h")
ENDIF()
ENDIF()