-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.cmake
84 lines (75 loc) · 2.96 KB
/
Utils.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
76
77
78
79
80
81
82
83
84
#
# This file is licensed under the 3-clause BSD license.
# Copyright Department of Chemistry and Applied Biosciences, Reiher Group.
# See LICENSE.txt for details.
#
function(scine_install_component_cmake_files)
set(options "")
set(oneValueArgs COMPONENT EXPORT_NAME CONFIG_FILE)
set(multiValueArgs "")
cmake_parse_arguments(SCINE_INSTALL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
include(CMakePackageConfigHelpers)
# -- Config version file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${SCINE_INSTALL_COMPONENT}/${SCINE_INSTALL_COMPONENT}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
set(SCINE_COMPONENT ${PROJECT_NAME})
set(SCINE_COMPONENT_VERSION ${PROJECT_VERSION})
# -- Config file
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${SCINE_INSTALL_COMPONENT}/${SCINE_INSTALL_COMPONENT}Config.cmake"
INSTALL_DESTINATION "${SCINE_CMAKE_PACKAGE_ROOT}/${SCINE_INSTALL_COMPONENT}"
PATH_VARS SCINE_CMAKE_PACKAGE_ROOT
)
# Install config and configVersion
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${SCINE_INSTALL_COMPONENT}/${SCINE_INSTALL_COMPONENT}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${SCINE_INSTALL_COMPONENT}/${SCINE_INSTALL_COMPONENT}ConfigVersion.cmake"
DESTINATION "${SCINE_CMAKE_PACKAGE_ROOT}/${SCINE_INSTALL_COMPONENT}"
COMPONENT ${SCINE_INSTALL_COMPONENT}
)
# -- Targets file
# This makes the project importable from the build directory
export(
EXPORT ${SCINE_INSTALL_EXPORT_NAME}
FILE "${CMAKE_CURRENT_BINARY_DIR}/${SCINE_INSTALL_COMPONENT}/${SCINE_INSTALL_COMPONENT}Targets.cmake"
NAMESPACE Scine::
)
# This makes the project importable from the install directory
# Put config file in per-project dir (name MUST match), can also
# just go into <prefix>/cmake.
install(
EXPORT ${SCINE_INSTALL_EXPORT_NAME}
FILE "${SCINE_INSTALL_COMPONENT}Targets.cmake"
DESTINATION "${SCINE_CMAKE_PACKAGE_ROOT}/${SCINE_INSTALL_COMPONENT}"
NAMESPACE Scine::
COMPONENT ${SCINE_INSTALL_COMPONENT}
)
endfunction()
function(workaround_link_object_library_target targetName)
set(options "")
set(oneValueArgs "")
set(multiValueArgs PUBLIC PRIVATE)
cmake_parse_arguments(WORKAROUND_LINK "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
target_link_libraries(targetName
PUBLIC ${WORKAROUND_LINK_PUBLIC}
PRIVATE ${WORKAROUND_LINK_PRIVATE}
)
else()
foreach(publicTarget ${WORKAROUND_LINK_PUBLIC})
target_include_directories(targetName
PUBLIC $<TARGET_PROPERTY:${publicTarget},INTERFACE_INCLUDE_DIRECTORIES>
)
endforeach()
foreach(privateTarget ${WORKAROUND_LINK_PRIVATE})
target_include_directories(targetName
PRIVATE $<TARGET_PROPERTY:${privateTarget},INTERFACE_INCLUDE_DIRECTORIES>
)
endforeach()
endif()
endfunction()