forked from CambridgeNuclear/SCONE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
215 lines (169 loc) · 7.68 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
####################################################################################################
# CMAKE requirements and project INFO
cmake_minimum_required(VERSION 3.10)
project(SCONE)
# Set CMAKE Policies
# CMP0074: Starting with CMake 3.12, all `find_package` commands will use `<package>_ROOT`
# variables as hints for where to search. This policy provides compatibility
# with older projects.
# https://cmake.org/cmake/help/latest/policy/CMP0074.html
cmake_policy(SET CMP0074 NEW)
####################################################################################################
# DEFINE COMPILATION OPTIONS
option(BUILD_TESTS "If is set to ON will compile tests" ON)
option(LTO "Enables link-time optimisation" ON)
option(COVERAGE "Collect Coverage Info" OFF)
option(DEBUG "Enable extra run-time checks" OFF)
option(OPENMP "Enable parallelism with OpenMP" ON)
# Include local cmake modules. TODO: Test on WINDOWS!!!
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
####################################################################################################
# CONFIGURE FORTRAN COMPILER
#
# NOTE:
# Compiler flags are set for gfortran
#
enable_language(Fortran)
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/modFiles)
# Add compilers flags
# The flags set below will be applied to all Fortran files
#
set(CMAKE_Fortran_FLAGS "-std=f2008 -O3 -g -pedantic -Wall -Wno-unused-dummy-argument -cpp")
# Add extra flags to all Fortran files
if(COVERAGE)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -coverage")
endif()
# Add Debugging flags to scone library
# NOTE: GFortran 7.5 may give buggy warnings here
# If this is an issue, consider using `-fcheck=bounds,do,mem,pointer`
# https://github.com/CambridgeNuclear/SCONE/pull/15#issuecomment-1384192425
if(DEBUG)
list(APPEND scone_extra_flags "-fcheck=all,no-array-temps" "-Waliasing")
endif()
# If LTO is requested check if it is supported by compiler
# LTO flags will be set by CMAKE via `set_property` command later
if(LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT has_lto OUTPUT lto_error)
if(NOT has_lto)
message(STATUS "<><><><><><><><><><><><><><><><><><><><><><><><><><>")
message(FATAL_ERROR "LTO was requested but it is not supported by the compiler. "
"Use -DLTO=FALSE option to disable LTO. Error message: <${lto_error}>")
endif()
endif()
# Set up OpenMP
if(OPENMP)
find_package(OpenMP)
if(NOT OpenMP_Fortran_FOUND)
message(STATUS "<><><><><><><><><><><><><><><><><><><><><><><><><><>")
message(FATAL_ERROR "It seems that the Fortran compiler does not support OpanMP"
"Use -DOPENMP=OFF to disable")
endif()
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
endif()
####################################################################################################
# CHECK FOR DEPENDENCIES
# Add environmental variable to default search directories
list(APPEND CMAKE_PREFIX_PATH $ENV{LAPACK_INSTALL})
find_package(LAPACK REQUIRED )
message(STATUS ${LAPACK_LIBRARIES})
# Dependencies for BUILD_TESTS
if (BUILD_TESTS)
# FIND PYTHON INTERPRETER
# Sets PYTHONINTERP_FOUND & PYTHON_EXECUTABLE
find_package(PythonInterp REQUIRED)
find_package(PFUNIT 4.7 REQUIRED)
add_library(pFUnit STATIC IMPORTED)
set_property(TARGET pFUnit PROPERTY IMPORTED_LOCATION ${PFUNIT_LIBRARIES})
endif()
####################################################################################################
# IMPORT FUNCTIONS TO COLLECT SOURCE FILES
include(add_sources)
include(add_unit_tests)
include(add_integration_tests)
####################################################################################################
# COLLECT ALL SOURCE AND TEST FILES
# Include Nested Directories
add_subdirectory(RandomNumbers)
add_subdirectory(LinearAlgebra)
add_subdirectory(SharedModules)
add_subdirectory(Visualisation)
add_subdirectory(ParticleObjects)
add_subdirectory(NamedGrids)
add_subdirectory(NuclearData)
add_subdirectory(Geometry)
add_subdirectory(Tallies)
add_subdirectory(CollisionOperator)
add_subdirectory(TransportOperator)
add_subdirectory(UserInterface)
add_subdirectory(PhysicsPackages)
add_subdirectory(DataStructures)
####################################################################################################
# Compile SCONE static library
# Copy source files collected in add_sources to variable SRCS
get_property(SRCS GLOBAL PROPERTY SRCS_LIST)
# Compile library
add_library(scone STATIC ${SRCS})
target_compile_options(scone PRIVATE ${scone_extra_flags} )
target_link_libraries(scone ${LAPACK_LIBRARIES} )
if(LTO)
set_property(TARGET scone PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
####################################################################################################
# COMPILE SOLVERS
add_executable(scone.out ./Apps/scone.f90 )
target_link_libraries(scone.out scone )
####################################################################################################
# COMPILE UNIT TESTS
if(BUILD_TESTS)
enable_testing()
get_property(UNIT_TESTS GLOBAL PROPERTY UNIT_TESTS_LIST)
# Make absolute paths relative to source directory
foreach(_testPath IN LISTS UNIT_TESTS)
file(RELATIVE_PATH _testPath ${CMAKE_SOURCE_DIR} ${_testPath})
list(APPEND UNIT_TESTS_RELATIVE ${_testPath})
endforeach()
add_pfunit_ctest(unitTests
TEST_SOURCES ${UNIT_TESTS_RELATIVE}
LINK_LIBRARIES scone ${LAPACK_LIBRARIES}
)
# pFUnit may have a bug which causes a unused variable `class(Test), allocatable :: t` be
# present if the suite contains only a TestCase and its methods
# We need to suppress this warning for clarity
target_compile_options(unitTests PRIVATE "-Wno-unused-variable" )
####################################################################################################
# COMPILE INTEGRATION TESTS
get_property(INTEGRATION_TESTS GLOBAL PROPERTY INTEGRATION_TESTS_LIST)
# Make absolute paths relative to source directory
foreach(_testPath IN LISTS INTEGRATION_TESTS)
file(RELATIVE_PATH _testPath ${CMAKE_SOURCE_DIR} ${_testPath})
list(APPEND INTEGRATION_TESTS_RELATIVE ${_testPath})
endforeach()
add_pfunit_ctest(integrationTests
TEST_SOURCES ${INTEGRATION_TESTS_RELATIVE}
LINK_LIBRARIES scone ${LAPACK_LIBRARIES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
# pFUnit may have a bug which causes a unused variable `class(Test), allocatable :: t` be
# present if the suite contains only a TestCase and its methods
# We need to suppress this warning for clarity
target_compile_options(integrationTests PRIVATE "-Wno-unused-variable" )
endif()
####################################################################################################
# Print summary of CMake options
#
message(STATUS "")
message(STATUS " ><((((*> ><((((*> ><((((*> ><((((*> ><((((*> ><((((*> ")
message(STATUS " SCONE CONFIGURATION SUMMARY")
message(STATUS " Unit Tests: " ${BUILD_TESTS})
message(STATUS " Link-time optimisation: " ${LTO})
message(STATUS " Code coverage logging: " ${COVERAGE})
message(STATUS " Extra runtime debug checks: " ${DEBUG})
message(STATUS " OpenMP parallelism: " ${OPENMP})
message(STATUS " Fortran compiler: " ${CMAKE_Fortran_COMPILER})
message(STATUS " Compiler version: " ${CMAKE_Fortran_COMPILER_VERSION})
message(STATUS " OpenMP version: " ${OpenMP_CXX_VERSION})
message(STATUS " Global Fortran flags: " ${CMAKE_Fortran_FLAGS})
message(STATUS " SCONE library flags: " "${scone_extra_flags}")
message(STATUS " <*))))>< <*))))>< <*))))>< <*))))>< <*))))>< <*))))>< ")
message(STATUS "")