1add_custom_target(libc_loader_tests)
2
3# A rule to add loader tests. When we have a complete loader, we should
4# be able to use the add_libc_unittest rule or an extension of it. But,
5# while the loader is getting built, we need to use a special rule like
6# this.
7function(add_loader_test target_name)
8  if(NOT CMAKE_HOST_UNIX)
9    message(
10        WARNING
11        "Loader tests currently assume a POSIX/Unix like environment and "
12        "may not work on your platform.")
13  endif()
14
15  cmake_parse_arguments(
16    "ADD_LOADER_TEST"
17    ""    # No option arguments
18    "SRC" # Single value arguments
19    "DEPENDS;ARGS;ENV" # Multivalue arguments.
20    ${ARGN}
21  )
22
23  get_fq_target_name(${target_name} fq_target_name)
24  add_executable(
25    ${fq_target_name}
26    EXCLUDE_FROM_ALL
27    ${ADD_LOADER_TEST_SRC}
28  )
29
30  set_target_properties(${fq_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
31
32  target_include_directories(
33    ${fq_target_name}
34    PRIVATE
35      ${LIBC_SOURCE_DIR}
36      ${LIBC_BUILD_DIR}
37      ${LIBC_BUILD_DIR}/include
38  )
39
40  if(ADD_LOADER_TEST_DEPENDS)
41    get_fq_deps_list(fq_deps_list ${ADD_LOADER_TEST_DEPENDS})
42    add_dependencies(${fq_target_name} ${fq_deps_list})
43    get_object_files_for_test(link_object_files has_skipped_entrypoint_list ${fq_deps_list})
44    target_link_libraries(${fq_target_name} ${link_object_files})
45  endif()
46
47  target_link_options(
48    ${fq_target_name}
49    BEFORE PRIVATE
50    -nostdlib
51  )
52
53  add_custom_command(
54    TARGET ${fq_target_name}
55    POST_BUILD
56    COMMAND ${ADD_LOADER_TEST_ENV} $<TARGET_FILE:${fq_target_name}> ${ADD_LOADER_TEST_ARGS}
57  )
58
59  add_dependencies(libc_loader_tests ${fq_target_name})
60endfunction(add_loader_test)
61
62if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
63  add_subdirectory(${LIBC_TARGET_OS})
64endif()
65