1# 2# Copyright 2019, Data61 3# Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4# ABN 41 687 119 230. 5# 6# This software may be distributed and modified according to the terms of 7# the BSD 2-Clause license. Note that NO WARRANTY is provided. 8# See "LICENSE_BSD2.txt" for details. 9# 10# @TAG(DATA61_BSD) 11# 12 13set(MUSLLIBC_CURRENT_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE STRING "") 14mark_as_advanced(MUSLLIBC_CURRENT_DIR) 15 16macro(musllibc_set_environment_flags) 17 include(environment_flags) 18 add_default_compilation_options() 19 20 find_libgcc_files() 21 22 set(CRTObjFiles "${CMAKE_BINARY_DIR}/lib/crt0.o ${CMAKE_BINARY_DIR}/lib/crti.o ${CRTBeginFile}") 23 set(FinObjFiles "${CRTEndFile} ${CMAKE_BINARY_DIR}/lib/crtn.o") 24 25 # libgcc has dependencies implemented by libc and so we use link groups to resolve these. 26 # This seems to be the same behaviour gcc has when building static binaries. 27 set(common_link_string "<LINK_FLAGS> ${CRTObjFiles} <OBJECTS> -Wl,--start-group \ 28 ${libgcc} <LINK_LIBRARIES> -Wl,--end-group ${FinObjFiles} -o <TARGET>") 29 set( 30 CMAKE_C_LINK_EXECUTABLE 31 "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> ${common_link_string}" 32 ) 33 set( 34 CMAKE_CXX_LINK_EXECUTABLE 35 "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> ${common_link_string}" 36 ) 37 set( 38 CMAKE_ASM_LINK_EXECUTABLE 39 "<CMAKE_ASM_COMPILER> <FLAGS> <CMAKE_ASM_LINK_FLAGS> ${common_link_string}" 40 ) 41 42 # We want to check what we can set the -mfloat-abi to on arm and if that matches what is requested 43 add_fpu_compilation_options() 44 # Now all platform compilation flags have been set, we can check the compiler against flags 45 include(check_arch_compiler) 46 check_arch_compiler() 47 48endmacro() 49 50macro(musllibc_import_library) 51 add_subdirectory(${MUSLLIBC_CURRENT_DIR} musllibc) 52endmacro() 53 54macro(musllibc_setup_build_environment_with_sel4runtime) 55 find_package(sel4runtime REQUIRED) 56 musllibc_set_environment_flags() 57 sel4runtime_import_project() 58 musllibc_import_library() 59endmacro() 60 61include(FindPackageHandleStandardArgs) 62FIND_PACKAGE_HANDLE_STANDARD_ARGS(musllibc DEFAULT_MSG MUSLLIBC_CURRENT_DIR) 63