63 lines · plain
1# A rule to add startup system tests. When we have a complete startup system,2# we should be able to use the add_libc_unittest rule or an extension of it.3# But, while the system is being developed, we need to use a special rule like4# this.5function(add_startup_test target_name)6 if(NOT CMAKE_HOST_UNIX)7 message(8 WARNING9 "Test for the startup system currently assume a POSIX/Unix like "10 "environment and may not work on your platform.")11 endif()12 13 cmake_parse_arguments(14 "ADD_STARTUP_TEST"15 "" # No option arguments16 "SRC" # Single value arguments17 "DEPENDS;ARGS;ENV" # Multivalue arguments.18 ${ARGN}19 )20 21 get_fq_target_name(${target_name} fq_target_name)22 add_executable(23 ${fq_target_name}24 EXCLUDE_FROM_ALL25 ${ADD_STARTUP_TEST_SRC}26 )27 28 set_target_properties(${fq_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})29 30 target_include_directories(31 ${fq_target_name}32 PRIVATE33 ${LIBC_SOURCE_DIR}34 ${LIBC_BUILD_DIR}35 ${LIBC_INCLUDE_DIR}36 )37 38 if(ADD_STARTUP_TEST_DEPENDS)39 get_fq_deps_list(fq_deps_list ${ADD_STARTUP_TEST_DEPENDS})40 add_dependencies(${fq_target_name} ${fq_deps_list})41 get_object_files_for_test(link_object_files has_skipped_entrypoint_list ${fq_deps_list})42 target_link_libraries(${fq_target_name} ${link_object_files})43 endif()44 45 target_link_options(46 ${fq_target_name}47 BEFORE PRIVATE48 -nostdlib49 )50 51 add_custom_command(52 TARGET ${fq_target_name}53 POST_BUILD54 COMMAND ${ADD_STARTUP_TEST_ENV} $<TARGET_FILE:${fq_target_name}> ${ADD_STARTUP_TEST_ARGS}55 )56 57 add_dependencies(libc_startup_tests ${fq_target_name})58endfunction(add_startup_test)59 60if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})61 add_subdirectory(${LIBC_TARGET_OS})62endif()63