CMakeLists.txt 8 KB
Newer Older
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# ###############################################################################
# #
# # Copyright (C) 1994 Narvik University College
# # Contact: GMlib Online Portal at http://episteme.hin.no
# #
# # This file is part of the Geometric Modeling Library, GMlib.
# #
# # GMlib is free software: you can redistribute it and/or modify
# # it under the terms of the GNU Lesser General Public License as published by
# # the Free Software Foundation, either version 3 of the License, or
# # (at your option) any later version.
# #
# # GMlib 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 Lesser General Public License for more details.
# #
# # You should have received a copy of the GNU Lesser General Public License
# # along with GMlib. If not, see <http://www.gnu.org/licenses/>.
# #
# ###############################################################################

# Minimum CMake version required
cmake_minimum_required(VERSION 3.4)

# Nice name for the IDEs
project(GMlib VERSION 0.6.9 LANGUAGES CXX)

# Specify compiler features
set(CMAKE_CXX_STANDARD 14)

# Compiler options
if(MSVC)
  message("Compiler: ${CMAKE_CXX_COMPILER_ID}")
elseif (CMAKE_CXX_COMPILER_ID MATCHES GNU)
  message("Compiler: ${CMAKE_CXX_COMPILER_ID}")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Werror")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
  message("Compiler: ${CMAKE_CXX_COMPILER_ID}")

  # Default compile flags (read: turn on all checks)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-documentation -pedantic -Werror")

  # Extra compile flags to turn of stuff we don't want to handle at the moment
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-exit-time-destructors")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-conversion")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-padded")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-global-constructors")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undefined-var-template")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-double-promotion")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-float-equal")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ignored-qualifiers")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-non-virtual-dtor")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-covered-switch-default")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-statement-expression")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-zero-as-null-pointer-constant")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-shadow-field")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-destructor-override")
  #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess")



else()
  message(WARNING "Compiler <${CMAKE_CXX_COMPILER_ID}> is not a supported C++ compiler.")
endif()

# Extra CMake modules
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/" )

# Include some cmake utils
include(cmake/utils.cmake)
GM_INIT()





####### TEMP !!!!!!!!!!! TMP
#add_custom_target( ECMake SOURCES ecmake/enhanced.cmake )
add_subdirectory(cmake)
####### TEMP !!!!!!!!!!! TMP





# Options
option( GM_STREAM "Enable output stream operators for core types." ON )

# Developer/debug options
option( GM_DEVELOPER_MODE "Set gmlib in developer mode" ON )
#option( GM_DEBUG "Enable internal debugging, assertions, etc." FALSE )
option( GM_DEBUG_OPENGL "Enable opengl debug. OpenGL function calls are safe called." ON )
option( GM_TESTING "Create unit tests." OFF )
option( GM_BENCHMARKING "Create benchmarks." OFF )

# API documentation options
#option( GM_DOXYGEN "Create build target for doxygen documentation." FALSE )



#################
## Developer Mode
if(GM_DEVELOPER_MODE)

  ##########
  ## TESTING
  if(GM_TESTING)
    message("Finding GTest")
    find_package(GTest REQUIRED)
    if(GTEST_FOUND)
      include_directories(${GTEST_INCLUDE_DIRS})
      message("GTest include dir: ${GTEST_INCLUDE_DIRS}")
      enable_testing()
    else(GTEST_FOUND)
      message(WARNING "GTest NOT found: Unittests disabled")
      message(WARNING "GTest include dir: ${GTEST_INCLUDE_DIRS}")
      set(GM_TESTING FALSE)
    endif(GTEST_FOUND)

  endif(GM_TESTING)

  if(GM_BENCHMARKING)
    message("Finding Google Benchmark:")
    find_package(benchmark)
    if(benchmark_FOUND)
      message(WARNING "Google benchmark found: Benchmarking enabled!")
      enable_testing()
    else(benchmark_FOUND)
      message(WARNING "Google benchmark NOT fould: benchmarks disabled!")
      set(GM_TESTING FALSE)
    endif(benchmark_FOUND)
  endif(GM_BENCHMARKING)

  if(GM_DEBUG_OPENGL)
    GM_ADD_DEFINITION( GM_GL_DEBUG )
    add_definitions( -DGM_GL_DEBUG )
  endif(GM_DEBUG_OPENGL)

endif(GM_DEVELOPER_MODE)

##########################
# Add GM_STREAM definition
if(GM_STREAM)
  GM_ADD_DEFINITION( GM_STREAM )
  add_definitions(-DGM_STREAM)
  message("GMStream enabled")
endif(GM_STREAM)

##########################################
# Build shared libs instead of static libs
option( GM_BUILD_SHARED "Build shared libs instead of static libs." TRUE )
if(GM_BUILD_SHARED)
  message( "GMlib: Building shared libs!" )
else(GM_BUILD_SHARED)
  message( "GMlib: Building static libs!" )
endif(GM_BUILD_SHARED)

################################################
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE)
  message(STATUS "Setting build type to 'Release' as none was specified.")
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
  # Set the possible values of build type for cmake-gui
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
    "MinSizeRel" "RelWithDebInfo")
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" )






# Add modules directory
add_subdirectory(modules)






#message( "custom config: ${GM_CUSTOM_CONFIG}" )

GM_JOIN( "${GM_CUSTOM_CONFIG}" "\n" VAR_CUSTOM_CONFIG )


#foreach( TARGET ${GM_MODULE_TARGETS} )
##  get_target_property( TARGET_LOC ${TARGET} ${CMAKE_BUILD_TYPE}_LOCATION )
##  set( TARGET_LOC $<TARGET_FILE:${TARGET}>)
#  message( "target: ${TARGET}, LOC: ${TARGET_LOC}"  )
#endforeach()


set( GM_DEFINITIONS_STR "" )
foreach( DEFINITION ${GM_DEFINITIONS} )
  set( GM_DEFINITIONS_STR "-D${DEFINITION} ${GM_DEFINITIONS_STR}" )
endforeach()
set( VAR_DEFINITIONS "set( ${PROJECT_NAME}_DEFINITIONS ${GM_DEFINITIONS_STR})" )

GM_JOIN( "${GM_MODULE_TARGETS}" " " VAR_MODULE_TARGETS )

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
  ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}/${PROJECT_NAME}ConfigVersion.cmake
  VERSION ${PROJECT_VERSION}
  COMPATIBILITY ExactVersion
)

set(INCLUDE_INSTALL_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(SYSCONFIG_INSTALL_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
configure_package_config_file(
  ${CMAKE_SOURCE_DIR}/cmake/common/config.cmake.in
  ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}/${PROJECT_NAME}Config.cmake
  INSTALL_DESTINATION ${CMAKE_LIBRARY_PATH}/GMlib/cmake
  PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR
)








###### Custom carget for "other files" -- IDE friendly
set(GM_OTHER_FILES
  COPYING
  COPYING.LESSER
  README
  .gitignore
  .clang-format
  )
add_custom_target( CustomTargetForOtherFiles SOURCES ${GM_OTHER_FILES} )