forked from ABRG-Models/morphologica
/
CMakeLists.txt
197 lines (170 loc) · 7.65 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
187
188
189
190
191
192
193
194
195
196
197
# AUTOMOC requires 2.8.6. The CMAKE_CXX_STANDARD variable requires 3.1.
cmake_minimum_required(VERSION 3.1)
project(morphologica)
set(VERSION 0.1)
set(SOVERSION 1.0)
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS " (This can be changed with `cmake -DCMAKE_INSTALL_PREFIX=/some/place`")
# From CMAKE_SYSTEM work out which of __OSX__, __GLN__, __NIX__ or
# __WIN__ are required
message(STATUS "Operating system: " ${CMAKE_SYSTEM})
if(CMAKE_SYSTEM MATCHES Linux.*)
set(MORPH_HOST_DEFINITION "-D__GLN__")
elseif(CMAKE_SYSTEM MATCHES BSD.*)
set(MORPH_HOST_DEFINITION "-D__NIX__")
elseif(APPLE)
set(MORPH_HOST_DEFINITION "-D__OSX__")
elseif(CMAKE_SYSTEM MATCHES Win.*)
set(MORPH_HOST_DEFINITION "-D__WIN__")
else()
message(ERROR " Operating system not supported: " ${CMAKE_SYSTEM})
endif()
# An option that's useful for Ubuntu 16.04 builds
option(USE_GLEW "Link libglew.so (try if the linker can't find glCreateVertexArrays)" OFF)
# Using c++-14 (calls to std::decay_t in number_type.h). c++-17
# required to allow brace initializers for the morph::Vector class
set (CMAKE_CXX_STANDARD 17)
# Add the host definition to CXXFLAGS along with other switches
if (APPLE)
set(CMAKE_CXX_FLAGS "${MORPH_HOST_DEFINITION} -Wall -g -O3")
else()
# To use Intel compiler, you can call cmake as: `cmake -DCMAKE_CXX_COMPILER=icpc ..` or `CXX=icpc cmake ..`
if (CMAKE_CXX_COMPILER_ID MATCHES Intel)
set(CMAKE_CXX_FLAGS "${MORPH_HOST_DEFINITION} -Wall -g -std=c++17 -xHOST -O3 -D__ICC__")
else () # GCC or Clang
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
# Add compiler version check, to ensure gcc is version 7 or later.
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.1)
message(FATAL_ERROR "GCC version must be at least 7.1! Use CXX=g++-7 cmake (options) and don't forget to clean out your build directory first!")
else()
message(STATUS "GCC version ${CMAKE_CXX_COMPILER_VERSION} OK!")
endif()
endif()
set(CMAKE_CXX_FLAGS "${MORPH_HOST_DEFINITION} -Wall -g -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -march=native -O3")
endif()
endif()
# Tell clang to be quiet about brace initialisers
if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces")
endif()
find_package(OpenMP)
if(OpenMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
# Following `cmake --help-policy CMP0072`
set(OpenGL_GL_PREFERENCE "GLVND")
# Additional GL compiler flags.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGL3_PROTOTYPES -DGL_GLEXT_PROTOTYPES")
if(USE_GLEW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_GLEW")
endif(USE_GLEW)
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGL_SILENCE_DEPRECATION")
endif()
# The code in VisualFace which builds the Vera family truetype fonts
# into the program binary needs to have a define of MORPH_FONTS_DIR,
# so set it up here:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMORPH_FONTS_DIR=\"\\\"${PROJECT_SOURCE_DIR}/fonts\\\"\"")
# Note that in client code you may have to do something similar. For
# example, if you're compiling with morphologica in a subdirectory, you may need:
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMORPH_FONTS_DIR=\"\\\"${PROJECT_SOURCE_DIR}/morphologica/fonts\\\"\"")
# The package managed version of armadillo8 on Ubuntu 18.04 LTS didn't
# work, but was required for OpenCV, so it's useful to be able to
# install a from-source build of Armadillo in /usr/local and link to
# this.
set(MORPH_ARMADILLO_LIBPATH "" CACHE PATH "The path to the armadillo library (e.g. /usr/local/lib)")
# A section to ensure library linking works on Apple. No longer necessary? Doesn't seem to be.
if(0)#APPLE
set(CMAKE_MACOSX_RPATH ON)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# the RPATH to be used when installing
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
include_directories(/usr/local/include)
endif()
# Lib finding
find_package(jsoncpp REQUIRED)
find_package(OpenCV REQUIRED)
find_package(OpenGL REQUIRED)
if(USE_GLEW)
find_package(GLEW REQUIRED)
endif(USE_GLEW)
# X11 is required only for morphdisplay0 on Apple, which uses Cocoa for glfw3/GL.
find_package(X11 REQUIRED)
find_package(glfw3 3.3 REQUIRED)
find_package(LAPACK REQUIRED)
# Find the HDF5 library. To prefer the use of static linking of HDF5, set HDF5_USE_STATIC_LIBRARIES first
#set(HDF5_USE_STATIC_LIBRARIES ON)
find_package(HDF5 REQUIRED)
find_package(Armadillo REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${OPENGL_INCLUDE_DIR})
include_directories(${X11_INC_SEARCH_PATH})
include_directories(${HDF5_INCLUDE_DIR})
# Two possible values for the armadillo include dirs
include_directories(${ARMADILLO_INCLUDE_DIR} ${ARMADILLO_INCLUDE_DIRS})
include_directories(${GLFW3_INCLUDE_DIR})
get_target_property(JSON_INC_PATH jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES)
include_directories(${JSON_INC_PATH})
# New, text rendering dependencies
find_package(Freetype REQUIRED)
include_directories(${FREETYPE_INCLUDE_DIRS})
# rapidxml is bundled in the source, but its headers will be installed in ${CMAKE_INSTALL_PREFIX}/morph/, and they're symlinked in ${PROJECT_SOURCE_DIR}/morph
#include_directories("${PROJECT_SOURCE_DIR}/include/rapidxml-1.13")
# OpenGL code needs the local include directory, too
include_directories("${PROJECT_SOURCE_DIR}/include")
# Library code is compiled up as a shared library in lib/ (could also
# be compiled static if needed)
add_subdirectory(morph)
# We have to make a morph/rapidxml-1.13 installation for client code
# that uses the ReadCurves class.
add_subdirectory(include)
# Unit testing using the ctest framework
enable_testing()
add_subdirectory(tests)
# Install the font files, for the examples, which seek to work with an
# *installed* morphologica, as opposed to an in-tree morphologica.
add_subdirectory(fonts)
# Example code (you can also see tests/ for examples)
add_subdirectory(examples)
# first we can indicate the documentation build as an option and set it to ON by default
option (BUILD_DOC "Build documentation" OFF)
if (BUILD_DOC)
# check if Doxygen is installed
find_package(Doxygen)
if(DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the application
add_custom_target(doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else(DOXYGEN_FOUND)
message("Need doxygen for documentation")
endif(DOXYGEN_FOUND)
endif (BUILD_DOC)
# For debugging of variables:
option(DEBUG_VARIABLES OFF)
if(DEBUG_VARIABLES)
get_cmake_property(_variableNames VARIABLES)
foreach(_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endif(DEBUG_VARIABLES)