1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2# file Copyright.txt or https://cmake.org/licensing for details. 3 4if(UNIX) 5 set(CMAKE_Swift_OUTPUT_EXTENSION .o) 6else() 7 set(CMAKE_Swift_OUTPUT_EXTENSION .obj) 8endif() 9 10# Load compiler-specific information. 11if(CMAKE_Swift_COMPILER_ID) 12 include(Compiler/${CMAKE_Swift_COMPILER_ID}-Swift OPTIONAL) 13 14 if(CMAKE_SYSTEM_PROCESSOR) 15 include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_Swift_COMPILER_ID}-Swift-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL) 16 endif() 17 include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_Swift_COMPILER_ID}-Swift OPTIONAL) 18endif() 19 20set(CMAKE_EXE_EXPORTS_Swift_FLAG "-emit-module -emit-module-path <SWIFT_MODULE> ${CMAKE_Swift_IMPLIB_LINKER_FLAGS}") 21 22set(CMAKE_INCLUDE_FLAG_Swift "-I ") 23if(CMAKE_SYSTEM_NAME STREQUAL Darwin) 24 set(CMAKE_SHARED_LIBRARY_SONAME_Swift_FLAG "-Xlinker -install_name -Xlinker ") 25elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) 26 set(CMAKE_SHARED_LIBRARY_SONAME_Swift_FLAG "-Xlinker -soname -Xlinker ") 27endif() 28 29if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) 30 set(CMAKE_EXECUTABLE_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ") 31 set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ") 32 if(CMAKE_SYSTEM_NAME STREQUAL Darwin) 33 set(CMAKE_EXECUTABLE_RUNTIME_Swift_FLAG_SEP "") 34 set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG_SEP "") 35 else() 36 set(CMAKE_EXECUTABLE_RUNTIME_Swift_FLAG_SEP ":") 37 set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG_SEP ":") 38 endif() 39endif() 40 41set(CMAKE_Swift_COMPILE_OPTIONS_TARGET "-target ") 42set(CMAKE_Swift_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "-tools-directory ") 43# NOTE(compnerd) the `-sdk` support is not yet ready in the compiler; when that 44# is fully working, we should be able to enable this. 45# set(CMAKE_Swift_COMPILE_OPTIONS_SYSROOT "-sdk ") 46# NOTE(compnerd) do not setup `-frontend` as we use the compiler as the driver 47# during the link phase and use that to drive the compilation 48set(CMAKE_Swift_COMPILER_ARG1 "") 49set(CMAKE_Swift_DEFINE_FLAG -D) 50set(CMAKE_Swift_FRAMEWORK_SEARCH_FLAG "-F ") 51set(CMAKE_Swift_LIBRARY_PATH_FLAG "-L ") 52set(CMAKE_Swift_LIBRARY_PATH_TERMINATOR "") 53set(CMAKE_Swift_LINK_LIBRARY_FLAG "-l") 54set(CMAKE_Swift_LINKER_WRAPPER_FLAG "-Xlinker" " ") 55set(CMAKE_Swift_RESPONSE_FILE_LINK_FLAG @) 56 57set(CMAKE_Swift_LINKER_PREFERENCE 50) 58set(CMAKE_Swift_LINKER_PREFERENCE_PROPAGATES 1) 59 60# NOTE(compnerd) use the short form for convenience and ease of search. They 61# are treated equivalent to their long form names as well as custom Swift 62# specific names. 63set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded -libc MT) 64set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL -libc MD) 65set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug -libc MTd) 66set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -libc MDd) 67 68set(CMAKE_Swift_FLAGS_DEBUG_INIT "-g") 69set(CMAKE_Swift_FLAGS_RELEASE_INIT "-O") 70set(CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT "-O -g") 71set(CMAKE_Swift_FLAGS_MINSIZEREL_INIT "-Osize") 72 73if(CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF") 74 if(NOT DEFINED CMAKE_Swift_LINK_WHAT_YOU_USE_FLAG) 75 set(CMAKE_Swift_LINK_WHAT_YOU_USE_FLAG "LINKER:--no-as-needed") 76 endif() 77 if(NOT DEFINED CMAKE_LINK_WHAT_YOU_USE_CHECK) 78 set(CMAKE_LINK_WHAT_YOU_USE_CHECK ldd -u -r) 79 endif() 80endif() 81 82cmake_initialize_per_config_variable(CMAKE_Swift_FLAGS "Swift Compiler Flags") 83 84# NOTE(compnerd) we do not have an object compile rule since we build the objects as part of the link step 85if(NOT CMAKE_Swift_COMPILE_OBJECT) 86 set(CMAKE_Swift_COMPILE_OBJECT ":") 87endif() 88 89if(NOT CMAKE_Swift_NUM_THREADS MATCHES "^[0-9]+$") 90 cmake_host_system_information(RESULT CMAKE_Swift_NUM_THREADS QUERY NUMBER_OF_LOGICAL_CORES) 91endif() 92 93if(NOT CMAKE_Swift_CREATE_SHARED_LIBRARY) 94 set(CMAKE_Swift_CREATE_SHARED_LIBRARY "<CMAKE_Swift_COMPILER> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -j ${CMAKE_Swift_NUM_THREADS} -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> ${CMAKE_Swift_IMPLIB_LINKER_FLAGS} <LINK_LIBRARIES>") 95endif() 96 97if(NOT CMAKE_Swift_CREATE_SHARED_MODULE) 98 set(CMAKE_Swift_CREATE_SHARED_MODULE ${CMAKE_Swift_CREATE_SHARED_LIBRARY}) 99endif() 100 101if(NOT CMAKE_Swift_LINK_EXECUTABLE) 102 set(CMAKE_Swift_LINK_EXECUTABLE "<CMAKE_Swift_COMPILER> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -j ${CMAKE_Swift_NUM_THREADS} -emit-executable -o <TARGET> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") 103endif() 104 105if(NOT CMAKE_Swift_CREATE_STATIC_LIBRARY) 106 set(CMAKE_Swift_CREATE_STATIC_LIBRARY "<CMAKE_Swift_COMPILER> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -j ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") 107 108 set(CMAKE_Swift_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <OBJECTS>") 109 set(CMAKE_Swift_ARCHIVE_FINISH "") 110endif() 111 112set(CMAKE_Swift_INFORMATION_LOADED 1) 113