Debian Codegraph @

src/CMakeLists.txt

raw
1 configure_file(mbd_version.f90.in "${CMAKE_CURRENT_BINARY_DIR}/mbd_version.f90")
2
3 add_library(mbd
4 mbd.F90
5 mbd_constants.f90
6 mbd_coulomb.f90
7 mbd_damping.F90
8 mbd_density.f90
9 mbd_defaults.f90
10 mbd_dipole.F90
11 mbd_formulas.f90
12 mbd_geom.F90
13 mbd_gradients.f90
14 mbd_hamiltonian.F90
15 mbd_lapack.f90
16 mbd_linalg.F90
17 mbd_matrix.F90
18 mbd_methods.F90
19 mbd_rpa.F90
20 mbd_scs.f90
21 mbd_ts.F90
22 mbd_utils.F90
23 "${CMAKE_CURRENT_BINARY_DIR}/mbd_version.f90"
24 mbd_vdw_param.f90
25 )
26
27 # Shared-library versioning. VERSION is informational and tracks the release
28 # version (the full versioned library file). SOVERSION is the compatibility
29 # version baked into the library identity (the SONAME on ELF, the
30 # compatibility version on macOS) and must track the C-ABI (mbd.h)
31 # compatibility only: bump MBD_SOVERSION by hand on every C-ABI break. It is
32 # deliberately decoupled from the release version, which is 0.x and derived
33 # from Git, so a major bump cannot be relied on to signal an ABI break. Note
34 # this guards C consumers only; the Fortran .mod ABI is compiler-specific and
35 # not covered by SOVERSION, so Fortran callers must rebuild against a matching
36 # libMBD build regardless.
37 set(MBD_SOVERSION 0)
38 set_target_properties(mbd PROPERTIES
39 VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
40 SOVERSION ${MBD_SOVERSION}
41 )
42
43 if(ENABLE_SCALAPACK_MPI)
44 target_sources(mbd PRIVATE mbd_mpi.F90 mbd_blacs.f90 mbd_scalapack.f90)
45 if(NOT MPI_Fortran_HAVE_F08_MODULE OR ENABLE_MPIFH)
46 if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "NAG")
47 set(mismatch_flag "-mismatch")
48 elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU"
49 AND "${CMAKE_Fortran_COMPILER_VERSION}" VERSION_GREATER_EQUAL "10")
50 set(mismatch_flag "-fallow-argument-mismatch -Wno-pedantic")
51 endif()
52 if(DEFINED mismatch_flag)
53 set_source_files_properties(
54 SOURCE mbd_geom.F90 mbd_methods.F90 mbd_mpi.F90 mbd_ts.F90
55 PROPERTY COMPILE_FLAGS ${mismatch_flag}
56 )
57 endif()
58 endif()
59 endif()
60
61 if(ENABLE_ELSI)
62 target_sources(mbd PRIVATE mbd_elsi.F90)
63 endif()
64
65 if(ENABLE_C_API)
66 target_sources(mbd PRIVATE mbd_c_api.F90)
67 endif()
68
69 set(moduledir "${CMAKE_CURRENT_BINARY_DIR}/modules")
70 set(includedir "${CMAKE_INSTALL_INCLUDEDIR}/mbd")
71 set(install_moduledir "${CMAKE_INSTALL_MODULEDIR}/mbd")
72 set_target_properties(mbd PROPERTIES Fortran_MODULE_DIRECTORY "${moduledir}")
73
74 target_include_directories(mbd
75 PRIVATE
76 ${moduledir}
77 INTERFACE
78 $<BUILD_INTERFACE:${moduledir}>
79 $<INSTALL_INTERFACE:${includedir}>
80 $<INSTALL_INTERFACE:${install_moduledir}>
81 )
82
83 if(ENABLE_SCALAPACK_MPI)
84 target_link_libraries(mbd PRIVATE MPI::MPI_Fortran scalapack)
85 set_property(TARGET mbd APPEND PROPERTY COMPILE_DEFINITIONS WITH_MPI WITH_SCALAPACK)
86 if(ENABLE_MPIFH)
87 set_property(TARGET mbd APPEND PROPERTY COMPILE_DEFINITIONS WITH_MPIFH)
88 elseif(MPI_Fortran_HAVE_F08_MODULE)
89 set_property(TARGET mbd APPEND PROPERTY COMPILE_DEFINITIONS WITH_MPIF08)
90 endif()
91 endif()
92
93 target_link_libraries(mbd PRIVATE LAPACK::LAPACK)
94
95 if(ENABLE_ELSI)
96 target_link_libraries(mbd PRIVATE elsi::elsi)
97 set_property(TARGET mbd APPEND PROPERTY COMPILE_DEFINITIONS WITH_ELSI)
98 endif()
99
100 if(ENABLE_C_API)
101 set_property(TARGET mbd PROPERTY PUBLIC_HEADER mbd.h)
102 endif()
103
104 add_library(Mbd INTERFACE)
105 target_link_libraries(Mbd INTERFACE mbd)
106 if(CMAKE_INSTALL_LIBDIR)
107 install(TARGETS mbd Mbd EXPORT MbdConfig
108 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
109 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
110 PUBLIC_HEADER DESTINATION "${includedir}"
111 )
112 install(DIRECTORY "${moduledir}/" DESTINATION "${install_moduledir}")
113 install(EXPORT MbdConfig NAMESPACE Mbd:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/mbd")
114 endif()