forked from fortran-lang/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdlib.cmake
49 lines (42 loc) · 1.81 KB
/
stdlib.cmake
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
# Preprocesses a list of files with given preprocessor and preprocessor options
#
# Args:
# preproc [in]: Preprocessor program
# preprocopts [in]: Preprocessor options
# srcext [in]: File extension of the source files
# trgext [in]: File extension of the target files
# srcfiles [in]: List of the source files
# trgfiles [out]: Contains the list of the preprocessed files on exit
#
function(preprocess preproc preprocopts srcext trgext srcfiles trgfiles)
set(_trgfiles)
foreach(srcfile IN LISTS srcfiles)
string(REGEX REPLACE "\\.${srcext}$" ".${trgext}" trgfile ${srcfile})
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}
COMMAND ${preproc} ${preprocopts} ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile} ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile})
list(APPEND _trgfiles ${CMAKE_CURRENT_BINARY_DIR}/${trgfile})
endforeach()
set(${trgfiles} ${_trgfiles} PARENT_SCOPE)
endfunction()
# Preprocesses fortran files with fypp.
#
# It assumes that source files have the ".fypp" extension. Target files will be
# created with the extension ".f90". The FYPP variable must contain the path to
# the fypp-preprocessor.
#
# Args:
# fyppopts [in]: Options to pass to fypp.
# fyppfiles [in]: Files to be processed by fypp
# f90files [out]: List of created f90 files on exit
#
function (fypp_f90 fyppopts fyppfiles f90files)
preprocess("${FYPP}" "${fyppopts}" "fypp" "f90" "${fyppfiles}" _f90files)
set(${f90files} ${_f90files} PARENT_SCOPE)
endfunction()
# For fortran sources that contain C preprocessor flags: create ".F90" files
function (fypp_f90pp fyppopts fyppfiles F90files)
preprocess("${FYPP}" "${fyppopts}" "fypp" "F90" "${fyppfiles}" _F90files)
set(${F90files} ${_F90files} PARENT_SCOPE)
endfunction()