-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
98 lines (78 loc) · 2.9 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
cmake_minimum_required(VERSION 3.10)
# set the project name
set(CMAKE_PROJECT_NAME "SurfATT")
project(${CMAKE_PROJECT_NAME} VERSION 1.5.1 LANGUAGES Fortran CXX)
# set the version number and git commit hash
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(
${PROJECT_SOURCE_DIR}/include/version.h.in
${PROJECT_SOURCE_DIR}/include/version.h
)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules)
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
set(MPI_Fortran_COMPILE_FLAGS "-ffixed-line-length-none -O3")
elseif ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel")
set(MPI_Fortran_COMPILE_FLAGS "-132 -xHost -O3")
endif()
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${MPI_Fortran_COMPILE_FLAGS}")
set(CMAKE_CXX_STANDARD 17)
set(BUILD_TESTING OFF)
set(SOURCE_DIR "${PROJECT_SOURCE_DIR}/src")
# setup mpi
find_package(MPI REQUIRED)
message(STATUS "MPI_FOUND: ${MPI_FOUND}")
message(STATUS "MPI_VERSION: ${MPI_VERSION}")
find_package(HDF5 REQUIRED COMPONENTS Fortran HL)
include_directories(${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
message(STATUS "HDF5_FOUND: ${HDF5_FOUND}")
message(STATUS "HDF5_VERSION: ${HDF5_VERSION}")
# add sub modules
find_package(yaml-cpp 0.8 QUIET)
if (yaml-cpp_FOUND)
message(STATUS "yaml-cpp found")
message(STATUS "YAML_CPP_INCLUDE_DIR: ${YAML_CPP_INCLUDE_DIR}")
message(STATUS "YAML_CPP_LIBRARIES: ${YAML_CPP_LIBRARIES}")
else()
message(STATUS "yaml-cpp not found. Using external_libs/yaml-cpp ...")
add_subdirectory("${PROJECT_SOURCE_DIR}/external_libs")
set(YAML_CPP_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/external_libs/yaml-cpp/include)
set(YAML_CPP_LIBRARIES yaml-cpp)
endif()
# surfatt_modules
add_subdirectory("${SOURCE_DIR}")
# setup include directory
include_directories(
${PROJECT_SOURCE_DIR}/include
)
set(APP_SOURCES
${SOURCE_DIR}/surfatt_tomo.f90
${SOURCE_DIR}/surfatt_cb_fwd.f90
${SOURCE_DIR}/surfatt_tomo2d.f90
${SOURCE_DIR}/surfatt_rotate_src_rec.f90
${SOURCE_DIR}/surfatt_rotate_topo.f90
${SOURCE_DIR}/surfatt_rotate_model.f90
)
foreach(execsourcefile ${APP_SOURCES})
# get exec name
get_filename_component(EXEC_NAME ${execsourcefile} NAME_WE)
# add executable
add_executable(${EXEC_NAME} ${execsourcefile})
# link MPI
target_link_libraries(${EXEC_NAME} PUBLIC MPI::MPI_Fortran)
# link yaml-app:
target_link_libraries(${EXEC_NAME} PUBLIC fortran-yaml)
# link fortran-csv
target_link_libraries(${EXEC_NAME} PUBLIC fortran-csv)
# link h5fortran
target_link_libraries(${EXEC_NAME} PUBLIC ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
# link surfatt_modules
target_link_libraries(${EXEC_NAME} PUBLIC shared_obj surfker_obj surfatt_modules)
# set linker language
set_target_properties(${EXEC_NAME} PROPERTIES LINKER_LANGUAGE Fortran)
endforeach()