-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
167 lines (132 loc) · 6.39 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
# ---------------------------------------------------------------------------------------------------------------------
# The MIT License (MIT)
#
# Copyright (c) 2018-2019 Ralph-Gordon Paul. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ---------------------------------------------------------------------------------------------------------------------
cmake_minimum_required (VERSION 3.9)
project (RGPZip)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)
# for Visual Studio Code
include(CMakeToolsHelpers OPTIONAL)
# setup conan if conan is used
if (EXISTS ${CMAKE_BINARY_DIR}/conan_paths.cmake)
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
endif (EXISTS ${CMAKE_BINARY_DIR}/conan_paths.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/include)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/deps/lib)
# options
option(BUILD_TESTS "Build test programs" ON)
# add local cmake modules to module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
# disable root path for android and ios platforms
if (${CMAKE_SYSTEM_NAME} MATCHES "^(iOS|tvOS|watchOS|Android)$")
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
endif()
# specify windows specific settings
# if (WIN32)
# if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# set(CMAKE_CXX_FLAGS_RELEASE "/MT")
# set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
# endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# endif (WIN32)
# ----------------------------------------------------------------------------------------------------------------------
# Dependencies
# ----------------------------------------------------------------------------------------------------------------------
# zlib Compressing File-I/O Library - https://www.zlib.net
find_package(ZLIB REQUIRED)
# Boost - http://www.boost.org
set(Boost_USE_STATIC_LIBS ON )
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
find_package(Boost 1.70.0 REQUIRED COMPONENTS system filesystem)
# ----------------------------------------------------------------------------------------------------------------------
# Library
# ----------------------------------------------------------------------------------------------------------------------
file(GLOB MINIZIP_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib/contrib/minizip/unzip.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib/contrib/minizip/zip.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib/contrib/minizip/ioapi.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib/contrib/minizip/mztools.c)
file(GLOB RGPZIP_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/RGPZip.cpp)
if (WIN32)
file(GLOB MINIZIP_PLATFORM_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib/contrib/minizip/iowin32.c)
endif (WIN32)
add_library(rgpzip STATIC
# minizip sources
${MINIZIP_SRC}
# platform specific minizip sources
${MINIZIP_PLATFORM_SRC}
# rgpzip sources
${RGPZIP_SRC})
target_include_directories(rgpzip
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib/contrib/minizip
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(rgpzip
${ZLIB_LIBRARIES}
${Boost_LIBRARIES})
# set version info
set_target_properties(rgpzip PROPERTIES
VERSION 1.0.1
SOVERSION 0
PUBLIC_HEADER "include/rgpaul/RGPZip.hpp")
# ----------------------------------------------------------------------------------------------------------------------
# Installation
# ----------------------------------------------------------------------------------------------------------------------
install(TARGETS rgpzip
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/rgpaul
RUNTIME DESTINATION bin)
# ----------------------------------------------------------------------------------------------------------------------
# Unit Tests
# ----------------------------------------------------------------------------------------------------------------------
# Boost Unit Tests
find_package(Boost 1.70.0 COMPONENTS unit_test_framework)
# only enable unit tests if the unit test framework was found and tests are enabled
if(Boost_UNIT_TEST_FRAMEWORK_FOUND AND BUILD_TESTS)
# enable cmake testing
enable_testing()
# all tests are in the test folder
file(GLOB TEST_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test/*.cpp)
# copy test data
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/golden-retriever-3058383_1920.jpg DESTINATION .)
# process every test file
foreach(testSrc ${TEST_SRC})
# get the filename without the extension
get_filename_component(testname ${testSrc} NAME_WE)
# add test as executable
add_executable(${testname} ${testSrc})
# link jwtpp, boost and crypto++
target_link_libraries(${testname}
rgpzip
${ZLIB_LIBRARIES}
${Boost_LIBRARIES})
target_include_directories(${testname}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/zlib/contrib/minizip
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${Boost_INCLUDE_DIRS})
# save the executable in the tests folder
set_target_properties(${testname} PROPERTIES RUNTIME_OUTPUT_DIRECTORY tests)
# add to cmake tests
add_test(NAME ${testname} COMMAND tests/${testname})
endforeach(testSrc)
endif()