mirror of
https://github.com/PureDarwin/PureDarwin.git
synced 2026-01-25 04:06:25 +00:00
Add USE_HOST_SDK to add_darwin_*() CMake functions
By default, -nostdinc and -nostdlib are used. If USE_HOST_SDK is specified, CMake will *not* emit these two flags. The default Xcode SDK will then be consulted as well if a file cannot be found here. In the long term this should never be used, but for now it unblocks contributions to any part of PureDarwin without risking breaking the build.
This commit is contained in:
@@ -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_FILE:darwin_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)
|
||||
|
||||
Reference in New Issue
Block a user