-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper.cmake
75 lines (69 loc) · 2.19 KB
/
helper.cmake
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
# helper.cmake
#
# A collection of macros and functions making life with CMake and Fortran a
# bit simpler.
# Use to include and export headers
function(include_headers lib dir install_dir)
target_include_directories(
${lib}
INTERFACE
$<BUILD_INTERFACE:${dir}>
$<INSTALL_INTERFACE:${install_dir}>
)
endfunction()
# Use instead of add_library.
function(add_fortran_library lib_name mod_dir include_install_dir version major)
add_library(${lib_name} ${ARGN})
set_target_properties(
${lib_name}
PROPERTIES
POSITION_INDEPENDENT_CODE TRUE
OUTPUT_NAME ${lib_name}
VERSION ${version}
SOVERSION ${major}
Fortran_MODULE_DIRECTORY ${include_install_dir}
)
target_include_directories(
${lib_name}
PUBLIC
$<BUILD_INTERFACE:${mod_dir}>
$<INSTALL_INTERFACE:${include_install_dir}>
)
endfunction()
# Installs the library
function(install_library lib_name lib_install_dir bin_install_dir mod_dir install_dir)
install(
TARGETS ${lib_name}
EXPORT ${lib_name}Targets
RUNTIME DESTINATION ${bin_install_dir}
LIBRARY DESTINATION ${lib_install_dir}
ARCHIVE DESTINATION ${lib_install_dir}
INCLUDES DESTINATION ${install_dir}/include
)
install(
DIRECTORY ${mod_dir}
DESTINATION ${install_dir}
)
endfunction()
# Install the documentation files
function(install_documentation doc_dir install_dir)
install(
DIRECTORY ${doc_dir}
DESTINATION ${install_dir}
)
endfunction()
# Links the supplied library
function(link_library targ lib include_dir)
target_link_libraries(${targ} PRIVATE ${lib})
target_include_directories(${targ} PUBLIC $<BUILD_INTERFACE:${include_dir}>)
endfunction()
# ------------------------------------------------------------------------------
# Helpful Macros
macro(print_all_variables)
message(STATUS "---------- CURRENTLY DEFINED VARIABLES -----------")
get_cmake_property(varNames VARIABLES)
foreach(varName ${varNames})
message(STATUS ${varName} = ${${varName}})
endforeach()
message(STATUS "---------- END ----------")
endmacro()