-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathO2AddHeaderOnlyLibrary.cmake
More file actions
71 lines (59 loc) · 2.37 KB
/
O2AddHeaderOnlyLibrary.cmake
File metadata and controls
71 lines (59 loc) · 2.37 KB
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
# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
# All rights not expressly granted are reserved.
#
# This software is distributed under the terms of the GNU General Public
# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
#
# In applying this license CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.
include_guard()
# o2_add_header_only_library creates a header-only target.
#
# * INCLUDE_DIRECTORIES the relative path(s) to the headers of that library if
# not specified will be set as "include" simply (which should work just fine
# in most cases)
#
function(o2_add_header_only_library baseTargetName)
cmake_parse_arguments(PARSE_ARGV
1
A
""
"TARGETVARNAME"
"INCLUDE_DIRECTORIES;INTERFACE_LINK_LIBRARIES")
if(A_UNPARSED_ARGUMENTS)
message(
FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}")
endif()
o2_name_target(${baseTargetName} NAME target)
# define the target and its O2:: alias
add_library(${target} INTERFACE)
add_library(O2::${baseTargetName} ALIAS ${target})
# set the export name so that packages using O2 can reference the target as
# O2::${baseTargetName} as well (assuming the export is installed with
# namespace O2::)
set_property(TARGET ${target} PROPERTY EXPORT_NAME ${baseTargetName})
if(A_TARGETVARNAME)
set(${A_TARGETVARNAME} ${target} PARENT_SCOPE)
endif()
if(NOT A_INCLUDE_DIRECTORIES)
get_filename_component(dir include ABSOLUTE)
if(EXISTS ${dir})
set(A_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${dir}>)
else()
set(A_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
endif()
endif()
target_include_directories(
${target}
INTERFACE $<BUILD_INTERFACE:${A_INCLUDE_DIRECTORIES}>)
if(A_INTERFACE_LINK_LIBRARIES)
target_link_libraries(${target} INTERFACE ${A_INTERFACE_LINK_LIBRARIES})
endif()
install(DIRECTORY ${A_INCLUDE_DIRECTORIES}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS ${target}
EXPORT O2Targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endfunction()