forked from Exawind/amr-wind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
166 lines (135 loc) · 5.47 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
############################ BASE ######################################
cmake_minimum_required (VERSION 3.14 FATAL_ERROR)
project(AMR-Wind CXX C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
########################## OPTIONS #####################################
#General options for the project
option(AMR_WIND_ENABLE_FORTRAN "Enable Fortran interfaces" OFF)
option(AMR_WIND_ENABLE_DOCUMENTATION "Build documentation" OFF)
option(AMR_WIND_ENABLE_SPHINX_API_DOCS "Link Doxygen API docs to Sphinx" OFF)
option(AMR_WIND_ENABLE_ALL_WARNINGS "Show most warnings for most compilers" OFF)
option(AMR_WIND_ENABLE_FCOMPARE "Enable building fcompare when not testing" OFF)
#Enabling tests overrides the executable options
option(AMR_WIND_ENABLE_UNIT_TESTS "Enable unit testing" ON)
option(AMR_WIND_ENABLE_TESTS "Enable testing suite" OFF)
option(AMR_WIND_TEST_WITH_FCOMPARE "Check test plots against gold files" OFF)
#Options for the executable
option(AMR_WIND_ENABLE_MPI "Enable MPI" OFF)
option(AMR_WIND_ENABLE_OPENMP "Enable OpenMP" OFF)
option(AMR_WIND_ENABLE_CUDA "Enable CUDA" OFF)
# Third party libraries
option(AMR_WIND_ENABLE_NETCDF "Enable NetCDF library" OFF)
option(AMR_WIND_ENABLE_MASA "Enable MASA library" OFF)
#Options for C++
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(AMR_WIND_ENABLE_CUDA)
enable_language(CUDA)
if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "10.0")
message(FATAL_ERROR "Your nvcc version is ${CMAKE_CUDA_COMPILER_VERSION} which is unsupported."
"Please use CUDA toolkit version 10.0 or newer.")
endif()
endif()
if(AMR_WIND_TEST_WITH_FCOMPARE)
set(AMR_WIND_ENABLE_FCOMPARE ON)
endif()
########################### AMReX #####################################
set(AMREX_SUBMOD_LOCATION "${CMAKE_SOURCE_DIR}/submods/amrex")
include(${CMAKE_SOURCE_DIR}/cmake/set_amrex_options.cmake)
list(APPEND CMAKE_MODULE_PATH "${AMREX_SUBMOD_LOCATION}/Tools/CMake")
add_subdirectory(${AMREX_SUBMOD_LOCATION})
########################### AMR-Wind #####################################
if(AMR_WIND_ENABLE_MPI)
find_package(MPI REQUIRED)
endif()
# General information about machine, compiler, and build type
message(STATUS "AMR-Wind Information:")
message(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
include(${CMAKE_SOURCE_DIR}/cmake/set_rpath.cmake)
#Create target names
set(amr_wind_lib_name "amrwind_obj")
set(amr_wind_exe_name "amr_wind")
set(amr_wind_unit_test_exe_name "${amr_wind_exe_name}_unit_tests")
#Create main target executable
add_library(${amr_wind_lib_name} OBJECT)
add_executable(${amr_wind_exe_name})
include(${CMAKE_SOURCE_DIR}/cmake/set_compile_flags.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/amr-wind-utils.cmake)
if (AMR_WIND_ENABLE_FORTRAN)
#Keep our Fortran module files confined to a directory
set_target_properties(
${amr_wind_lib_name} PROPERTIES
Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/fortran_modules/")
endif()
if (AMR_WIND_ENABLE_NETCDF)
set(CMAKE_PREFIX_PATH ${NETCDF_DIR} ${CMAKE_PREFIX_PATH})
find_package(NetCDF REQUIRED)
endif()
if(AMR_WIND_ENABLE_MASA)
set(CMAKE_PREFIX_PATH ${MASA_DIR} ${CMAKE_PREFIX_PATH})
find_package(MASA QUIET REQUIRED)
if(MASA_FOUND)
message(STATUS "Found MASA = ${MASA_DIR}")
endif()
target_compile_definitions(${amr_wind_lib_name} PUBLIC AMR_WIND_USE_MASA)
target_link_libraries(${amr_wind_lib_name} PUBLIC MASA::MASA)
endif()
#Build amr-wind and link to amrex library
add_subdirectory(amr-wind)
if (AMR_WIND_ENABLE_CUDA)
set(awtargets "${amr_wind_lib_name};${amr_wind_exe_name}")
foreach(tgt IN LISTS awtargets)
get_target_property(AMR_WIND_SOURCES ${tgt} SOURCES)
list(FILTER AMR_WIND_SOURCES INCLUDE REGEX "\\.cpp")
set_source_files_properties(${AMR_WIND_SOURCES} PROPERTIES LANGUAGE CUDA)
endforeach()
endif()
if (AMR_WIND_ENABLE_UNIT_TESTS OR AMR_WIND_ENABLE_TESTS)
add_executable(${amr_wind_unit_test_exe_name})
add_subdirectory("submods/googletest")
add_subdirectory("unit_tests")
if (AMR_WIND_ENABLE_CUDA)
get_target_property(UTEST_SOURCES ${amr_wind_unit_test_exe_name} SOURCES)
set_source_files_properties(${UTEST_SOURCES} PROPERTIES LANGUAGE CUDA)
endif()
endif()
if(AMR_WIND_ENABLE_TESTS)
enable_testing()
include(CTest)
add_subdirectory(test)
endif()
if(AMR_WIND_ENABLE_DOCUMENTATION)
add_subdirectory(docs)
endif()
#Define what we want to be installed during a make install
install(
TARGETS ${amr_wind_exe_name} ${amr_wind_unit_test_exe_name}
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/amr-wind
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.H")
export(
TARGETS ${amr_wind_exe_name} ${amr_wind_unit_test_exe_name}
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}Targets.cmake
)
install(
EXPORT ${PROJECT_NAME}Targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
configure_package_config_file(
cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})