-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
179 lines (146 loc) · 5.71 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
# -*- coding: utf-8; mode: cmake -*-
# global CMakeLists.txt
# (c) lloda@sarc.name 2019
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.
# -------------------
# readme
# -------------------
# cd build && FFLAGS=-O3 cmake -DCMAKE_INSTALL_PREFIX=./install .. && VERBOSE=1 make && make test && cmake
# -------------------
# prologue
# -------------------
project (prop_618)
enable_language (Fortran C)
cmake_minimum_required (VERSION 3.5)
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
include_directories (${CMAKE_SOURCE_DIR}/mod)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/config)
# -------------------
# body
# -------------------
set (BASE_FFLAGS "-std=f2018 -fopenmp -fdiagnostics-color=always -Wall -Werror \
-fdefault-real-8 -fbounds-check -fimplicit-none -ffpe-summary=invalid,overflow,zero")
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${BASE_FFLAGS} $ENV{FFLAGS}")
set (BASE_CLAGS " -std=c17 -fopenmp -fdiagnostics-color=always -Wall -Werror")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${BASE_CFLAGS} $ENV{CFLAGS}")
set (LINK_FLAGS "-fopenmp $ENV{LINKFLAGS}")
include (GNUInstallDirs)
set (PROP_DATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/prop-618/")
set (PROP_TEST_DATADIR "${CMAKE_SOURCE_DIR}/data/")
configure_file (src/config.f90.in config.f90)
add_library (prop SHARED src/prop.f90 config.f90)
add_library (atmospheres SHARED src/atmospheres.f90 config.f90)
# -------------------
# bindings
# -------------------
# If Guile isn't available, will rely on committed bindings in mod/.
find_package (Guile)
if (GUILE_EXECUTABLE)
add_custom_target (bindings ALL)
foreach (libname atmospheres prop)
set (source "${CMAKE_SOURCE_DIR}/src/${libname}.f90")
set (generator "${CMAKE_SOURCE_DIR}/config/protos.scm")
set (bindc "${CMAKE_SOURCE_DIR}/mod/${libname}.h")
set (bindpython "${CMAKE_SOURCE_DIR}/mod/prop_618/${libname}.py")
set (bindguile "${CMAKE_SOURCE_DIR}/mod/prop-618/${libname}.scm")
foreach (dest ${bindc} ${bindpython} ${bindguile})
get_filename_component (dest_as_target ${dest} NAME)
add_custom_target (${dest_as_target}
DEPENDS ${source} ${generator}
COMMAND ${GUILE_EXECUTABLE} -s ${generator} ${libname} ${dest} ${source}
BYPRODUCTS ${dest}
COMMENT "Generating binding file ${dest}"
VERBATIM)
add_dependencies (bindings ${dest_as_target})
endforeach ()
endforeach ()
endif ()
# -------------------
# tests
# -------------------
# Fortran, this has the functional tests.
foreach (target test-0)
add_executable (${target} "test/${target}.f90")
target_link_libraries (${target} prop atmospheres)
add_test (${target} ${target})
endforeach ()
# C, just the headers.
foreach (target test-1)
add_executable (${target} "test/${target}.c"
${CMAKE_SOURCE_DIR}/mod/atmospheres.h
${CMAKE_SOURCE_DIR}/mod/prop.h)
target_link_libraries (${target} prop atmospheres)
add_test (${target} ${target})
endforeach ()
# Python, just the bindings.
find_package (Python3)
if (Python3_FOUND)
foreach (target test-2)
# FIXME Would like a way to make these depend on mod/*.py
add_test (${target} ${Python3_EXECUTABLE} "${CMAKE_SOURCE_DIR}/test/${target}.py")
set_tests_properties (${target} PROPERTIES ENVIRONMENT
"LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/;PYTHONPATH=${CMAKE_SOURCE_DIR}/mod")
endforeach ()
endif ()
# Guile, just test the bindings.
if (GUILE_EXECUTABLE)
foreach (target test-3)
# FIXME Would like a way to make these depend on mod/*.py
add_test (${target} ${GUILE_EXECUTABLE} -q -L "${CMAKE_SOURCE_DIR}/mod" "${CMAKE_SOURCE_DIR}/test/${target}.scm")
set_tests_properties (${target} PROPERTIES ENVIRONMENT
"LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}")
endforeach ()
endif ()
# -------------------
# documentation
# -------------------
# add_subdirectory (docs)
# -------------------
# install
# -------------------
install (DIRECTORY "${CMAKE_SOURCE_DIR}/data/"
DESTINATION "${CMAKE_INSTALL_DATADIR}/prop-618")
foreach (module prop atmospheres)
install (TARGETS ${module}
DESTINATION lib)
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/${module}.mod"
DESTINATION include)
install (FILES "${CMAKE_SOURCE_DIR}/mod/${module}.h"
DESTINATION include)
endforeach ()
if (GUILE_FOUND)
foreach (module prop atmospheres)
install (FILES "${CMAKE_SOURCE_DIR}/mod/prop-618/${module}.scm"
DESTINATION "${CMAKE_INSTALL_DATADIR}/guile/site/prop-618")
endforeach ()
endif ()
if (Python3_FOUND)
execute_process(
COMMAND "${Python3_EXECUTABLE}" -c "if True:
from distutils import sysconfig as sc
print(sc.get_python_lib(prefix='', plat_specific=True))"
OUTPUT_VARIABLE Python3_SITE
OUTPUT_STRIP_TRAILING_WHITESPACE)
message ("* Python3 install site: ${Python3_SITE}")
foreach (module prop atmospheres)
install(FILES "${CMAKE_SOURCE_DIR}/mod/prop_618/${module}.py"
DESTINATION "${Python3_SITE}/prop_618") # FIXME maybe I should just change this
endforeach ()
endif ()
# -------------------
# epilogue
# -------------------
enable_testing ()
message ("* Current build type is: ${CMAKE_BUILD_TYPE}")
message ("* Crosscompiling is: ${CMAKE_CROSSCOMPILING}")
message ("* C compiler is: ${CMAKE_C_COMPILER}")
message ("* C flags are: ${CMAKE_C_FLAGS}")
message ("* C++ compiler is: ${CMAKE_CXX_COMPILER}")
message ("* C++ flags are: ${CMAKE_CXX_FLAGS}")
message ("* Fortran compiler is: ${CMAKE_Fortran_COMPILER}")
message ("* Fortran_FLAGS are: ${CMAKE_Fortran_FLAGS}")
message ("* Current binary dir is: ${CMAKE_BINARY_DIR}")
message ("* Install prefix is: ${CMAKE_INSTALL_PREFIX}")