-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
165 lines (147 loc) · 3.55 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
# This file is part of gfn0.
# SPDX-Identifier: LGPL-3.0-or-later
#
# gfn0 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.
#
# gfn0 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
cmake_minimum_required(VERSION 3.14)
project(
"gfn0"
LANGUAGES "Fortran" "C"
VERSION "0.1"
)
# Follow GNU conventions for installing directories
include(GNUInstallDirs)
# General configuration information
set(libs)
add_subdirectory("config")
#
# Libraries
#
# OpenMP dependency
if(NOT TARGET OpenMP::OpenMP_Fortran AND WITH_OpenMP)
find_package(OpenMP REQUIRED)
list(
APPEND libs
OpenMP::OpenMP_Fortran
)
endif()
# BLAS and LAPACK
if(NOT TARGET BLAS::BLAS)
find_package(BLAS REQUIRED)
if(NOT TARGET BLAS::BLAS AND BLAS_FOUND)
add_library(BLAS::BLAS INTERFACE IMPORTED)
target_link_libraries(BLAS::BLAS INTERFACE "${BLAS_LIBRARIES}")
target_link_options(BLAS::BLAS INTERFACE "${BLAS_LINKER_FLAGS}")
endif()
endif()
if(NOT TARGET LAPACK::LAPACK)
find_package(LAPACK REQUIRED)
if(NOT TARGET LAPACK::LAPACK AND LAPACK_FOUND)
add_library(LAPACK::LAPACK INTERFACE IMPORTED)
target_link_libraries(LAPACK::LAPACK INTERFACE "${LAPACK_LIBRARIES}")
target_link_options(LAPACK::LAPACK INTERFACE "${LAPACK_LINKER_FLAGS}")
endif()
endif()
list(
APPEND libs
LAPACK::LAPACK
BLAS::BLAS
)
#
# gfn0 sources
#
set(srcs)
add_subdirectory("src")
#
# Build the lib
#
add_library(
"${PROJECT_NAME}-lib"
"${srcs}"
)
set_target_properties(
"${PROJECT_NAME}-lib"
PROPERTIES
POSITION_INDEPENDENT_CODE TRUE
OUTPUT_NAME "${PROJECT_NAME}"
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
WINDOWS_EXPORT_ALL_SYMBOLS TRUE
Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include"
)
target_include_directories(
"${PROJECT_NAME}-lib"
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(
"${PROJECT_NAME}-lib"
PUBLIC
"${libs}"
)
IF(WITH_GBSA)
add_definitions(-DWITH_GBSA)
ENDIF()
#
# Executables
#
IF(BUILD_EXE)
set(srcs2)
add_subdirectory("testprog")
add_executable(
${PROJECT_NAME}-tester
"${srcs2}"
)
set_target_properties(
${PROJECT_NAME}-tester
PROPERTIES
Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
OUTPUT_NAME "${PROJECT_NAME}-tester"
)
target_link_libraries(
${PROJECT_NAME}-tester
PRIVATE
"${PROJECT_NAME}-lib"
)
ENDIF()
#
# Export targets for other projects
#
add_library("${PROJECT_NAME}" INTERFACE)
target_link_libraries("${PROJECT_NAME}" INTERFACE "${PROJECT_NAME}-lib")
install(
TARGETS
"${PROJECT_NAME}"
"${PROJECT_NAME}-lib"
EXPORT
"${PROJECT_NAME}-targets"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
install(
EXPORT
"${PROJECT_NAME}-targets"
NAMESPACE
"${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
install(
DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${module-dir}"
)