1+ # ========================
2+ # RTL Integration Helpers
3+ # ========================
4+
5+ # --------------------------------------------------
6+ # Attach generated registration sources to a target
7+ # --------------------------------------------------
8+ function (rtl_attach_registration TARGET REG_DIR )
9+
10+ # Validate registration directory exists
11+ if (NOT EXISTS "${REG_DIR} " )
12+ message (FATAL_ERROR
13+ "\n RTL ERROR: Registration directory not found:\n "
14+ " ${REG_DIR} \n "
15+ "Make sure clang-mirror generated files exist.\n "
16+ )
17+ endif ()
18+
19+ # Validate reg_src exists
20+ # clang-mirror generates the files in the same folder.
21+ # TODO: remove hard-coding.
22+ if (NOT EXISTS "${REG_DIR} /reg_src" )
23+ message (FATAL_ERROR
24+ "\n RTL ERROR: Registration source folder not found in:\n "
25+ " ${REG_DIR} \n "
26+ "Make sure clang-mirror generated registration sources.\n "
27+ )
28+ endif ()
29+
30+ # Collect generated sources
31+ file (GLOB RTL_REG_SRCS
32+ "${REG_DIR} /reg_src/*.cpp"
33+ )
34+
35+ if (NOT RTL_REG_SRCS)
36+ message (FATAL_ERROR
37+ "\n RTL ERROR: No registration source files found in:\n "
38+ " ${REG_DIR} \n "
39+ )
40+ endif ()
41+
42+ # Collect headers
43+ file (GLOB RTL_REG_HDRS
44+ "${REG_DIR} /*.h"
45+ )
46+
47+ # Attach to target
48+ target_sources (${TARGET} PRIVATE
49+ ${RTL_REG_SRCS}
50+ ${RTL_REG_HDRS}
51+ )
52+
53+ target_include_directories (${TARGET} PRIVATE
54+ "${REG_DIR} "
55+ )
56+
57+ set_source_files_properties (${RTL_REG_SRCS}
58+ PROPERTIES GENERATED TRUE
59+ )
60+
61+ source_group ("RTLRegistration" FILES
62+ ${RTL_REG_SRCS}
63+ ${RTL_REG_HDRS}
64+ )
65+
66+ message (STATUS
67+ "RTL: Registration attached from ${REG_DIR} "
68+ )
69+
70+ endfunction ()
71+
72+ # -------------------
73+ # Public entry point
74+ # -------------------
75+ function (rtl_enable TARGET )
76+
77+ if (NOT TARGET ${TARGET} )
78+ message (FATAL_ERROR
79+ "RTL ERROR: Target '${TARGET} ' does not exist"
80+ )
81+ endif ()
82+
83+ target_link_libraries (${TARGET}
84+ PRIVATE RTL::ReflectionTemplateLib
85+ )
86+
87+ get_target_property (TARGET_SOURCE_DIR ${TARGET} SOURCE_DIR )
88+
89+ if (NOT TARGET_SOURCE_DIR )
90+ message (FATAL_ERROR
91+ "RTL ERROR: Could not determine source directory for '${TARGET} '"
92+ )
93+ endif ()
94+
95+ # Define folder name locally, hard-coded for now.
96+ # clang-mirror generates the files in the same folder.
97+ # TODO: remove hard-coding.
98+ set (RTL_REGISTRATION_FOLDER "RTLRegistration" )
99+
100+ set (REG_DIR
101+ "${TARGET_SOURCE_DIR} /${RTL_REGISTRATION_FOLDER} "
102+ )
103+
104+ rtl_attach_registration (${TARGET} "${REG_DIR} " )
105+
106+ endfunction ()
0 commit comments