@@ -13,35 +13,55 @@ enable_testing()
13
13
# SWIG setup
14
14
##---------------------------------------------------------------------------##
15
15
16
- find_package (SWIG REQUIRED)
17
- list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" )
18
- include (CheckSWIGFortran)
19
- if (CMAKE_VERSION VERSION_LESS 3.20)
20
- # TODO: This is until Fortran support gets added to the upstream cmake script
21
- include (UseSWIGFortran)
16
+ option (USE_SWIG "Enable SWIG generation" ON )
17
+ if (USE_SWIG)
18
+ find_package (SWIG)
19
+ endif ()
20
+
21
+ if (USE_SWIG AND SWIG_FOUND)
22
+ # SWIG is requested and available; make sure it's the Fortran fork.
23
+ list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" )
24
+ include (CheckSWIGFortran)
25
+ if (CMAKE_VERSION VERSION_LESS 3.20)
26
+ # TODO: This is until Fortran support gets added to the upstream cmake script
27
+ include (UseSWIGFortran)
28
+ else ()
29
+ cmake_policy (SET CMP0078 "NEW" )
30
+ cmake_policy (SET CMP0086 "NEW" )
31
+ include (UseSWIG)
32
+ endif ()
22
33
else ()
23
- cmake_policy (SET CMP0078 "NEW" )
24
- cmake_policy (SET CMP0086 "NEW" )
25
- include (UseSWIG)
34
+ set (USE_SWIG FALSE )
26
35
endif ()
27
36
28
37
##---------------------------------------------------------------------------##
29
38
# LIBRARY
30
39
##---------------------------------------------------------------------------##
40
+ set (GENERATE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /src/generated )
31
41
32
- macro (swig_fortran_add_library name )
42
+ function (swig_fortran_add_library name )
33
43
# We're using C++
34
44
set_property (SOURCE src/${name} .i PROPERTY CPLUSPLUS ON )
35
45
# We need to include the source directory
36
46
set_property (SOURCE src/${name} .i
37
47
PROPERTY USE_TARGET_INCLUDE_DIRECTORIES ON )
38
48
39
- # Create the library
40
- swig_add_library(${name}
41
- LANGUAGE Fortran
42
- TYPE USE_BUILD_SHARED_LIBS
43
- OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR} /src/generated
44
- SOURCES src/${name} .i ${ARGN} )
49
+ if (USE_SWIG)
50
+ # SWIG is available; actually generate the library dynamically.
51
+ # Create the library
52
+ swig_add_library(${name}
53
+ LANGUAGE Fortran
54
+ TYPE USE_BUILD_SHARED_LIBS
55
+ OUTPUT_DIR "${GENERATE_DIR} "
56
+ SOURCES src/${name} .i ${ARGN} )
57
+ else ()
58
+ # SWIG is *not* being used: compile the code committed in the repository,
59
+ # generated by the developer with SWIG.
60
+ add_library (${name}
61
+ "${GENERATE_DIR} /${name} .f90"
62
+ "${GENERATE_DIR} /${name} FORTRAN_wrap.cxx"
63
+ ${ARGN} )
64
+ endif ()
45
65
46
66
# Enable C++11
47
67
target_compile_features (${name} PRIVATE cxx_std_11)
@@ -61,7 +81,7 @@ macro(swig_fortran_add_library name)
61
81
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR} >
62
82
$<INSTALL_INTERFACE:modules>
63
83
)
64
- endmacro ()
84
+ endfunction ()
65
85
66
86
# Four SWIG libraries
67
87
swig_fortran_add_library(utils)
0 commit comments