-
Notifications
You must be signed in to change notification settings - Fork 69
/
CMakeLists.txt
118 lines (93 loc) · 3.31 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
# Copyright (c) 2022 Bartek Fabiszewski
# http://www.fabiszewski.net
#
# This file is part of libmobi.
# Licensed under LGPL, either version 3, or any later.
# See <http://www.gnu.org/licenses/>
cmake_minimum_required(VERSION 3.12)
project(LIBMOBI C)
set(CMAKE_C_STANDARD 99)
file(STRINGS ${LIBMOBI_SOURCE_DIR}/configure.ac VERSION_LINE REGEX "AC_INIT\\(\\[libmobi\\], \\[(.*)\\]\\)")
string(REGEX MATCH "([0-9]+\\.[0-9]+)" PACKAGE_VERSION "${VERSION_LINE}")
message(STATUS "libmobi version ${PACKAGE_VERSION}")
add_definitions(-DPACKAGE_VERSION="${PACKAGE_VERSION}")
string(REPLACE "." ";" VERSION_LIST ${PACKAGE_VERSION})
list(GET VERSION_LIST 0 PACKAGE_VERSION_MAJOR)
list(GET VERSION_LIST 1 PACKAGE_VERSION_MINOR)
# Option to enable encryption
option(USE_ENCRYPTION "Enable encryption" ON)
# Option to enable static tools compilation
option(TOOLS_STATIC "Enable static tools compilation" OFF)
# Option to use libxml2
option(USE_LIBXML2 "Use libxml2 instead of internal xmlwriter" ON)
# Option to use zlib
option(USE_ZLIB "Use zlib" ON)
# Option to enable XMLWRITER
option(USE_XMLWRITER "Enable xmlwriter (for opf support)" ON)
# Option to enable debug
option(MOBI_DEBUG "Enable debug" OFF)
# Option to enable debug alloc
option(MOBI_DEBUG_ALLOC "Enable debug alloc" OFF)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
if(TOOLS_STATIC)
set(BUILD_SHARED_LIBS OFF)
endif(TOOLS_STATIC)
if(USE_ENCRYPTION)
add_definitions(-DUSE_ENCRYPTION)
endif(USE_ENCRYPTION)
if(USE_XMLWRITER)
add_definitions(-DUSE_XMLWRITER)
if(USE_LIBXML2)
add_definitions(-DUSE_LIBXML2)
find_package(LibXml2 REQUIRED)
include_directories(${LIBXML2_INCLUDE_DIR})
endif(USE_LIBXML2)
endif(USE_XMLWRITER)
if(MOBI_DEBUG)
add_definitions(-DMOBI_DEBUG)
message(STATUS "CMAKE_CXX_COMPILER_ID=${CMAKE_C_COMPILER_ID}")
if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options(-pedantic -Wall -Wextra -Werror)
endif()
endif(MOBI_DEBUG)
if(MOBI_DEBUG_ALLOC)
add_definitions(-DMOBI_DEBUG_ALLOC)
endif(MOBI_DEBUG_ALLOC)
if(USE_ZLIB)
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
else()
add_definitions(-DUSE_MINIZ)
endif(USE_ZLIB)
include(CheckIncludeFile)
include(CheckFunctionExists)
check_include_file(unistd.h HAVE_UNISTD_H)
if(HAVE_UNISTD_H)
add_definitions(-DHAVE_UNISTD_H)
endif(HAVE_UNISTD_H)
check_function_exists(getopt HAVE_GETOPT)
if(HAVE_GETOPT)
add_definitions(-DHAVE_GETOPT)
endif(HAVE_GETOPT)
check_function_exists(strdup HAVE_STRDUP)
if(HAVE_STRDUP)
add_definitions(-DHAVE_STRDUP)
endif(HAVE_STRDUP)
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
if(HAVE_SYS_RESOURCE_H)
add_definitions(-DHAVE_SYS_RESOURCE_H)
endif(HAVE_SYS_RESOURCE_H)
include(CheckCSourceCompiles)
foreach(keyword "inline" "__inline__" "__inline")
check_c_source_compiles("${keyword} void func(); void func() { } int main() { func(); return 0; }" HAVE_INLINE)
if(HAVE_INLINE)
add_definitions(-DMOBI_INLINE=${keyword})
break()
endif(HAVE_INLINE)
endforeach(keyword)
check_c_source_compiles("void func() { } __attribute__((noreturn)); int main() { func(); return 0; }" HAVE_ATTRIBUTE_NORETURN)
if(HAVE_ATTRIBUTE_NORETURN)
add_definitions(-DHAVE_ATTRIBUTE_NORETURN)
endif(HAVE_ATTRIBUTE_NORETURN)
add_subdirectory(src)
add_subdirectory(tools)