diff --git a/cmake/crosscompile.cmake b/cmake/crosscompile.cmake index aaa89b53..b3a29277 100644 --- a/cmake/crosscompile.cmake +++ b/cmake/crosscompile.cmake @@ -1,20 +1,24 @@ function(add_darwin_executable name) - cmake_parse_arguments(SL "NO_STANDARD_LIBRARIES" "MACOSX_VERSION_MIN" "" ${ARGN}) + cmake_parse_arguments(SL "NO_STANDARD_LIBRARIES;USE_HOST_SDK" "MACOSX_VERSION_MIN" "" ${ARGN}) add_executable(${name}) add_dependencies(${name} darwin_ld) target_compile_definitions(${name} PRIVATE __PUREDARWIN__) target_link_options(${name} PRIVATE -fuse-ld=$) - target_compile_options(${name} PRIVATE -target x86_64-apple-macos${CMAKE_MACOSX_MIN_VERSION}) - target_compile_options(${name} PRIVATE -nostdlib -nostdinc) - target_link_options(${name} PRIVATE -nostdlib) + + if(NOT SL_USE_HOST_SDK) + target_compile_options(${name} PRIVATE -nostdlib -nostdinc) + target_link_options(${name} PRIVATE -nostdlib) + endif() # TODO: Handle SL_NO_STANDARD_LIBRARIES here, once the libraries have been added to the build. if(SL_MACOSX_VERSION_MIN) + target_compile_options(${name} PRIVATE -target x86_64-apple-macos${SL_MACOSX_VERSION_MIN}) target_compile_options(${name} PRIVATE -mmacosx-version-min=${SL_MACOSX_VERSION_MIN}) target_link_options(${name} PRIVATE -mmacosx-version-min=${SL_MACOSX_VERSION_MIN}) elseif(CMAKE_MACOSX_MIN_VERSION) + target_compile_options(${name} PRIVATE -target x86_64-apple-macos${CMAKE_MACOSX_MIN_VERSION}) target_compile_options(${name} PRIVATE -mmacosx-version-min=${CMAKE_MACOSX_MIN_VERSION}) target_link_options(${name} PRIVATE -mmacosx-version-min=${CMAKE_MACOSX_MIN_VERSION}) else() @@ -23,6 +27,8 @@ function(add_darwin_executable name) endfunction() function(add_darwin_static_library name) + cmake_parse_arguments(SL "USE_HOST_SDK" "MACOSX_VERSION_MIN" "" ${ARGN}) + add_library(${name} STATIC) add_dependencies(${name} darwin_libtool) target_compile_definitions(${name} PRIVATE __PUREDARWIN__) @@ -32,12 +38,21 @@ function(add_darwin_static_library name) set_property(TARGET ${name} PROPERTY PREFIX "") endif() - target_compile_options(${name} PRIVATE -target x86_64-apple-macos${CMAKE_MACOSX_MIN_VERSION}) - target_compile_options(${name} PRIVATE -nostdlib -nostdinc) + if(SL_MACOSX_VERSION_MIN) + target_compile_options(${name} PRIVATE -target x86_64-apple-macos${SL_MACOSX_VERSION_MIN}) + elseif(CMAKE_MACOSX_MIN_VERSION) + target_compile_options(${name} PRIVATE -target x86_64-apple-macos${CMAKE_MACOSX_MIN_VERSION}) + else() + message(AUTHOR_WARNING "Could not determine -mmacosx-version-min flag for target ${name}") + endif() + + if(NOT SL_USE_HOST_SDK) + target_compile_options(${name} PRIVATE -nostdlib -nostdinc) + endif() endfunction() function(add_darwin_shared_library name) - cmake_parse_arguments(SL "MODULE" "MACOSX_VERSION_MIN;INSTALL_NAME_DIR" "RPATHS" ${ARGN}) + cmake_parse_arguments(SL "MODULE;USE_HOST_SDK" "MACOSX_VERSION_MIN;INSTALL_NAME_DIR" "RPATHS" ${ARGN}) if(SL_MODULE) add_library(${name} MODULE) @@ -54,14 +69,17 @@ function(add_darwin_shared_library name) set_property(TARGET ${name} PROPERTY PREFIX "") endif() - target_compile_options(${name} PRIVATE -target x86_64-apple-darwin20) - target_compile_options(${name} PRIVATE -nostdlib -nostdinc) - target_link_options(${name} PRIVATE -nostdlib) + if(NOT SL_USE_HOST_SDK) + target_compile_options(${name} PRIVATE -nostdlib -nostdinc) + target_link_options(${name} PRIVATE -nostdlib) + endif() if(SL_MACOSX_VERSION_MIN) + target_compile_options(${name} PRIVATE -target x86_64-apple-macos${SL_MACOSX_VERSION_MIN}) target_compile_options(${name} PRIVATE -mmacosx-version-min=${SL_MACOSX_VERSION_MIN}) target_link_options(${name} PRIVATE -mmacosx-version-min=${SL_MACOSX_VERSION_MIN}) elseif(CMAKE_MACOSX_MIN_VERSION) + target_compile_options(${name} PRIVATE -target x86_64-apple-macos${CMAKE_MACOSX_MIN_VERSION}) target_compile_options(${name} PRIVATE -mmacosx-version-min=${CMAKE_MACOSX_MIN_VERSION}) target_link_options(${name} PRIVATE -mmacosx-version-min=${CMAKE_MACOSX_MIN_VERSION}) else() @@ -82,11 +100,27 @@ function(add_darwin_shared_library name) endfunction() function(add_darwin_object_library name) + cmake_parse_arguments(SL "USE_HOST_SDK" "MACOSX_VERSION_MIN" "" ${ARGN}) + add_library(${name} OBJECT) set_property(TARGET ${name} PROPERTY LINKER_LANGUAGE C) target_compile_definitions(${name} PRIVATE __PUREDARWIN__) - target_compile_options(${name} PRIVATE -target x86_64-apple-darwin20) - target_compile_options(${name} PRIVATE -nostdlib -nostdinc) + + if(SL_MACOSX_VERSION_MIN) + target_compile_options(${name} PRIVATE -target x86_64-apple-macos${SL_MACOSX_VERSION_MIN}) + target_compile_options(${name} PRIVATE -mmacosx-version-min=${SL_MACOSX_VERSION_MIN}) + target_link_options(${name} PRIVATE -mmacosx-version-min=${SL_MACOSX_VERSION_MIN}) + elseif(CMAKE_MACOSX_MIN_VERSION) + target_compile_options(${name} PRIVATE -target x86_64-apple-macos${CMAKE_MACOSX_MIN_VERSION}) + target_compile_options(${name} PRIVATE -mmacosx-version-min=${CMAKE_MACOSX_MIN_VERSION}) + target_link_options(${name} PRIVATE -mmacosx-version-min=${CMAKE_MACOSX_MIN_VERSION}) + else() + message(AUTHOR_WARNING "Could not determine -mmacosx-version-min flag for target ${name}") + endif() + + if(NOT SL_USE_HOST_SDK) + target_compile_options(${name} PRIVATE -nostdlib -nostdinc) + endif() endfunction() set(CMAKE_SKIP_RPATH TRUE)