-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreason.add_interface_library.cmake
56 lines (51 loc) · 2.46 KB
/
reason.add_interface_library.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
function(reason__add_interface_library__tsources TARGET_NAME INC_DIRS HDR_SRCS)
reason_verbose(" target_sources:")
# add target_sources
if(NOT "${HDR_SRCS}" STREQUAL "")
target_sources("${TARGET_NAME}" INTERFACE "$<BUILD_INTERFACE:${HDR_SRCS}")
foreach(HDR IN LISTS HDR_SRCS)
reason_verbose(" [interface-source=${HDR}]")
endforeach()
else()
foreach(INC_DIR IN LISTS INC_DIRS)
file(GLOB_RECURSE HDRS "${INC_DIR}/*")
target_sources("${TARGET_NAME}" INTERFACE "$<BUILD_INTERFACE:${HDRS}>")
foreach(HDR IN LISTS HDRS)
reason_verbose(" [interface-source=${HDR}]")
endforeach()
endforeach()
endif()
endfunction()
function(reason__add_interface_library__tinclude_dirs TARGET_NAME INC_DIRS)
reason_verbose(" target_include_directories:")
# Handle include directories
foreach(INC_DIR IN LISTS INC_DIRS)
set(build_interface "${CMAKE_CURRENT_LIST_DIR}/${INC_DIR}")
target_include_directories("${TARGET_NAME}" INTERFACE "$<BUILD_INTERFACE:${build_interface}>")
reason_verbose(" [interface-include=${build_interface}]")
endforeach()
target_include_directories("${TARGET_NAME}" INTERFACE "$<INSTALL_INTERFACE:include>")
reason_verbose(" [interface-include=\"$<INSTALL_INTERFACE:include>\"]")
endfunction()
function(reason__add_interface_library__compile_define TARGET_NAME DEFINES)
target_compile_definitions("${TARGET_NAME}" INTERFACE "${DEFINES}")
foreach(DEFINE IN LISTS DEFINES)
reason_verbose(" target_compile_definitions: [interface-define=${DEFINE}]")
endforeach()
endfunction()
function(reason_add_interface_library)
set(options HELP)
set(one_value_args TARGET)
set(mlt_value_args INC_DIRS HDR_SRCS DEFINES)
cmake_parse_arguments(reason "${options}" "${one_value_args}" "${mlt_value_args}" "${ARGN}")
if(reason_HELP)
reason_print_help_file("${REASON_MODULE_DIR}/reason.add_interface_library.help")
endif()
reason_set_check(reason_TARGET "reason_add_interface_library: TARGET is required")
reason_set_check(reason_INC_DIRS "reason_add_interface_library: INC_DIRS is required")
reason_verbose("interface-library: [target=${reason_TARGET}]")
add_library("${reason_TARGET}" INTERFACE)
reason__add_interface_library__tsources("${reason_TARGET}" "${reason_INC_DIRS}" "${reason_HDR_SRCS}")
reason__add_interface_library__tinclude_dirs("${reason_TARGET}" "${reason_INC_DIRS}")
reason__add_interface_library__compile_define("${reason_TARGET}" "${reason_DEFINES}")
endfunction()