forked from Exawind/amr-wind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
148 lines (118 loc) · 5.52 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
############################ BASE ######################################
cmake_minimum_required (VERSION 3.14 FATAL_ERROR)
project(AMR-Wind CXX C Fortran)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(CMakePackageConfigHelpers)
########################## OPTIONS #####################################
#General options for the project
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)
#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)
endif()
########################### AMReX #####################################
set(AMREX_SUBMOD_LOCATION "submods/amrex")
include(${CMAKE_SOURCE_DIR}/cmake/set_amrex_options.cmake)
add_subdirectory(${AMREX_SUBMOD_LOCATION})
if(AMR_WIND_ENABLE_FCOMPARE OR AMR_WIND_TEST_WITH_FCOMPARE)
add_subdirectory(${AMREX_SUBMOD_LOCATION}/Tools/Plotfile)
endif()
########################### AMR-Wind #####################################
find_package(Python REQUIRED)
find_package(Threads REQUIRED) # Needed this for the Travis CI system
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}")
# 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)
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")
#Create target names
set(amr_wind_lib_name "amrwind")
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})
add_executable(${amr_wind_exe_name})
include(${CMAKE_SOURCE_DIR}/cmake/set_compile_flags.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/amr-wind-utils.cmake)
#Keep our Fortran module files confined to a unique directory for each executable
set_target_properties(${amr_wind_lib_name} PROPERTIES Fortran_MODULE_DIRECTORY
"${CMAKE_BINARY_DIR}/fortran_modules/")
#Create directory unique to executable to store generated files
set(GENERATED_FILES_DIR ${CMAKE_BINARY_DIR})
#Generate the AMReX_buildInfo.cpp file with Python
add_custom_target(generate_build_info ALL
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/${AMREX_SUBMOD_LOCATION}/Tools/C_scripts/makebuildinfo_C.py
--amrex_home "${CMAKE_SOURCE_DIR}/${AMREX_SUBMOD_LOCATION}"
--COMP ${CMAKE_CXX_COMPILER_ID} --COMP_VERSION ${CMAKE_CXX_COMPILER_VERSION}
--FCOMP ${CMAKE_Fortran_COMPILER_ID} --FCOMP_VERSION ${CMAKE_Fortran_COMPILER_VERSION}
--GIT "${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/${AMREX_SUBMOD_LOCATION}"
WORKING_DIRECTORY ${GENERATED_FILES_DIR} BYPRODUCTS ${GENERATED_FILES_DIR}/AMReX_buildInfo.cpp
COMMENT "Generating AMReX_buildInfo.cpp"
)
#Set the dependencies on targets so the generated source code files are there
#before we try to build the executable
add_dependencies(${amr_wind_lib_name} generate_build_info)
#Build amr-wind and link to amrex library
add_subdirectory(src)
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_TESTING 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_lib_name}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)