|
1 | 1 | set(OBJECT_LIBRARY_TARGET_TYPE "OBJECT_LIBRARY")
|
| 2 | +set(ENTRYPOINT_OBJ_TARGET_TYPE "ENTRYPOINT_OBJ") |
| 3 | +set(ENTRYPOINT_EXT_TARGET_TYPE "ENTRYPOINT_EXT") |
| 4 | + |
| 5 | +# Rule to check if a list of dependencies contains any entrypoint objects. Returns a list in entrypoint_deps. |
| 6 | +function(check_entrypoint_deps entrypoint_deps) |
| 7 | + set(PUBLIC_DEPS "") |
| 8 | + set(fq_deps_list "") |
| 9 | + list(APPEND fq_deps_list ${ARGN}) |
| 10 | + |
| 11 | + #don't warn for deps that are allowed, such as errno |
| 12 | + set(ALLOWED_DEPS |
| 13 | + "libc.src.errno.errno" |
| 14 | + "libc.src.setjmp.longjmp" |
| 15 | + ) |
| 16 | + list(REMOVE_ITEM fq_deps_list ${ALLOWED_DEPS}) |
| 17 | + |
| 18 | + foreach(dep IN LISTS fq_deps_list) |
| 19 | + if(NOT TARGET ${dep}) |
| 20 | + continue() |
| 21 | + endif() |
| 22 | + |
| 23 | + get_target_property(target_type ${dep} "TARGET_TYPE") |
| 24 | + if(${target_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE}) |
| 25 | + list(APPEND PUBLIC_DEPS ${dep}) |
| 26 | + endif() |
| 27 | + endforeach() |
| 28 | + set(${entrypoint_deps} ${PUBLIC_DEPS} PARENT_SCOPE) |
| 29 | +endfunction() |
| 30 | + |
2 | 31 |
|
3 | 32 | # Rule which is essentially a wrapper over add_library to compile a set of
|
4 | 33 | # sources to object files.
|
@@ -65,6 +94,18 @@ function(create_object_library fq_target_name)
|
65 | 94 | target_include_directories(${fq_target_name} PRIVATE ${LIBC_SOURCE_DIR})
|
66 | 95 | target_compile_options(${fq_target_name} PRIVATE ${compile_options})
|
67 | 96 |
|
| 97 | + #loop through the deps, check if any have the TARGET_TYPE of ENTRYPOINT_OBJ_TARGET_TYPE, and print a warning if they do. |
| 98 | + if(LIBC_CMAKE_VERBOSE_LOGGING) |
| 99 | + set(entrypoint_deps "") |
| 100 | + if(NOT "${fq_deps_list}" STREQUAL "") |
| 101 | + check_entrypoint_deps(entrypoint_deps ${fq_deps_list}) |
| 102 | + endif() |
| 103 | + if(NOT "${entrypoint_deps}" STREQUAL "") |
| 104 | + message(WARNING "Object ${fq_target_name} depends on public entrypoint(s) ${entrypoint_deps}. |
| 105 | + Depending on public entrypoints is not allowed in internal code.") |
| 106 | + endif() |
| 107 | + endif() |
| 108 | + |
68 | 109 | if(SHOW_INTERMEDIATE_OBJECTS)
|
69 | 110 | message(STATUS "Adding object library ${fq_target_name}")
|
70 | 111 | if(${SHOW_INTERMEDIATE_OBJECTS} STREQUAL "DEPS")
|
@@ -110,7 +151,6 @@ function(add_object_library target_name)
|
110 | 151 | ${ARGN})
|
111 | 152 | endfunction(add_object_library)
|
112 | 153 |
|
113 |
| -set(ENTRYPOINT_OBJ_TARGET_TYPE "ENTRYPOINT_OBJ") |
114 | 154 |
|
115 | 155 | # A rule for entrypoint object targets.
|
116 | 156 | # Usage:
|
@@ -179,7 +219,6 @@ function(create_entrypoint_object fq_target_name)
|
179 | 219 |
|
180 | 220 | get_target_property(obj_type ${fq_dep_name} "TARGET_TYPE")
|
181 | 221 | if((NOT obj_type) OR (NOT ${obj_type} STREQUAL ${ENTRYPOINT_OBJ_TARGET_TYPE}))
|
182 |
| - |
183 | 222 | message(FATAL_ERROR "The aliasee of an entrypoint alias should be an entrypoint.")
|
184 | 223 | endif()
|
185 | 224 |
|
@@ -230,6 +269,19 @@ function(create_entrypoint_object fq_target_name)
|
230 | 269 | _get_common_compile_options(common_compile_options "${ADD_ENTRYPOINT_OBJ_FLAGS}")
|
231 | 270 | list(APPEND common_compile_options ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS})
|
232 | 271 | get_fq_deps_list(fq_deps_list ${ADD_ENTRYPOINT_OBJ_DEPENDS})
|
| 272 | + |
| 273 | + #loop through the deps, check if any have the TARGET_TYPE of entrypoint_target_type, and print a warning if they do. |
| 274 | + if(LIBC_CMAKE_VERBOSE_LOGGING) |
| 275 | + set(entrypoint_deps "") |
| 276 | + if(NOT "${fq_deps_list}" STREQUAL "") |
| 277 | + check_entrypoint_deps(entrypoint_deps ${fq_deps_list}) |
| 278 | + endif() |
| 279 | + if(NOT "${entrypoint_deps}" STREQUAL "") |
| 280 | + message(WARNING "Entrypoint ${fq_target_name} depends on public entrypoint(s) ${entrypoint_deps}. |
| 281 | + Depending on public entrypoints is not allowed in internal code.") |
| 282 | + endif() |
| 283 | + endif() |
| 284 | + |
233 | 285 | set(full_deps_list ${fq_deps_list} libc.src.__support.common)
|
234 | 286 |
|
235 | 287 | if(SHOW_INTERMEDIATE_OBJECTS)
|
@@ -390,8 +442,6 @@ function(add_entrypoint_object target_name)
|
390 | 442 | )
|
391 | 443 | endfunction(add_entrypoint_object)
|
392 | 444 |
|
393 |
| -set(ENTRYPOINT_EXT_TARGET_TYPE "ENTRYPOINT_EXT") |
394 |
| - |
395 | 445 | # A rule for external entrypoint targets.
|
396 | 446 | # Usage:
|
397 | 447 | # add_entrypoint_external(
|
|
0 commit comments