1
+ # helper.cmake
2
+ #
3
+ # A collection of macros and functions making life with CMake and Fortran a
4
+ # bit simpler.
5
+
6
+ # Use to include and export headers
7
+ function (include_headers lib dir install_dir)
8
+ target_include_directories (
9
+ ${lib}
10
+ INTERFACE
11
+ $<BUILD_INTERFACE:${dir} >
12
+ $<INSTALL_INTERFACE:${install_dir} >
13
+ )
14
+ endfunction ()
15
+
16
+ # Use instead of add_library.
17
+ function (add_fortran_library lib_name mod_dir include_install_dir version major)
18
+ add_library (${lib_name} ${ARGN} )
19
+ set_target_properties (
20
+ ${lib_name}
21
+ PROPERTIES
22
+ POSITION_INDEPENDENT_CODE TRUE
23
+ OUTPUT_NAME ${lib_name}
24
+ VERSION ${version}
25
+ SOVERSION ${major}
26
+ Fortran_MODULE_DIRECTORY ${include_install_dir}
27
+ )
28
+ target_include_directories (
29
+ ${lib_name}
30
+ PUBLIC
31
+ $<BUILD_INTERFACE:${mod_dir} >
32
+ $<INSTALL_INTERFACE:${include_install_dir} >
33
+ )
34
+ endfunction ()
35
+
36
+ # Installs the library
37
+ function (install_library lib_name lib_install_dir bin_install_dir mod_dir install_dir)
38
+ install (
39
+ TARGETS ${lib_name}
40
+ EXPORT ${lib_name} Targets
41
+ RUNTIME DESTINATION ${bin_install_dir}
42
+ LIBRARY DESTINATION ${lib_install_dir}
43
+ ARCHIVE DESTINATION ${lib_install_dir}
44
+ INCLUDES DESTINATION ${install_dir} /include
45
+ )
46
+ install (
47
+ DIRECTORY ${mod_dir}
48
+ DESTINATION ${install_dir}
49
+ )
50
+ endfunction ()
51
+
52
+ # Install the documentation files
53
+ function (install_documentation doc_dir install_dir)
54
+ install (
55
+ DIRECTORY ${doc_dir}
56
+ DESTINATION ${install_dir}
57
+ )
58
+ endfunction ()
59
+
60
+ # Links the supplied library
61
+ function (link_library targ lib include_dir)
62
+ target_link_libraries (${targ} ${lib} )
63
+ target_include_directories (${targ} PUBLIC $<BUILD_INTERFACE:${include_dir} >)
64
+ endfunction ()
65
+
66
+ # ------------------------------------------------------------------------------
67
+ # Helpful Macros
68
+ macro (print_all_variables)
69
+ message (STATUS "---------- CURRENTLY DEFINED VARIABLES -----------" )
70
+ get_cmake_property (varNames VARIABLES )
71
+ foreach (varName ${varNames} )
72
+ message (STATUS ${varName} = ${${varName} })
73
+ endforeach ()
74
+ message (STATUS "---------- END ----------" )
75
+ endmacro ()
0 commit comments