-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathCMakeLists.txt
167 lines (136 loc) · 5.03 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
cmake_minimum_required(VERSION 3.1)
project(
PillowResize
VERSION 1.0.0
LANGUAGES CXX)
#
# BUILD SETTINGS
#
# Set compilation flags
if(NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "" FORCE)
endif()
endif()
# (un)set: cmake -DCVV_DEBUG_MODE=OFF ..
option(CVV_DEBUG_MODE "cvvisual-debug-mode" OFF)
if(CVV_DEBUG_MODE MATCHES ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCVVISUAL_DEBUGMODE")
endif()
# Clang tidy setup: add option for enabling clang tidy checks and search for the
# exe
option(ENABLE_CLANG_TIDY
"Output clang-tidy suggestions during the building process" OFF)
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable")
if(NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found.")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}")
endif()
#
# BUILD DEPENDENCIES
#
# Build and setup the correct cmake variables for third-party libraries
#
# Find required libraries
find_package(OpenCV REQUIRED)
# the CLI11 library
if(NOT TARGET CLI11::CLI11)
add_subdirectory("${PROJECT_SOURCE_DIR}/libs/CLI11/")
endif()
# the magic_enum library
if(NOT TARGET magic_enum::magic_enum)
add_subdirectory("${PROJECT_SOURCE_DIR}/libs/magic_enum/")
endif()
# updated in the following steps
set(RESIZE_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include/PillowResize")
#
# Build project
#
add_subdirectory(src/PillowResize)
# the variable for the PillowResize libraries
set(PILLOWRESIZE_LIBS PillowResize)
#
# Add executable
#
add_subdirectory(bin)
# Testing
option(BUILD_TESTS "Build the tests" OFF)
if(BUILD_TESTS)
message(STATUS "Building Tests")
enable_testing()
add_subdirectory(tests)
endif()
#
# Installation support
#
message(STATUS "INSTALLATION SUPPORT")
set(PILLOWRESIZE_INSTALLING PillowResize)
# Specify the installation configuration directory
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
# Installing Targets
# (https://cmake.org/cmake/help/latest/command/install.html#installing-targets)
install(
TARGETS ${PILLOWRESIZE_INSTALLING}
EXPORT pillowresize-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Installing Directories
# (https://cmake.org/cmake/help/latest/command/install.html#installing-directories)
# The DIRECTORY form installs contents of one or more directories to a given
# destination. Here we are installing the contents of the include directory
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Installing Exports
# https://cmake.org/cmake/help/latest/command/install.html#installing-exports
# The EXPORT form generates and installs a CMake file containing code to import
# targets from the installation tree into another project. Target installations
# are associated with the export <export-name> using the EXPORT option of the
# install(TARGETS) FILE does not specify a source but the name of the generated
# file (default: <export-name>.cmake)
install(
EXPORT pillowresize-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${INSTALL_CONFIGDIR})
# Helpers functions for creating config files that can be included by other
# projects to find and use a package. Adds the configure_package_config_file()
# and write_basic_package_version_file() commands.
include(CMakePackageConfigHelpers)
# Create a ConfigVersion.cmake file
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
# configure_package_config_file() should be used instead of the plain
# configure_file() command when creating the <PackageName>Config.cmake or
# <PackageName>config.cmake file for installing a project or library. It helps
# making the resulting package relocatable by avoiding hardcoded paths in the
# installed Config.cmake file
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR})
# Install the config, configversion and custom find modules
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR})
# ##############################################################################
export(EXPORT pillowresize-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake)
# Register package in user's package registry
export(PACKAGE ${PROJECT_NAME})
# ##############################################################################
# Add support for uninstall target As seen on
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/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)
endif()