-
Notifications
You must be signed in to change notification settings - Fork 96
/
CMakeLists.txt
164 lines (139 loc) · 4.93 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
cmake_minimum_required(VERSION 3.16.0)
project(libzippp
VERSION 6.0.0
DESCRIPTION "C++ wrapper for libzip"
HOMEPAGE_URL "http://github.com/ctabin/libzippp"
LANGUAGES CXX
)
# Use C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Do not install or build tests by default when this file is included
# as a sub-project (via add_subdirectory)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(is_root_project ON)
else()
set(is_root_project OFF)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -ansi -pedantic -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
endif()
option(LIBZIPPP_INSTALL "Install library" ${is_root_project})
option(LIBZIPPP_INSTALL_HEADERS "Install the headers" ${is_root_project})
option(LIBZIPPP_BUILD_TESTS "Build unit tests" ${is_root_project})
option(LIBZIPPP_ENABLE_ENCRYPTION "Build with encryption enabled" OFF)
option(LIBZIPPP_CMAKE_CONFIG_MODE "Build with libzip installed cmake config files" OFF)
option(LIBZIPPP_GNUINSTALLDIRS "Install into directories taken from GNUInstallDirs" OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if(LIBZIPPP_CMAKE_CONFIG_MODE)
set(LIBZIP_PKGNAME "libzip")
set(fp_mode "CONFIG")
else()
set(LIBZIP_PKGNAME "LIBZIP")
set(fp_mode "MODULE")
endif()
find_package(${LIBZIP_PKGNAME} ${fp_mode} REQUIRED)
if(LIBZIPPP_GNUINSTALLDIRS)
include(GNUInstallDirs)
set(install_include_location ${CMAKE_INSTALL_INCLUDEDIR}/libzippp)
else()
set(install_include_location include/libzippp)
endif()
add_library(libzippp "src/libzippp.cpp")
add_library(libzippp::libzippp ALIAS libzippp) # Convenience alias
target_include_directories(libzippp
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${install_include_location}>
)
set_target_properties(libzippp PROPERTIES PREFIX "") # Avoid duplicate "lib" prefix
target_link_libraries(libzippp PRIVATE libzip::zip)
if(LIBZIPPP_ENABLE_ENCRYPTION)
target_compile_definitions(libzippp PUBLIC LIBZIPPP_WITH_ENCRYPTION)
endif()
if (BUILD_SHARED_LIBS)
target_compile_definitions(libzippp PRIVATE LIBZIPPP_EXPORTS)
else()
set_target_properties(libzippp PROPERTIES OUTPUT_NAME "libzippp_static")
endif()
export(TARGETS libzippp NAMESPACE libzippp:: FILE ${PROJECT_BINARY_DIR}/libzippp-target.cmake)
if(LIBZIPPP_BUILD_TESTS)
enable_testing()
add_executable(libzippp_test "tests/tests.cpp")
target_link_libraries(libzippp_test PRIVATE libzippp)
add_test(NAME libzippp_tests COMMAND libzippp_test)
if (BUILD_SHARED_LIBS)
set_target_properties(libzippp_test PROPERTIES OUTPUT_NAME "libzippp_shared_test")
else()
set_target_properties(libzippp_test PROPERTIES OUTPUT_NAME "libzippp_static_test")
endif()
endif()
if(LIBZIPPP_INSTALL)
install(
TARGETS libzippp
EXPORT libzipppTargets
)
if(LIBZIPPP_INSTALL_HEADERS)
install(
FILES src/libzippp.h
DESTINATION ${install_include_location}
)
endif()
include(CMakePackageConfigHelpers)
set(PROJECT_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}Config.cmake")
set(PROJECT_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}ConfigVersion.cmake")
if(LIBZIPPP_GNUINSTALLDIRS)
set(configInstallDestination ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
else()
if(WIN32)
set(configInstallDestination cmake/${PROJECT_NAME})
else()
set(configInstallDestination share/${PROJECT_NAME})
endif()
endif()
configure_package_config_file(
"Config.cmake.in"
${PROJECT_CONFIG_FILE}
INSTALL_DESTINATION ${configInstallDestination}
)
write_basic_package_version_file(
${PROJECT_VERSION_FILE}
COMPATIBILITY SameMajorVersion
)
install(
FILES ${PROJECT_CONFIG_FILE} ${PROJECT_VERSION_FILE}
$<$<NOT:$<BOOL:"${LIBZIPPP_CMAKE_CONFIG_MODE}">>:cmake/FindLIBZIP.cmake>
DESTINATION ${configInstallDestination}
)
install(
EXPORT libzipppTargets
NAMESPACE "${PROJECT_NAME}::"
DESTINATION ${configInstallDestination}
)
if(BUILD_SHARED_LIBS AND LIBZIPPP_GNUINSTALLDIRS AND LIBZIPPP_INSTALL_HEADERS)
string(
REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}"
pc_includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
)
string(
REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${exec_prefix}"
pc_libdir "${CMAKE_INSTALL_FULL_LIBDIR}"
)
get_target_property(pc_cd_list libzippp INTERFACE_COMPILE_DEFINITIONS)
if(pc_cd_list)
list(TRANSFORM pc_cd_list PREPEND "-D")
list(JOIN pc_cd_list " " pc_compile_definitions)
endif()
configure_file(libzippp.pc.in generated/libzippp.pc @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/libzippp.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
endif()
endif()