forked from dekamps/miind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
260 lines (222 loc) · 10.3 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
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
257
258
259
project( miind )
cmake_minimum_required(VERSION 2.6)
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake-modules )
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
enable_language(C CXX)
# include cmake scripts
#############################################################################
IF (APPLE)
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake-modules ${PROJECT_SOURCE_DIR}/cmake-modules/APPLE )
ELSE (APPLE)
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake-modules )
ENDIF (APPLE)
# require out-of-source build
INCLUDE(require_out_of_src_build)
MACRO_REQUIRE_OUT_OF_SRC_BUILD("Miind requires out-of-source builds.")
# default install prefix. can be set with ccmake
set( CMAKE_INSTALL_PREFIX "/usr/local" CACHE STRING "Install prefix." )
set( MIIND_LIBRARY_PREFIX "miind" CACHE STRING "prefix string for all libs" )
# On linux, we define all libs as shared so they can be used in
# generated python import libraries. On windows, we don't need to do that.
# If we need dlls in windows instead of static lib files,
# we need to set DLL export macro here and will need to go through *ALL*
# classes we want to export... yeesh...
#if (WIN32)
#add_compile_definitions("DllExport=__declspec(dllexport)")
#else(WIN32)
#add_compile_definitions("DllExport=")
#endif(WIN32)
##############################################################################
# cmake options
##############################################################################
OPTION(ENABLE_OPENMP "Enable OpenMP" ON)
OPTION(ENABLE_CUDA "Enable CUDA" OFF)
OPTION(ENABLE_TESTING "Compile tests" OFF)
OPTION(ENABLE_ROOT "Root Desired" OFF)
OPTION(ENABLE_MEMORY_TEST "Generate memory test" OFF)
OPTION(ENABLE_MPI "Enable mpi" OFF)
OPTION(ENABLE_COVERAGE "Enable GCov coverage analysis (defines a 'coverage' target and enforces static build of miind)" OFF)
set(DEBUGLEVEL "logINFO" CACHE STRING "Define the Debug Level")
add_definitions( -DDEBUGLEVEL=${DEBUGLEVEL})
##############################################################################
# compile flags
##############################################################################
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -Wall -Wextra -Wno-unused-parameter -Wno-error=unused-parameter -O0 -pedantic")
endif(CMAKE_COMPILER_IS_GNUCXX)
if (APPLE)
# -D_GLIBCXX_USE_CXX11_ABI=0 sets the ABI to match older boost unit test framework on mac
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC")
set(GLUT_LIBRARY "-lGL -lGLU -lGLUT")
else (APPLE)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fext-numeric-literals -fPIC")
set(GLUT_LIBRARY "-lGL -lGLU -lglut")
endif(CMAKE_COMPILER_IS_GNUCXX)
endif(APPLE)
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
##############################################################################
# enable MPI dependent build
##############################################################################
# Require MPI for this project:
IF(ENABLE_MPI)
MESSAGE(STATUS "MPI enabled")
find_package(MPI REQUIRED)
add_definitions( -DENABLE_MPI=1 )
ENDIF(ENABLE_MPI)
IF(ENABLE_OPENMP)
if (APPLE)
if(ENABLE_OPENMP)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
message ( "Setting OpenMP_C_FLAGS for Clang.")
set(OpenMP_C "${CMAKE_C_COMPILER}")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -Wno-unused-command-line-argument")
set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5")
set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES})
set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES})
set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES})
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message ( "Setting OpenMP_CXX_FLAGS for Clang.")
set(OpenMP_CXX "${CMAKE_CXX_COMPILER}")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -Wno-unused-command-line-argument")
set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5")
set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES})
endif()
endif()
endif()
find_package(OpenMP REQUIRED)
if (OpenMP_FOUND AND APPLE)
message ( "Found OpenMP. Try to find omp.h..." )
find_path(OpenMP_INCLUDE_DIR
omp.h
)
message ( "Adding include directories: ${OpenMP_INCLUDE_DIR} ")
include_directories("${OpenMP_INCLUDE_DIR}")
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}")
endif(OpenMP_FOUND AND APPLE)
add_definitions( -DENABLE_OPENMP=1 )
ENDIF(ENABLE_OPENMP)
IF (WIN32 OR APPLE) # For windows packaging, we want to include the glut dll so we need FindGLUT to find it during install
#message( "installed to ${VCPKG_INSTALLED_DIR}")
#set(OPENGL_LIBRARY_DIR "${VCPKG_INSTALLED_DIR}/lib")
find_package(GLUT REQUIRED)
if (GLUT_FOUND AND APPLE)
add_definitions( -DUSING_APPLE_GLUT=1 ) # this tells TwoDLib/display.cpp to avoid non mac-glut functions.
endif(GLUT_FOUND AND APPLE)
ENDIF (WIN32 OR APPLE)
IF(ENABLE_OPENMP)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ENDIF(ENABLE_OPENMP)
IF(ENABLE_MPI)
set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})
set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS})
include_directories(${MPI_INCLUDE_PATH})
ENDIF(ENABLE_MPI)
##############################################################################
# find boost with mpi
##############################################################################
IF(ENABLE_MPI)
# On mac, if boost-mpi is installed, without manually being told where boost is,
# cmake can't find it.
if (APPLE)
set(Boost_NO_BOOST_CMAKE ON)
endif (APPLE)
find_package( Boost COMPONENTS unit_test_framework filesystem program_options mpi thread serialization timer system REQUIRED)
ELSE(ENABLE_MPI)
find_package( Boost COMPONENTS unit_test_framework filesystem program_options thread serialization timer system REQUIRED)
ENDIF(ENABLE_MPI)
if( Boost_FOUND )
message(STATUS "Boost found setting up directories")
message(STATUS "BOOST_ROOT: " ${BOOST_ROOT} )
message(STATUS "Boost include directories:" ${Boost_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} )
message(STATUS "Boost library directories:" ${Boost_LIBRARY_DIRS} ${Boost_LIBRARY_DIR_RELEASE} ${Boost_LIBRARY_DIR} )
include_directories( ${Boost_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} )
link_directories( ${Boost_LIBRARY_DIRS} ${Boost_LIBRARY_DIR_RELEASE} ${Boost_LIBRARY_DIR} )
else ( Boost_FOUND )
message("Boost is not found. Non MPI only.")
endif( Boost_FOUND )
##############################################################################
#
##############################################################################
IF(ENABLE_ROOT)
find_package( Root )
if( ROOT_FOUND )
message(STATUS "Building Root dependent parts")
message(STATUS "Root include directories:" ${ROOT_INCLUDE_DIRS})
message(STATUS "Root library directories:" ${ROOT_LIBRARY_DIRS})
set (ROOT_LIBRARIES Core Hist Tree Matrix MathCore MathMore Gpad Graf Postscript RIO)
add_definitions(-DWANTROOT)
else( ROOT_FOUND )
message(FATAL_ERROR "Root is required for MPILib")
endif( ROOT_FOUND )
# TODO: This is ugly and must be fixed in the windows install procedure
if (WIN32)
SET (LIB_PREFIX lib)
else (WIN32)
SET (CBLAS_PREFIX gsl)
endif (WIN32)
ENDIF (ENABLE_ROOT)
#############################################################################
# code coverage analysis
#############################################################################
IF (ENABLE_COVERAGE)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ENABLE_TESTING)
MESSAGE(STATUS "Coverage enabled")
MESSAGE(WARNING "At the moment lcov does not work with gcc 4.7, therefore coverage fails")
INCLUDE(CodeCoverage)
SETUP_TARGET_FOR_COVERAGE(coverage test coverageReport)
ELSEIF(NOT ENABLE_TESTING)
MESSAGE(FATAL_ERROR "Coverage analysis requires Testing Enabled")
ELSE()
MESSAGE(FATAL_ERROR "Coverage analysis requires DEBUG build")
ENDIF()
ELSE()
MESSAGE(STATUS "Coverage disabled")
ENDIF()
#############################################################################
# documentation
#############################################################################
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/doc/Doxyfile.cmake
${CMAKE_BINARY_DIR}/doc/Doxyfile
@ONLY IMMEDIATE
)
FIND_PACKAGE(Doxygen)
# target for doxygen
ADD_CUSTOM_TARGET(doc COMMAND ${DOXYGEN} ${CMAKE_BINARY_DIR}/doc/Doxyfile)
IF(ENABLE_TESTING AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
MESSAGE(STATUS "Testing enabled")
INCLUDE(CTest)
ENABLE_TESTING()
ELSE(ENABLE_TESTING AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
MESSAGE(STATUS "Testing disabled, enable testing and Debug build")
ENDIF(ENABLE_TESTING AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
include_directories( ./libs )
message("========================================Common settings done going on with libs===================================")
ADD_SUBDIRECTORY( libs )
message("========================================libs set and done continuing with apps====================================")
ADD_SUBDIRECTORY( apps )
message("========================================compiler flags====================================")
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
MESSAGE(STATUS "Compiler flags:" ${CMAKE_CXX_COMPILE_FLAGS})
MESSAGE(STATUS "Compiler cxx debug flags:" ${CMAKE_CXX_FLAGS_DEBUG})
MESSAGE(STATUS "Compiler cxx release flags:" ${CMAKE_CXX_FLAGS_RELEASE})
MESSAGE(STATUS "Compiler cxx min size flags:" ${CMAKE_CXX_FLAGS_MINSIZEREL})
MESSAGE(STATUS "Compiler cxx flags:" ${CMAKE_CXX_FLAGS})
ADD_SUBDIRECTORY( python )
ADD_SUBDIRECTORY( examples )
if (NOT SKBUILD) # If miind is being built as a standalone (not a pip wheel)
message("======================================== Please update ENV variables ====================================")
message("")
message("export PATH=$PATH:${CMAKE_INSTALL_PREFIX}/share/miind/python/miind")
message("export PYTHONPATH=$PYTHONPATH:${CMAKE_INSTALL_PREFIX}/share/miind/python/")
message("export OMP_NUM_THREADS=<NUMBER OF AVAILABLE CORES>" )
message("")
message("==========================================================================================================")
endif (NOT SKBUILD)