-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
146 lines (126 loc) · 5.94 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
#**********************************************************************************
# MIT License *
# *
# Copyright (c) 2022 Vahan Aghajanyan <[email protected]> *
# *
# 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.16)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# The project definition
project(nkar VERSION 0.3.0 DESCRIPTION "The image comparison library" LANGUAGES CXX)
# Make cache variables for install destinations
include(GNUInstallDirs)
# General options
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(BUILD_DOCUMENTATION "Build documentation" ON)
option(ENABLE_TESTING "Enable unit test build" OFF)
option(ENABLE_EXAMPLES "Enable examples build" OFF)
if (MSVC)
# Make sure the __cplusplus macro reflects the true value for the C++ standard used.
add_compile_options(/W3 /Zc:__cplusplus)
else()
# Specify the target architecture (Linux). For Windows based generator use rather
# '-A Win32' or '-A x64 options'
set(TARGET_ARCH x86 CACHE STRING "the target architecture")
set_property(CACHE TARGET_ARCH PROPERTY STRINGS x86 x64)
if (TARGET_ARCH STREQUAL "x86")
set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_FLAGS -m32)
elseif(TARGET_ARCH STREQUAL "x64")
set(CMAKE_C_FLAGS -m64)
set(CMAKE_CXX_FLAGS -m64)
else()
message(FATAL_ERROR "Incorrect target architecture specified. "
"It should be either x86 or x64")
endif()
# Get the architecture: x86 vs x64
if(TARGET_ARCH STREQUAL "x64")
set(BIT "x86_64")
else()
set(BIT "x86")
endif()
add_compile_options(-Wall -Wextra -pedantic)
endif()
# Append a postfix for the debug libraries
if (NOT CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX d)
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
###############################################################################
# Generate documentation if needed
#
# Check if Doxygen is installed
find_package(Doxygen)
if (DOXYGEN_FOUND AND BUILD_DOCUMENTATION)
set(DOXYGEN_GENERATE_LATEX NO)
set(DOXYGEN_CREATE_SUBDIRS YES)
set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/docs/html)
set(DOXYGEN_PROJECT_NAME ${PROJECT_DESCRIPTION})
set(DOXYGEN_EXTRACT_STATIC YES)
set(DOXYGEN_EXTRACT_ALL YES)
set(DOXYGEN_EXTRACT_LOCAL_METHODS YES)
set(DOXYGEN_WARN_NO_PARAMDOC YES)
set(DOXYGEN_RECURSIVE YES)
set(DOXYGEN_EXCLUDE ${PROJECT_SOURCE_DIR}/test
${PROJECT_SOURCE_DIR}/examples)
set(DOXYGEN_HTML_OUTPUT .)
set(DOXYGEN_GENERATE_TREEVIEW YES)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md)
# Add the documentation target. This target doesn't build by default if doxygen is found.
# To build it explicitly, use '--target documentation' or 'make documentation' option.
doxygen_add_docs(documentation
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Building the project documentation")
else()
message("Failed to generate documentation: Doxygen is not found")
endif()
###############################################################################
# Testing
#
if (ENABLE_TESTING)
# Coverage support.
option(CODE_COVERAGE "Enable coverage reporting" OFF)
if (CODE_COVERAGE AND CMAKE_BUILD_TYPE STREQUAL Debug AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
add_compile_options(-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
add_link_options(--coverage)
else()
link_libraries(--coverage)
endif()
endif()
endif()
add_subdirectory(src)
if (ENABLE_EXAMPLES)
add_subdirectory(examples)
endif()
if (ENABLE_TESTING)
enable_testing()
include(Dart)
add_subdirectory(test)
endif()