-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
112 lines (95 loc) · 3.53 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
##---------------------------------------------------------------------------##
## File : algorithm/CMakeLists.txt
## Author: Seth R Johnson
## Date : Tue Dec 06 11:46:55 2016
## Copyright (c) 2016 Oak Ridge National Laboratory, UT-Battelle, LLC.
##---------------------------------------------------------------------------##
cmake_minimum_required(VERSION 3.8)
project(swig-fortran-sample CXX Fortran)
enable_testing()
##---------------------------------------------------------------------------##
# SWIG setup
##---------------------------------------------------------------------------##
option(USE_SWIG "Enable SWIG generation" ON)
if (USE_SWIG)
find_package(SWIG)
endif()
if (USE_SWIG AND SWIG_FOUND)
# SWIG is requested and available; make sure it's the Fortran fork.
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(CheckSWIGFortran)
if (CMAKE_VERSION VERSION_LESS 3.20)
# TODO: This is until Fortran support gets added to the upstream cmake script
include(UseSWIGFortran)
else()
cmake_policy(SET CMP0078 "NEW")
cmake_policy(SET CMP0086 "NEW")
include(UseSWIG)
endif()
else()
set(USE_SWIG FALSE)
endif()
##---------------------------------------------------------------------------##
# LIBRARY
##---------------------------------------------------------------------------##
set(GENERATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/generated)
function(swig_fortran_add_library name)
# We're using C++
set_property(SOURCE src/${name}.i PROPERTY CPLUSPLUS ON)
# We need to include the source directory
set_property(SOURCE src/${name}.i
PROPERTY USE_TARGET_INCLUDE_DIRECTORIES ON)
if (USE_SWIG)
# SWIG is available; actually generate the library dynamically.
# Create the library
swig_add_library(${name}
LANGUAGE Fortran
TYPE USE_BUILD_SHARED_LIBS
OUTPUT_DIR "${GENERATE_DIR}"
SOURCES src/${name}.i ${ARGN})
else()
# SWIG is *not* being used: compile the code committed in the repository,
# generated by the developer with SWIG.
add_library(${name}
"${GENERATE_DIR}/${name}.f90"
"${GENERATE_DIR}/${name}FORTRAN_wrap.cxx"
${ARGN})
endif()
# Enable C++11
target_compile_features(${name} PRIVATE cxx_std_11)
# Use correct include directories for C++
target_include_directories(${name}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)
# Use correct Fortran module directories
target_include_directories(${name}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:modules>
)
endfunction()
# Four SWIG libraries
swig_fortran_add_library(utils)
swig_fortran_add_library(algorithm)
swig_fortran_add_library(formatrix src/matrix.cc)
swig_fortran_add_library(rng)
# One pure fortran library
add_library(futils
src/brainerd.f90
src/qsort.f90
src/timerlib.f90)
##---------------------------------------------------------------------------##
# TESTING
##---------------------------------------------------------------------------##
add_subdirectory(test)
##---------------------------------------------------------------------------##
# EXECUTABLES
##---------------------------------------------------------------------------##
add_subdirectory(example)
##---------------------------------------------------------------------------##
## end of algorithm/CMakeLists.txt
##---------------------------------------------------------------------------##