-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
91 lines (72 loc) · 2.95 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
#---------------------------------------------------------------------------#
# \file CMakeLists.txt
#
# Copyright (c) 2019 Oak Ridge National Laboratory, UT-Battelle, LLC.
# Distributed under an MIT open source license: see LICENSE for details.
#---------------------------------------------------------------------------#
cmake_minimum_required(VERSION 3.9)
project(FlibcppExampleApp VERSION 0.1.0 LANGUAGES Fortran)
include(GNUInstallDirs)
#---------------------------------------------------------------------------#
# OPTIONS
#---------------------------------------------------------------------------#
# Build static libs by default
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
# Use a local copy of Flibcpp rather than an external installation
option(BUILTIN_FLIBCPP
"Download Git submodules during configuration"
ON)
# Set up rpaths
if (NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_PATH)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON CACHE STRING
"Inform installed binaries of external library rpaths")
endif()
if (BUILD_SHARED_LIBS)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}" CACHE STRING
"Inform installed binaries of internal library rpaths")
endif()
#---------------------------------------------------------------------------#
# EXTERNAL DEPENDENCIES
#---------------------------------------------------------------------------#
if (BUILTIN_FLIBCPP)
include(external/SubmoduleUtils.cmake)
load_submodule(external/flibcpp)
add_subdirectory(external/flibcpp)
if (NOT BUILD_SHARED_LIBS)
# The C++ runtime libraries are scoped to the subdirectory, and since we're
# not using shared libs, they will not be linked into the example app.
# Enable the CXX language in *this* scope to avoid link errors.
enable_language(CXX)
endif()
else()
find_package(Flibcpp REQUIRED CONFIG)
endif()
#---------------------------------------------------------------------------#
# LIBRARY
#---------------------------------------------------------------------------#
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/module)
add_library(example_backend
"src/example_backend.f90")
# Use correct Fortran module directories
target_include_directories(example_backend
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_Fortran_MODULE_DIRECTORY}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)
# Link against Flibcpp libraries
target_link_libraries(example_backend Flibcpp::flc_random Flibcpp::flc_algorithm)
# Install
install(TARGETS example_backend
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
#---------------------------------------------------------------------------#
# APP
#---------------------------------------------------------------------------#
add_executable(example app/example.f90)
target_link_libraries(example example_backend)
install(TARGETS example
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)