-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
187 lines (154 loc) · 5.82 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#
# This file is part of the Glove distribution (https://github.com/piallai/glove).
# Copyright (C) 2024 Pierre Allain.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required(VERSION 3.0.0)
PROJECT(Glove VERSION 0.7.5
DESCRIPTION "A Qt C++ library for simple GUI")
message(STATUS "Glove " ${PROJECT_VERSION})
# Configure Glove options header
option(OPTION_ENABLE_SLV_QT_PROGRESS "Needed to enable qt in Sleeve library and provide progress management classes. Setting OFF will disable tracking of progress. Disabled if Qt is not found." ON)
option(OPTION_USE_THIRDPARTY_JSON "Use json library." ON)
option(OPTION_USE_BOOST "Enable default management of boost containers with GCC and Clang (nested containers management)." OFF)
option(OPTION_STD_BREAK_THROW_EXCEPTION "Throws std::runtime_error when using slv::flag::BREAK" ON)
option(OPTION_COMPILE_SAMPLES_WITH_SINGLE_HEADER "Examples to be compiled with the merged library as a single header." OFF)
option(OPTION_QT6 "Use Qt6. If ON, minimal C++ version is 17" ON)
set(OPTION_CXX "11" CACHE STRING "C++ version.")
set_property(CACHE OPTION_CXX PROPERTY STRINGS 11 14 17 20)
if (OPTION_QT6)
set(QT_VERSION_MAJOR "6")
else()
set(QT_VERSION_MAJOR "5")
endif()
# Find the QtWidgets library
find_package(Qt${QT_VERSION_MAJOR}Widgets)
if (Qt${QT_VERSION_MAJOR}Widgets_FOUND)
set(USE_QT ON)
find_package(Qt${QT_VERSION_MAJOR}PrintSupport REQUIRED)
else()
set(USE_QT OFF)
set(OPTION_ENABLE_SLV_QT_PROGRESS OFF)
endif()
include("${${PROJECT_NAME}_SOURCE_DIR}/CMake/options.txt")
configure_file (
"src/GloveOptions.h.in"
"${PROJECT_BINARY_DIR}/GloveOptions.h"
)
configure_file (
"src/GloveVersion.h.in"
"${PROJECT_BINARY_DIR}/GloveVersion.h"
)
###QT####
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
IF(UNIX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
ENDIF()
#########
if (OPTION_QT6 AND (${OPTION_CXX} STREQUAL "11" OR ${OPTION_CXX} STREQUAL "14"))
message(STATUS "Using Qt6 : C++ is set to 17 instead of " ${OPTION_CXX})
set(OPTION_CXX "17")
endif()
set(CMAKE_CXX_STANDARD ${OPTION_CXX})
# For examples
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
add_definitions(-DUSE_OMP)
endif()
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
IF(MSVC)
add_definitions(/bigobj)
add_definitions(/MP4)#parallel compilation of files
add_compile_options(/wd4250)#Ignore inheritance via dominance warning
add_compile_options(/wd4100)#Ignore unreferenced formal parameter
add_compile_options(/W4)#Ignore inheritance via dominance warning
add_compile_options(/Zc:__cplusplus)#Enable __cplusplus macro
#add_compile_options(/Zc:preprocessor)#Set _MSVC_TRADITIONAL to 0
if (OPTION_QT6)
add_compile_options(/permissive-)
endif()
ENDIF()
if(UNIX AND NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release)#set default build tpye to release
endif()
message(STATUS "CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
SET(CMAKE_VERBOSE_MAKEFILE True)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/samples)
if(OPTION_USE_THIRDPARTY_JSON)
add_subdirectory(thirdParty/json)
endif()
add_subdirectory(src)
add_subdirectory(doc/readme)
add_custom_target(_Config ALL
SOURCES
CMake/options.txt
src/GloveVersion.h.in
src/GloveOptions.h.in
)
if(Qt5Widgets_FOUND)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Sample001)
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(WIN32)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation directory" FORCE)
else()
set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation directory" FORCE)
endif()
endif()
message(STATUS "CMAKE_INSTALL_PREFIX " ${CMAKE_INSTALL_PREFIX})
##############################################################################
install(TARGETS Sleeve CONFIGURATIONS Release DESTINATION "lib/glove")
if(USE_QT)
install(TARGETS Glove CONFIGURATIONS Release DESTINATION "lib/glove")
install(TARGETS GloveAdd CONFIGURATIONS Release DESTINATION "lib/glove")
endif()
install(TARGETS Sleeve CONFIGURATIONS Debug DESTINATION "lib/glove")
if(USE_QT)
install(TARGETS Glove CONFIGURATIONS Debug DESTINATION "lib/glove")
install(TARGETS GloveAdd CONFIGURATIONS Debug DESTINATION "lib/glove")
endif()
install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/src_sleeve/"
DESTINATION "include/glove/sleeve"
FILES_MATCHING
PATTERN "*.h")
if(USE_QT)
install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/src_glove/"
DESTINATION "include/glove/glove"
FILES_MATCHING
PATTERN "*.h")
install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/src_glove_add/"
DESTINATION "include/glove/glove_add"
FILES_MATCHING
PATTERN "*.h")
endif()
install(FILES "${PROJECT_BINARY_DIR}/GloveOptions.h"
DESTINATION "include/glove/sleeve"
)
install(FILES "${PROJECT_BINARY_DIR}/GloveVersion.h"
DESTINATION "include/glove/sleeve"
)
if(OPTION_USE_THIRDPARTY_JSON)
install(FILES "${CMAKE_SOURCE_DIR}/thirdParty/json/json.hpp"
DESTINATION "include/glove/thirdParty"
)
endif()
##############################################################################