File: CMakeLists.txt

package info (click to toggle)
gridtools 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 21,728 kB
  • sloc: cpp: 45,263; python: 9,383; javascript: 8,445; ansic: 2,564; sh: 509; f90: 370; makefile: 216
file content (38 lines) | stat: -rw-r--r-- 1,505 bytes parent folder | download | duplicates (3)
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
cmake_minimum_required(VERSION 3.14.5)
project(simple_example_with_fetch_content LANGUAGES CXX Fortran)

# 1) fetch cpp_bindgen from the repository
include(FetchContent)
FetchContent_Declare(
  cpp_bindgen
  # In your application remove SOURCE_DIR ...
  SOURCE_DIR       ${CMAKE_CURRENT_LIST_DIR}/../..
  # By the following 2 lines to fetch content directly from github
  # GIT_REPOSITORY https://github.com/GridTools/cpp_bindgen.git
  # GIT_TAG        master # consider replacing master by a tagged version
)
FetchContent_MakeAvailable(cpp_bindgen)

# 2) create a library with bindings. This will generate the files simple.h and simple.f90 which can be included within C and Fortran. In CMake you can use them by linking against `simple_c`or `simple_fortran`.
bindgen_add_library(simple SOURCES simple.cpp)

# 3) link the generated library to a fortran executable
add_executable(driver driver.f90)
target_link_libraries(driver simple_fortran)

# 4) optional: demonstrates installing the library with CMake
# installs general cpp_bindgen targets
install_cpp_bindgen_targets(
  EXPORT simple_fortran_targets
  Fortran_MODULE_DESTINATION include
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  )
# install your library (simple) and the generated bindings library (simple_fortran) as usual
install(
  TARGETS simple simple_fortran
  EXPORT simple_fortran_targets
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  )
install(EXPORT simple_fortran_targets DESTINATION cmake NAMESPACE SimpleFortran::)