diff --git a/CMakeLists.txt b/CMakeLists.txt index c5dbd1e671..63cec0f8ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,30 +1,41 @@ -cmake_minimum_required(VERSION 3.4.3) +cmake_minimum_required(VERSION 3.14.20190522) -list(APPEND CMAKE_MODULE_PATH - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") + +if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif() # NOTE(compnerd) enable CMP0091 - select MSVC runtime based on # CMAKE_MSVC_RUNTIME_LIBRARY. Requires CMake 3.15 or newer if(POLICY CMP0091) - cmake_policy(CMP0091 NEW) + cmake_policy(SET CMP0091 NEW) endif() -project(Foundation - LANGUAGES - C) -enable_testing() +project(Foundation LANGUAGES Swift C) # NOTE(compnerd) default to /MD or /MDd by default based on the configuration. # Cache the variable to allow the user to alter the configuration. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL" CACHE STRING "MSVC Runtime Library") +set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) + option(BUILD_SHARED_LIBS "build shared libraries" ON) +option(ENABLE_TESTING "enable testing" YES) +if(ENABLE_TESTING) + enable_testing() +endif() + option(FOUNDATION_ENABLE_LIBDISPATCH "Enable GCD Support" YES) + +# FIXME(compnerd) these can go away with export targts option(FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE "Path to libdispatch source" "") option(FOUNDATION_PATH_TO_LIBDISPATCH_BUILD "Path to libdispatch build" "") + +# FIXME(compnerd) this can go away with export targets option(FOUNDATION_PATH_TO_XCTEST_BUILD "Path to XCTest build" "") find_package(CURL REQUIRED) @@ -37,16 +48,19 @@ include(GNUInstallDirs) if(CMAKE_SYSTEM_NAME STREQUAL Linux) include(CheckSymbolExists) include(CheckIncludeFile) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) + check_include_file("sched.h" HAVE_SCHED_H) check_symbol_exists(sched_getaffinity "sched.h" HAVE_SCHED_GETAFFINITY) endif() -string(TOLOWER ${CMAKE_SYSTEM_NAME} swift_os) get_swift_host_arch(swift_arch) +# FIXME(compnerd) these two can go away with export targets set(CF_PATH_TO_LIBDISPATCH_SOURCE ${FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE} CACHE PATH "Path to libdispatch source" FORCE) set(CF_PATH_TO_LIBDISPATCH_BUILD ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD} CACHE PATH "Path to libdispatch build" FORCE) + set(CF_DEPLOYMENT_SWIFT YES CACHE BOOL "Build for Swift" FORCE) set(SAVED_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) @@ -54,47 +68,9 @@ set(BUILD_SHARED_LIBS NO) add_subdirectory(CoreFoundation) set(BUILD_SHARED_LIBS ${SAVED_BUILD_SHARED_LIBS}) -add_library(uuid - STATIC - uuid/uuid.h - uuid/uuid.c) -set_target_properties(uuid - PROPERTIES - POSITION_INDEPENDENT_CODE YES) -# Add an include directory for the CoreFoundation framework headers to satisfy -# the dependency on TargetConditionals.h -target_compile_options(uuid - PUBLIC - -I${CMAKE_CURRENT_BINARY_DIR}/CoreFoundation.framework/Headers) -if(CMAKE_SYSTEM_NAME STREQUAL Windows) - target_compile_definitions(uuid - PRIVATE - _CRT_NONSTDC_NO_WARNINGS - _CRT_SECURE_NO_DEPRECATE - _CRT_SECURE_NO_WARNINGS) - target_link_libraries(uuid PRIVATE Bcrypt) -endif() -add_dependencies(uuid CoreFoundation) - -set(swift_optimization_flags) -if(NOT CMAKE_BUILD_TYPE MATCHES Debug) - set(swift_optimization_flags -O) -endif() -if(ENABLE_TESTING) - set(swift_enable_testing -enable-testing) -endif() -if(CMAKE_SYSTEM_NAME STREQUAL Windows) - set(swift_libc_flags -libc;${CMAKE_MSVC_RUNTIME_LIBRARY}) - if(CMAKE_SYSTEM_NAME STREQUAL Debug) - list(APPEND swift_libc_flags -Xcc;-D_DEBUG) - endif() -endif() +add_subdirectory(uuid) -set(libdispatch_cflags) -set(libdispatch_ldflags) if(FOUNDATION_ENABLE_LIBDISPATCH) - set(libdispatch_cflags -I;${FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE};-I;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src/swift;-Xcc;-fblocks) - set(libdispatch_ldflags -L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD};-L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src;-ldispatch;-lswiftDispatch) if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD) list(APPEND libdispatch_ldflags -Xlinker;-rpath;-Xlinker;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src) endif() @@ -111,528 +87,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Windows) set(WORKAROUND_SR9138 -Xlinker;-ignore:4049;-Xlinker;-ignore:4217) endif() -# NOTE(compnerd) this is a horrible hack to work around the fact that we do not -# have a proper library target for Foundation which can link against the -# CoreFoundation target. When we gain proper CMake support for Swift, we should -# be able to remove this and just use -# `target_link_libraries(Foundation PRIVATE CoreFoundation)`. -set(CoreFoundation_LIBRARIES $) -set(CFURLSessionInterface_LIBRARIES $) -get_target_property(CoreFoundation_LINK_LIBRARIES CoreFoundation LINK_LIBRARIES) -foreach(library ${CoreFoundation_LINK_LIBRARIES}) - if(NOT library STREQUAL Threads::Threads) - list(APPEND CoreFoundation_LIBRARIES -l${library}) - list(APPEND CFURLSessionInterface_LIBRARIES -l${library}) - endif() -endforeach() - -add_swift_library(Foundation - MODULE_NAME - Foundation - MODULE_LINK_NAME - Foundation - MODULE_PATH - ${CMAKE_CURRENT_BINARY_DIR}/swift/Foundation.swiftmodule - SOURCES - Foundation/AffineTransform.swift - Foundation/Array.swift - Foundation/Boxing.swift - Foundation/Bridging.swift - Foundation/Bundle.swift - Foundation/ByteCountFormatter.swift - Foundation/Calendar.swift - Foundation/CGFloat.swift - Foundation/CharacterSet.swift - Foundation/Codable.swift - Foundation/Collections+DataProtocol.swift - Foundation/ContiguousBytes.swift - Foundation/Data.swift - Foundation/DataProtocol.swift - Foundation/Date.swift - Foundation/DateComponents.swift - Foundation/DateComponentsFormatter.swift - Foundation/DateFormatter.swift - Foundation/DateInterval.swift - Foundation/DateIntervalFormatter.swift - Foundation/Decimal.swift - Foundation/Dictionary.swift - Foundation/DispatchData+DataProtocol.swift - Foundation/EnergyFormatter.swift - Foundation/ExtraStringAPIs.swift - Foundation/FileHandle.swift - Foundation/FileManager.swift - Foundation/FileManager+POSIX.swift - Foundation/FileManager+Win32.swift - Foundation/FileManager_XDG.swift - Foundation/Formatter.swift - Foundation/FoundationErrors.swift - Foundation/Host.swift - Foundation/IndexPath.swift - Foundation/IndexSet.swift - Foundation/ISO8601DateFormatter.swift - Foundation/JSONEncoder.swift - Foundation/JSONSerialization.swift - Foundation/LengthFormatter.swift - Foundation/Locale.swift - Foundation/MassFormatter.swift - Foundation/Measurement.swift - Foundation/MeasurementFormatter.swift - Foundation/Notification.swift - Foundation/NotificationQueue.swift - Foundation/NSArray.swift - Foundation/NSAttributedString.swift - Foundation/NSCache.swift - Foundation/NSCalendar.swift - Foundation/NSCFArray.swift - Foundation/NSCFBoolean.swift - Foundation/NSCFCharacterSet.swift - Foundation/NSCFDictionary.swift - Foundation/NSCFSet.swift - Foundation/NSCFString.swift - Foundation/NSCharacterSet.swift - Foundation/NSCoder.swift - Foundation/NSComparisonPredicate.swift - Foundation/NSCompoundPredicate.swift - Foundation/NSConcreteValue.swift - Foundation/NSData+DataProtocol.swift - Foundation/NSData.swift - Foundation/NSDate.swift - Foundation/NSDecimalNumber.swift - Foundation/NSDictionary.swift - Foundation/NSEnumerator.swift - Foundation/NSError.swift - Foundation/NSExpression.swift - Foundation/NSGeometry.swift - Foundation/NSIndexPath.swift - Foundation/NSIndexSet.swift - Foundation/NSKeyedArchiver.swift - Foundation/NSKeyedArchiverHelpers.swift - Foundation/NSKeyedCoderOldStyleArray.swift - Foundation/NSKeyedUnarchiver.swift - Foundation/NSLocale.swift - Foundation/NSLock.swift - Foundation/NSLog.swift - Foundation/NSMeasurement.swift - Foundation/NSNotification.swift - Foundation/NSNull.swift - Foundation/NSNumber.swift - Foundation/NSObjCRuntime.swift - Foundation/NSObject.swift - Foundation/NSOrderedSet.swift - Foundation/NSPathUtilities.swift - Foundation/NSPersonNameComponents.swift - Foundation/NSPlatform.swift - Foundation/NSPredicate.swift - Foundation/NSRange.swift - Foundation/NSRegularExpression.swift - Foundation/NSSet.swift - Foundation/NSSortDescriptor.swift - Foundation/NSSpecialValue.swift - Foundation/NSString.swift - Foundation/NSStringAPI.swift - Foundation/NSSwiftRuntime.swift - Foundation/NSTextCheckingResult.swift - Foundation/NSTimeZone.swift - Foundation/NSURL.swift - Foundation/NSURLError.swift - Foundation/NSUUID.swift - Foundation/NSValue.swift - Foundation/NumberFormatter.swift - Foundation/Operation.swift - Foundation/PersonNameComponents.swift - Foundation/PersonNameComponentsFormatter.swift - Foundation/Pointers+DataProtocol.swift - Foundation/Port.swift - Foundation/PortMessage.swift - Foundation/Process.swift - Foundation/ProcessInfo.swift - Foundation/Progress.swift - Foundation/ProgressFraction.swift - Foundation/PropertyListEncoder.swift - Foundation/PropertyListSerialization.swift - Foundation/ReferenceConvertible.swift - Foundation/RunLoop.swift - Foundation/Scanner.swift - Foundation/ScannerAPI.swift - Foundation/Set.swift - Foundation/Stream.swift - Foundation/String.swift - Foundation/StringEncodings.swift - Foundation/Thread.swift - Foundation/Timer.swift - Foundation/TimeZone.swift - Foundation/Unit.swift - Foundation/URL.swift - Foundation/URLComponents.swift - Foundation/UserDefaults.swift - Foundation/UUID.swift - Foundation/XMLDocument.swift - Foundation/XMLDTD.swift - Foundation/XMLDTDNode.swift - Foundation/XMLElement.swift - Foundation/XMLNode.swift - Foundation/XMLParser.swift - TARGET - ${CMAKE_C_COMPILER_TARGET} - CFLAGS - -F${CMAKE_CURRENT_BINARY_DIR} - LINK_FLAGS - ${CoreFoundation_LIBRARIES} - ${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY} - ${LIBXML2_LIBRARIES} - ${libdispatch_ldflags} - $ - ${Foundation_RPATH} - ${WORKAROUND_SR9138} - $<$:-lDbgHelp> - $<$:-lOle32> - $<$:-lShLwApi> - $<$:-lShell32> - $<$:-lWS2_32> - $<$:-liphlpapi> - $<$:-lpathcch> - $<$:$> - SWIFT_FLAGS - -DDEPLOYMENT_RUNTIME_SWIFT - $<$:-DDEPLOYMENT_ENABLE_LIBDISPATCH> - -I;${ICU_INCLUDE_DIR} - ${libdispatch_cflags} - ${swift_enable_testing} - ${swift_optimization_flags} - ${swift_libc_flags} - DEPENDS - uuid - CoreFoundation - $<$:CoreFoundationResources>) - -add_swift_library(FoundationNetworking - MODULE_NAME - FoundationNetworking - MODULE_LINK_NAME - FoundationNetworking - MODULE_PATH - ${CMAKE_CURRENT_BINARY_DIR}/swift/FoundationNetworking.swiftmodule - SOURCES - Foundation/Boxing.swift - Foundation/NSURLRequest.swift - Foundation/HTTPCookie.swift - Foundation/HTTPCookieStorage.swift - Foundation/URLAuthenticationChallenge.swift - Foundation/URLCache.swift - Foundation/URLCredential.swift - Foundation/URLCredentialStorage.swift - Foundation/URLProtectionSpace.swift - Foundation/URLProtocol.swift - Foundation/URLRequest.swift - Foundation/URLResponse.swift - Foundation/URLSession/BodySource.swift - Foundation/URLSession/Configuration.swift - Foundation/URLSession/http/HTTPMessage.swift - Foundation/URLSession/http/HTTPURLProtocol.swift - Foundation/URLSession/libcurl/EasyHandle.swift - Foundation/URLSession/libcurl/libcurlHelpers.swift - Foundation/URLSession/libcurl/MultiHandle.swift - Foundation/URLSession/Message.swift - Foundation/URLSession/NativeProtocol.swift - Foundation/URLSession/NetworkingSpecific.swift - Foundation/URLSession/ftp/FTPURLProtocol.swift - Foundation/URLSession/TaskRegistry.swift - Foundation/URLSession/TransferState.swift - Foundation/URLSession/URLSession.swift - Foundation/URLSession/URLSessionConfiguration.swift - Foundation/URLSession/URLSessionDelegate.swift - Foundation/URLSession/URLSessionTask.swift - TARGET - ${CMAKE_C_COMPILER_TARGET} - CFLAGS - ${MSVCRT_C_FLAGS} - -F${CMAKE_CURRENT_BINARY_DIR} - LINK_FLAGS - ${MSVCRT_LINK_FLAGS} - -L${CMAKE_CURRENT_BINARY_DIR} - ${libdispatch_ldflags} - -lFoundation - ${Foundation_INTERFACE_LIBRARIES} - ${CFURLSessionInterface_LIBRARIES} - ${CURL_LIBRARIES} - ${Foundation_RPATH} - ${WORKAROUND_SR9138} - ${WORKAROUND_SR9995} - SWIFT_FLAGS - -DDEPLOYMENT_RUNTIME_SWIFT - -DNS_BUILDING_FOUNDATION_NETWORKING - ${deployment_enable_libdispatch} - -I;${CMAKE_CURRENT_BINARY_DIR}/swift - ${libdispatch_cflags} - ${swift_enable_testing} - ${swift_optimization_flags} - DEPENDS - uuid - CoreFoundation - $<$:CoreFoundationResources> - Foundation) - - - -if(NOT BUILD_SHARED_LIBS) - set(Foundation_INTERFACE_LIBRARIES - -L${install_dir}/usr/lib - -lCoreFoundation - -L${CMAKE_CURRENT_BINARY_DIR} - -luuid - ${CURL_LIBRARIES} - ${ICU_UC_LIBRARY} - ${ICU_I18N_LIBRARY} - ${LIBXML2_LIBRARIES}) -endif() - -add_swift_executable(plutil - SOURCES - Tools/plutil/main.swift - CFLAGS - -F${CMAKE_CURRENT_BINARY_DIR} - LINK_FLAGS - ${libdispatch_ldflags} - -L${CMAKE_CURRENT_BINARY_DIR} - -lFoundation - ${Foundation_INTERFACE_LIBRARIES} - ${Foundation_RPATH} - SWIFT_FLAGS - -DDEPLOYMENT_RUNTIME_SWIFT - -I;${CMAKE_CURRENT_BINARY_DIR}/swift - -I;${ICU_INCLUDE_DIR} - ${libdispatch_cflags} - ${swift_enable_testing} - ${swift_optimization_flags} - ${swift_libc_flags} - DEPENDS - uuid - Foundation - CoreFoundation) +add_subdirectory(Foundation) +add_subdirectory(Tools) if(ENABLE_TESTING) - add_swift_executable(xdgTestHelper - CFLAGS - -F${CMAKE_CURRENT_BINARY_DIR} - LINK_FLAGS - ${libdispatch_ldflags} - -L${CMAKE_CURRENT_BINARY_DIR} - -lFoundation - ${Foundation_INTERFACE_LIBRARIES} - ${XDG_TEST_HELPER_RPATH} - SOURCES - TestFoundation/xdgTestHelper/main.swift - SWIFT_FLAGS - -I;${CMAKE_CURRENT_BINARY_DIR}/swift - -I;${ICU_INCLUDE_DIR} - ${libdispatch_cflags} - DEPENDS - uuid - Foundation - CoreFoundation) - - add_swift_executable(TestFoundation - SOURCES - TestFoundation/main.swift - TestFoundation/HTTPServer.swift - TestFoundation/FTPServer.swift - Foundation/ProgressFraction.swift - TestFoundation/Utilities.swift - TestFoundation/FixtureValues.swift - # Test Cases - TestFoundation/TestAffineTransform.swift - TestFoundation/TestBundle.swift - TestFoundation/TestByteCountFormatter.swift - TestFoundation/TestCalendar.swift - TestFoundation/TestCharacterSet.swift - TestFoundation/TestCodable.swift - TestFoundation/TestDateComponents.swift - TestFoundation/TestDateFormatter.swift - TestFoundation/TestDateInterval.swift - TestFoundation/TestDateIntervalFormatter.swift - TestFoundation/TestDate.swift - TestFoundation/TestDecimal.swift - TestFoundation/TestEnergyFormatter.swift - TestFoundation/TestFileHandle.swift - TestFoundation/TestFileManager.swift - TestFoundation/TestHost.swift - TestFoundation/TestHTTPCookieStorage.swift - TestFoundation/TestHTTPCookie.swift - TestFoundation/TestImports.swift - TestFoundation/TestIndexPath.swift - TestFoundation/TestIndexSet.swift - TestFoundation/TestISO8601DateFormatter.swift - TestFoundation/TestJSONEncoder.swift - TestFoundation/TestJSONSerialization.swift - TestFoundation/TestLengthFormatter.swift - TestFoundation/TestMassFormatter.swift - TestFoundation/TestMeasurement.swift - TestFoundation/TestNotificationCenter.swift - TestFoundation/TestNotificationQueue.swift - TestFoundation/TestNotification.swift - TestFoundation/TestNSArray.swift - TestFoundation/TestNSAttributedString.swift - TestFoundation/TestNSCache.swift - TestFoundation/TestNSCalendar.swift - TestFoundation/TestNSCompoundPredicate.swift - TestFoundation/TestNSData.swift - TestFoundation/TestNSDictionary.swift - TestFoundation/TestNSError.swift - TestFoundation/TestNSGeometry.swift - TestFoundation/TestNSKeyedArchiver.swift - TestFoundation/TestNSKeyedUnarchiver.swift - TestFoundation/TestNSLocale.swift - TestFoundation/TestNSLock.swift - TestFoundation/TestNSNull.swift - TestFoundation/TestNSNumberBridging.swift - TestFoundation/TestNSNumber.swift - TestFoundation/TestNSOrderedSet.swift - TestFoundation/TestNSPredicate.swift - TestFoundation/TestNSRange.swift - TestFoundation/TestNSRegularExpression.swift - TestFoundation/TestNSSet.swift - TestFoundation/TestNSSortDescriptor.swift - TestFoundation/TestNSString.swift - TestFoundation/TestNSTextCheckingResult.swift - TestFoundation/TestNSURLRequest.swift - TestFoundation/TestNSUUID.swift - TestFoundation/TestNSValue.swift - TestFoundation/TestNumberFormatter.swift - TestFoundation/TestObjCRuntime.swift - TestFoundation/TestOperationQueue.swift - TestFoundation/TestPersonNameComponents.swift - TestFoundation/TestPipe.swift - TestFoundation/TestProcessInfo.swift - TestFoundation/TestProcess.swift - TestFoundation/TestProgress.swift - TestFoundation/TestProgressFraction.swift - TestFoundation/TestPropertyListEncoder.swift - TestFoundation/TestPropertyListSerialization.swift - TestFoundation/TestRunLoop.swift - TestFoundation/TestScanner.swift - TestFoundation/TestStream.swift - TestFoundation/TestThread.swift - TestFoundation/TestTimer.swift - TestFoundation/TestTimeZone.swift - TestFoundation/TestUnitConverter.swift - TestFoundation/TestUnit.swift - TestFoundation/TestURLCredential.swift - TestFoundation/TestURLProtectionSpace.swift - TestFoundation/TestURLProtocol.swift - TestFoundation/TestURLRequest.swift - TestFoundation/TestURLResponse.swift - TestFoundation/TestURLSession.swift - TestFoundation/TestURLSessionFTP.swift - TestFoundation/TestURL.swift - TestFoundation/TestUserDefaults.swift - TestFoundation/TestUtils.swift - TestFoundation/TestUUID.swift - TestFoundation/TestXMLDocument.swift - TestFoundation/TestXMLParser.swift - CFLAGS - -F${CMAKE_CURRENT_BINARY_DIR} - LINK_FLAGS - ${libdispatch_ldflags} - -L${CMAKE_CURRENT_BINARY_DIR} - -lFoundation - ${Foundation_INTERFACE_LIBRARIES} - -L${FOUNDATION_PATH_TO_XCTEST_BUILD} - -lXCTest - ${WORKAROUND_SR9138} - $<$:-lWS2_32> - RESOURCES - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/Info.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSURLTestData.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/Test.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSStringTestData.txt - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSString-UTF16-BE-data.txt - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSString-UTF16-LE-data.txt - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSString-UTF32-BE-data.txt - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSString-UTF32-LE-data.txt - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSString-ISO-8859-1-data.txt - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSXMLDocumentTestData.xml - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/PropertyList-1.0.dtd - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSXMLDTDTestData.xml - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-ArrayTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-ComplexTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-ConcreteValueTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-EdgeInsetsTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-NotificationTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-RangeTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-RectTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-URLTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-UUIDTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-OrderedSetTest.plist - ${CMAKE_SOURCE_DIR}/TestFoundation/Resources/TestFileWithZeros.txt - ${CMAKE_SOURCE_DIR}/TestFoundation/Fixtures - SWIFT_FLAGS - -I;${CMAKE_CURRENT_BINARY_DIR}/swift - -I;${FOUNDATION_PATH_TO_XCTEST_BUILD}/swift - -I;${ICU_INCLUDE_DIR} - ${libdispatch_cflags} - ${swift_optimization_flags} - ${swift_libc_flags} - DEPENDS - Foundation - CoreFoundation - xdgTestHelper) - - add_custom_command(TARGET TestFoundation - POST_BUILD - BYPRODUCTS - ${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX} - COMMAND - ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX} - DEPENDS - TestFoundation - xdgTestHelper) - add_test(NAME - TestFoundation - COMMAND - ${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/TestFoundation - WORKING_DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR}/TestFoundation) - set_tests_properties(TestFoundation - PROPERTIES - ENVIRONMENT - LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:${FOUNDATION_PATH_TO_XCTEST_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src - DEPENDS - ${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX}) + add_subdirectory(TestFoundation) endif() -# TODO(compnerd) honour lib vs lib64 -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/swift/Foundation.swiftdoc - ${CMAKE_CURRENT_BINARY_DIR}/swift/Foundation.swiftmodule - DESTINATION - lib/swift/${swift_os}/${swift_arch}) - -if(BUILD_SHARED_LIBS) - set(library_kind SHARED) - set(swift_dir swift) -else() - set(library_kind STATIC) - set(swift_dir swift_static) -endif() - -set(Foundation_OUTPUT_FILE - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_${library_kind}_LIBRARY_PREFIX}Foundation${CMAKE_${library_kind}_LIBRARY_SUFFIX}) - -if(CMAKE_SYSTEM_NAME STREQUAL Windows AND BUILD_SHARED_LIBS) - install(FILES - ${Foundation_OUTPUT_FILE} - DESTINATION - bin) - install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}Foundation${CMAKE_IMPORT_LIBRARY_SUFFIX} - DESTINATION - lib/${swift_dir}/${swift_os}) -else() - install(FILES - ${Foundation_OUTPUT_FILE} - DESTINATION - lib/${swift_dir}/${swift_os}) -endif() # TODO(compnerd) install as a Framework as that is how swift actually is built install(DIRECTORY @@ -644,7 +105,3 @@ install(FILES CoreFoundation/Base.subproj/module.map DESTINATION lib/swift/CoreFoundation) -install(PROGRAMS - ${CMAKE_CURRENT_BINARY_DIR}/plutil${CMAKE_EXECUTABLE_SUFFIX} - DESTINATION - ${CMAKE_INSTALL_FULL_BINDIR}) diff --git a/CoreFoundation/CMakeLists.txt b/CoreFoundation/CMakeLists.txt index 0928546c44..dd18016e87 100644 --- a/CoreFoundation/CMakeLists.txt +++ b/CoreFoundation/CMakeLists.txt @@ -1,7 +1,11 @@ cmake_minimum_required(VERSION 3.4.3) -list(APPEND CMAKE_MODULE_PATH - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") + +if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif() project(CoreFoundation VERSION @@ -422,6 +426,9 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) PRIVATE ${LIBXML2_INCLUDE_DIR}) find_package(CURL REQUIRED) + target_include_directories(CoreFoundation + PRIVATE + ${CURL_INCLUDE_DIRS}) target_include_directories(CFURLSessionInterface PRIVATE ${CURL_INCLUDE_DIRS}) @@ -586,7 +593,7 @@ endif() install(TARGETS CoreFoundation - CFURLSessionInterface + CFURLSessionInterface DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}") install(DIRECTORY diff --git a/Foundation/CMakeLists.txt b/Foundation/CMakeLists.txt new file mode 100644 index 0000000000..cf54025b80 --- /dev/null +++ b/Foundation/CMakeLists.txt @@ -0,0 +1,263 @@ + +# FIXME(compnerd) workaround linker flag munging +set(CMAKE_SHARED_LINKER_FLAGS "") +set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "") +# FIXME(compnerd) workaround the library search path flag +set(CMAKE_LIBRARY_PATH_FLAG -L) +set(CMAKE_LINK_LIBRARY_FLAG "-l") + +add_library(Foundation + AffineTransform.swift + Array.swift + Boxing.swift + Bridging.swift + Bundle.swift + ByteCountFormatter.swift + Calendar.swift + CGFloat.swift + CharacterSet.swift + Codable.swift + Collections+DataProtocol.swift + ContiguousBytes.swift + Data.swift + DataProtocol.swift + Date.swift + DateComponents.swift + DateComponentsFormatter.swift + DateFormatter.swift + DateInterval.swift + DateIntervalFormatter.swift + Decimal.swift + Dictionary.swift + DispatchData+DataProtocol.swift + EnergyFormatter.swift + ExtraStringAPIs.swift + FileHandle.swift + FileManager.swift + FileManager+POSIX.swift + FileManager+Win32.swift + FileManager_XDG.swift + Formatter.swift + FoundationErrors.swift + Host.swift + IndexPath.swift + IndexSet.swift + ISO8601DateFormatter.swift + JSONEncoder.swift + JSONSerialization.swift + LengthFormatter.swift + Locale.swift + MassFormatter.swift + Measurement.swift + MeasurementFormatter.swift + Notification.swift + NotificationQueue.swift + NSArray.swift + NSAttributedString.swift + NSCache.swift + NSCalendar.swift + NSCFArray.swift + NSCFBoolean.swift + NSCFCharacterSet.swift + NSCFDictionary.swift + NSCFSet.swift + NSCFString.swift + NSCharacterSet.swift + NSCoder.swift + NSComparisonPredicate.swift + NSCompoundPredicate.swift + NSConcreteValue.swift + NSData+DataProtocol.swift + NSData.swift + NSDate.swift + NSDecimalNumber.swift + NSDictionary.swift + NSEnumerator.swift + NSError.swift + NSExpression.swift + NSGeometry.swift + NSIndexPath.swift + NSIndexSet.swift + NSKeyedArchiver.swift + NSKeyedArchiverHelpers.swift + NSKeyedCoderOldStyleArray.swift + NSKeyedUnarchiver.swift + NSLocale.swift + NSLock.swift + NSLog.swift + NSMeasurement.swift + NSNotification.swift + NSNull.swift + NSNumber.swift + NSObjCRuntime.swift + NSObject.swift + NSOrderedSet.swift + NSPathUtilities.swift + NSPersonNameComponents.swift + NSPlatform.swift + NSPredicate.swift + NSRange.swift + NSRegularExpression.swift + NSSet.swift + NSSortDescriptor.swift + NSSpecialValue.swift + NSString.swift + NSStringAPI.swift + NSSwiftRuntime.swift + NSTextCheckingResult.swift + NSTimeZone.swift + NSURL.swift + NSURLError.swift + NSUUID.swift + NSValue.swift + NumberFormatter.swift + Operation.swift + PersonNameComponents.swift + PersonNameComponentsFormatter.swift + Pointers+DataProtocol.swift + Port.swift + PortMessage.swift + Process.swift + ProcessInfo.swift + Progress.swift + ProgressFraction.swift + PropertyListEncoder.swift + PropertyListSerialization.swift + ReferenceConvertible.swift + RunLoop.swift + Scanner.swift + ScannerAPI.swift + Set.swift + Stream.swift + String.swift + StringEncodings.swift + Thread.swift + Timer.swift + TimeZone.swift + Unit.swift + URL.swift + URLComponents.swift + UserDefaults.swift + UUID.swift + XMLDocument.swift + XMLDTD.swift + XMLDTDNode.swift + XMLElement.swift + XMLNode.swift + XMLParser.swift) + +target_compile_definitions(Foundation PRIVATE + DEPLOYMENT_RUNTIME_SWIFT) + +target_compile_options(Foundation PRIVATE + $<$:-enable-testing>) +target_compile_options(Foundation PUBLIC + "SHELL:-Xcc -F${CMAKE_BINARY_DIR}") + +set_target_properties(Foundation PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY} + INTERFACE_LINK_DIRECTORIES $) + +if(FOUNDATION_ENABLE_LIBDISPATCH) + target_compile_definitions(Foundation PRIVATE + DEPLOYMENT_ENABLE_LIBDISPATCH) + + # FIXME(compnerd) these three can go away with export targets + target_compile_options(Foundation PUBLIC + "SHELL:-Xcc -fblocks" + "SHELL:-Xcc -I${FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE}") + target_include_directories(Foundation PUBLIC + ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/swift) + target_link_directories(Foundation PUBLIC + ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src + ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src/BlocksRuntime + ${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src/swift) + + target_link_libraries(Foundation PRIVATE + swiftDispatch) +endif() + +target_link_libraries(Foundation PRIVATE + uuid CoreFoundation) +target_link_libraries(Foundation PRIVATE + ${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY}) +target_link_libraries(Foundation PRIVATE + ${LIBXML2_LIBRARIES}) +if(CMAKE_SYSTEM_NAME STREQUAL Windows) + target_link_libraries(Foundation PRIVATE + DbgHelp Ole32 ShLwApi Shell32 WS2_32 iphlpapi pathcch) + target_link_libraries(Foundation PRIVATE + CoreFoundationResources) + + # FIXME(compnerd) SR-9138 + target_link_options(Foundation PRIVATE + "LINKER:-ignore:4217") +endif() + +add_library(FoundationNetworking + Boxing.swift + NSURLRequest.swift + HTTPCookie.swift + HTTPCookieStorage.swift + URLAuthenticationChallenge.swift + URLCache.swift + URLCredential.swift + URLCredentialStorage.swift + URLProtectionSpace.swift + URLProtocol.swift + URLRequest.swift + URLResponse.swift + URLSession/BodySource.swift + URLSession/Configuration.swift + URLSession/http/HTTPMessage.swift + URLSession/http/HTTPURLProtocol.swift + URLSession/libcurl/EasyHandle.swift + URLSession/libcurl/libcurlHelpers.swift + URLSession/libcurl/MultiHandle.swift + URLSession/Message.swift + URLSession/NativeProtocol.swift + URLSession/NetworkingSpecific.swift + URLSession/ftp/FTPURLProtocol.swift + URLSession/TaskRegistry.swift + URLSession/TransferState.swift + URLSession/URLSession.swift + URLSession/URLSessionConfiguration.swift + URLSession/URLSessionDelegate.swift + URLSession/URLSessionTask.swift) + +target_compile_definitions(FoundationNetworking PRIVATE + DEPLOYMENT_RUNTIME_SWIFT + NS_BUILDING_FOUNDATION_NETWORKING) + +target_compile_options(FoundationNetworking PRIVATE + $<$:-enable-testing>) + +target_link_libraries(FoundationNetworking PRIVATE + Foundation + CFURLSessionInterface) + +if(CMAKE_SYSTEM_NAME STREQUAL Windows) + # FIXME(compnerd) SR-9138 + target_link_options(FoundationNetworking PRIVATE + "LINKER:-ignore:4217") +endif() + +set_target_properties(FoundationNetworking PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY} + INTERFACE_LINK_DIRECTORIES $) + + +install(FILES + ${CMAKE_Swift_MODULE_DIRECTORY}/Foundation.swiftdoc + ${CMAKE_Swift_MODULE_DIRECTORY}/Foundation.swiftmodule + ${CMAKE_Swift_MODULE_DIRECTORY}/FoundationNetworking.swiftdoc + ${CMAKE_Swift_MODULE_DIRECTORY}/FoundationNetworking.swiftmodule + DESTINATION + lib/swift$<$>:_static>/$/${swift_arch}) +install(TARGETS + Foundation + FoundationNetworking + ARCHIVE DESTINATION lib/swift$<$>:_static>/$/${swift_arch} + LIBRARY DESTINATION lib/swift$<$>:_static>/$/${swift_arch} + RUNTIME DESTINATION bin) + diff --git a/TestFoundation/CMakeLists.txt b/TestFoundation/CMakeLists.txt new file mode 100644 index 0000000000..82b089a835 --- /dev/null +++ b/TestFoundation/CMakeLists.txt @@ -0,0 +1,148 @@ + +# FIXME(compnerd) workaround linker flag munging +set(CMAKE_EXE_LINKER_FLAGS "") +set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "") +# FIXME(compnerd) workaround the library search path flag +set(CMAKE_LIBRARY_PATH_FLAG -L) +set(CMAKE_LINK_LIBRARY_FLAG "-l") +set(CMAKE_CREATE_CONSOLE_EXE "") + +add_executable(xdgTestHelper + xdgTestHelper/main.swift) +target_link_libraries(xdgTestHelper PRIVATE + Foundation + FoundationNetworking) + +add_executable(TestFoundation + main.swift + HTTPServer.swift + FTPServer.swift + ../Foundation/ProgressFraction.swift + Utilities.swift + FixtureValues.swift + # Test Cases + TestAffineTransform.swift + TestBundle.swift + TestByteCountFormatter.swift + TestCalendar.swift + TestCharacterSet.swift + TestCodable.swift + TestDateComponents.swift + TestDateFormatter.swift + TestDateInterval.swift + TestDateIntervalFormatter.swift + TestDate.swift + TestDecimal.swift + TestEnergyFormatter.swift + TestFileHandle.swift + TestFileManager.swift + TestHost.swift + TestHTTPCookieStorage.swift + TestHTTPCookie.swift + TestImports.swift + TestIndexPath.swift + TestIndexSet.swift + TestISO8601DateFormatter.swift + TestJSONEncoder.swift + TestJSONSerialization.swift + TestLengthFormatter.swift + TestMassFormatter.swift + TestMeasurement.swift + TestNotificationCenter.swift + TestNotificationQueue.swift + TestNotification.swift + TestNSArray.swift + TestNSAttributedString.swift + TestNSCache.swift + TestNSCalendar.swift + TestNSCompoundPredicate.swift + TestNSData.swift + TestNSDictionary.swift + TestNSError.swift + TestNSGeometry.swift + TestNSKeyedArchiver.swift + TestNSKeyedUnarchiver.swift + TestNSLocale.swift + TestNSLock.swift + TestNSNull.swift + TestNSNumberBridging.swift + TestNSNumber.swift + TestNSOrderedSet.swift + TestNSPredicate.swift + TestNSRange.swift + TestNSRegularExpression.swift + TestNSSet.swift + TestNSSortDescriptor.swift + TestNSString.swift + TestNSTextCheckingResult.swift + TestNSURLRequest.swift + TestNSUUID.swift + TestNSValue.swift + TestNumberFormatter.swift + TestObjCRuntime.swift + TestOperationQueue.swift + TestPersonNameComponents.swift + TestPipe.swift + TestProcessInfo.swift + TestProcess.swift + TestProgress.swift + TestProgressFraction.swift + TestPropertyListEncoder.swift + TestPropertyListSerialization.swift + TestRunLoop.swift + TestScanner.swift + TestStream.swift + TestThread.swift + TestTimer.swift + TestTimeZone.swift + TestUnitConverter.swift + TestUnit.swift + TestURLCredential.swift + TestURLProtectionSpace.swift + TestURLProtocol.swift + TestURLRequest.swift + TestURLResponse.swift + TestURLSession.swift + TestURLSessionFTP.swift + TestURL.swift + TestUserDefaults.swift + TestUtils.swift + TestUUID.swift + TestXMLDocument.swift + TestXMLParser.swift) +target_link_libraries(TestFoundation PRIVATE + Foundation) + +target_link_libraries(TestFoundation PRIVATE + XCTest) +# FIXME(compnerd) these two can go away with export targets +target_include_directories(TestFoundation PRIVATE + ${FOUNDATION_PATH_TO_XCTEST_BUILD}/swift) +target_link_directories(TestFoundation PRIVATE + ${FOUNDATION_PATH_TO_XCTEST_BUILD}) + +if(CMAKE_SYSTEM_NAME STREQUAL Windows) + target_link_libraries(TestFoundation PRIVATE + WS2_32) +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL Windows) + # FIXME(compnerd) SR-9138 + target_link_options(TestFoundation PRIVATE + "LINKER:-ignore:4217") +endif() + +add_custom_command(TARGET TestFoundation POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory TestFoundation + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources TestFoundation/Resources/ + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Fixtures TestFoundation/Fixtures/ + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ TestFoundation/ + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ TestFoundation/ + BYPRODUCTS TestFoundation) + +add_test(NAME TestFoundation + COMMAND TestFoundation/TestFoundation${CMAKE_EXECUTABLE_SUFFIX}) +set_tests_properties(TestFoundation PROPERTIES + ENVIRONMENT LD_LIBRARY_PATH=$:${FOUNDATION_PATH_TO_XCTEST_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src + DEPENDS xdgTestHelper) + diff --git a/Tools/CMakeLists.txt b/Tools/CMakeLists.txt new file mode 100644 index 0000000000..829770a33f --- /dev/null +++ b/Tools/CMakeLists.txt @@ -0,0 +1,3 @@ + +add_subdirectory(plutil) + diff --git a/Tools/plutil/CMakeLists.txt b/Tools/plutil/CMakeLists.txt new file mode 100644 index 0000000000..dfdf2de2e0 --- /dev/null +++ b/Tools/plutil/CMakeLists.txt @@ -0,0 +1,17 @@ + +# FIXME(compnerd) workaround linker flag munging +set(CMAKE_EXE_LINKER_FLAGS "") +set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "") +# FIXME(compnerd) workaround the library search path flag +set(CMAKE_LIBRARY_PATH_FLAG -L) +set(CMAKE_LINK_LIBRARY_FLAG "-l") +set(CMAKE_CREATE_CONSOLE_EXE "") + +add_executable(plutil + main.swift) +target_link_libraries(plutil PRIVATE + Foundation) + +install(TARGETS plutil + DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) + diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index fc6b054a6e..5d8c7e45ab 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -1,243 +1,4 @@ -include(CMakeParseArguments) -include(ProcessorCount) - -# Creates an output file map give a target and its list of sources at -# output_path -# -# Usage: -# create_output_file_map(target sources output_path) -function(create_output_file_map target sources output_path) - set(output_list) - set(output_file_map "{\n") - foreach(source ${sources}) - get_filename_component(name ${source} NAME) - - set(obj ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${name}${CMAKE_C_OUTPUT_EXTENSION}) - set(deps ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${name}.d) - set(swiftdeps ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${name}.swiftdeps) - set(dia ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${name}.dia) - set(output_entry "\"${source}\": {\n\ - \"object\": \"${obj}\",\n\ - \"dependencies\": \"${deps}\",\n\ - \"swift-dependencies\": \"${swiftdeps}\",\n\ - \"diagnostics\": \"${dia}\"\n\ -},\n") - string(APPEND output_file_map ${output_entry}) - endforeach() - set(master_deps ${CMAKE_CURRENT_BINARY_DIR}/${target}.swiftdeps) - string(APPEND output_file_map "\"\": {\n\ - \"swift-dependencies\": \"${master_deps}\"\n\ - }\n") - string(APPEND output_file_map "}\n") - file(WRITE ${output_path} ${output_file_map}) -endfunction() - -function(add_swift_target target) - set(options LIBRARY;SHARED;STATIC) - set(single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT;TARGET) - set(multiple_value_options CFLAGS;DEPENDS;LINK_FLAGS;RESOURCES;SOURCES;SWIFT_FLAGS) - - cmake_parse_arguments(AST "${options}" "${single_value_options}" "${multiple_value_options}" ${ARGN}) - - set(compile_flags ${CMAKE_SWIFT_FLAGS}) - set(link_flags) - - list(APPEND compile_flags -incremental) - ProcessorCount(CPU_COUNT) - if(NOT CPU_COUNT EQUAL 0) - list(APPEND compile_flags -j;${CPU_COUNT}) - endif() - if(AST_TARGET) - list(APPEND compile_flags -target;${AST_TARGET}) - list(APPEND link_flags -target;${AST_TARGET}) - endif() - if(AST_MODULE_NAME) - list(APPEND compile_flags -module-name;${AST_MODULE_NAME}) - else() - list(APPEND compile_flags -module-name;${target}) - endif() - if(AST_MODULE_LINK_NAME) - list(APPEND compile_flags -module-link-name;${AST_MODULE_LINK_NAME}) - endif() - if(AST_MODULE_CACHE_PATH) - list(APPEND compile_flags -module-cache-path;${AST_MODULE_CACHE_PATH}) - endif() - if(AST_MODULE_PATH) - get_filename_component(module_location ${AST_MODULE_PATH} PATH) - file(MAKE_DIRECTORY "${module_location}") - list(APPEND compile_flags "-emit-module-path;${AST_MODULE_PATH}") - endif() - if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) - list(APPEND compile_flags -g) - endif() - if(AST_SWIFT_FLAGS) - foreach(flag ${AST_SWIFT_FLAGS}) - list(APPEND compile_flags ${flag}) - endforeach() - endif() - if(AST_CFLAGS) - foreach(flag ${AST_CFLAGS}) - list(APPEND compile_flags -Xcc;${flag}) - endforeach() - endif() - if(AST_LINK_FLAGS) - foreach(flag ${AST_LINK_FLAGS}) - list(APPEND link_flags ${flag}) - endforeach() - endif() - if(AST_LIBRARY) - if(AST_STATIC AND AST_SHARED) - message(SEND_ERROR "add_swift_target asked to create library as STATIC and SHARED") - elseif(AST_STATIC OR NOT BUILD_SHARED_LIBS) - set(library_kind STATIC) - elseif(AST_SHARED OR BUILD_SHARED_LIBS) - set(library_kind SHARED) - endif() - else() - if(AST_STATIC OR AST_SHARED) - message(SEND_ERROR "add_swift_target asked to create executable as STATIC or SHARED") - endif() - endif() - if(NOT AST_OUTPUT) - if(AST_LIBRARY) - if(AST_SHARED OR BUILD_SHARED_LIBS) - set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${CMAKE_SHARED_LIBRARY_PREFIX}${target}${CMAKE_SHARED_LIBRARY_SUFFIX}) - else() - set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${CMAKE_STATIC_LIBRARY_PREFIX}${target}${CMAKE_STATIC_LIBRARY_SUFFIX}) - endif() - else() - set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${target}${CMAKE_EXECUTABLE_SUFFIX}) - endif() - endif() - if(CMAKE_SYSTEM_NAME STREQUAL Windows) - if(AST_SHARED OR BUILD_SHARED_LIBS) - set(IMPORT_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${CMAKE_IMPORT_LIBRARY_PREFIX}${target}${CMAKE_IMPORT_LIBRARY_SUFFIX}) - endif() - endif() - - set(sources) - set(rsp_text) - foreach(source ${AST_SOURCES}) - get_filename_component(location ${source} PATH) - if(IS_ABSOLUTE ${location}) - list(APPEND sources ${source}) - string(APPEND rsp_text "${source} ") - else() - list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/${source}) - string(APPEND rsp_text "${CMAKE_CURRENT_SOURCE_DIR}/${source} ") - endif() - endforeach() - - set(output_map_path ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/output-file-map.json) - create_output_file_map(${target} "${sources}" ${output_map_path}) - list(APPEND compile_flags -output-file-map;${output_map_path}) - - string(LENGTH sources source_length) - set(rsp_file ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${target}.rsp) - file(WRITE ${rsp_file} ${rsp_text}) - - if(AST_LIBRARY) - set(emit_library -emit-library) - endif() - if(NOT AST_LIBRARY OR library_kind STREQUAL SHARED) - add_custom_command(OUTPUT - ${AST_OUTPUT} - DEPENDS - ${sources} - ${AST_DEPENDS} - COMMAND - ${CMAKE_SWIFT_COMPILER} ${emit_library} ${compile_flags} ${link_flags} -o ${AST_OUTPUT} @${rsp_file}) - add_custom_target(${target} - ALL - DEPENDS - ${AST_OUTPUT} - ${module} - ${documentation}) - else() - add_library(${target}-static STATIC ${sources}) - if(AST_DEPENDS) - add_dependencies(${target}-static ${AST_DEPENDS}) - endif() - get_filename_component(ast_output_bn ${AST_OUTPUT} NAME) - if(NOT CMAKE_STATIC_LIBRARY_PREFIX STREQUAL "") - string(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" ast_output_bn ${ast_output_bn}) - endif() - if(NOT CMAKE_STATIC_LIBRARY_SUFFIX STREQUAL "") - string(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" ast_output_bn ${ast_output_bn}) - endif() - get_filename_component(ast_output_dn ${AST_OUTPUT} DIRECTORY) - set_target_properties(${target}-static - PROPERTIES - LINKER_LANGUAGE C - ARCHIVE_OUTPUT_DIRECTORY ${ast_output_dn} - OUTPUT_DIRECTORY ${ast_output_dn} - OUTPUT_NAME ${ast_output_bn}) - add_custom_target(${target} - ALL - DEPENDS - ${target}-static - ${module} - ${documentation}) - endif() - - if(AST_RESOURCES) - if(CMAKE_SYSTEM_NAME STREQUAL Windows) - set(resources_dir ${target}.resources) - else() - set(resources_dir Resources) - endif() - add_custom_command(TARGET - ${target} - POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${target} - COMMAND - ${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${target} - COMMAND - ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${target}/${resources_dir}) - foreach(resource ${AST_RESOURCES}) - if(IS_DIRECTORY ${resource}) - get_filename_component(resource_basename ${resource} NAME) - add_custom_command(TARGET - ${target} - POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy_directory ${resource} ${CMAKE_CURRENT_BINARY_DIR}/${target}/${resources_dir}/${resource_basename}) - else() - add_custom_command(TARGET - ${target} - POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy ${resource} ${CMAKE_CURRENT_BINARY_DIR}/${target}/${resources_dir}/) - endif() - endforeach() - else() - add_custom_command(TARGET - ${target} - POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}) - if(CMAKE_SYSTEM_NAME STREQUAL Windows) - if(AST_SHARED OR BUILD_SHARED_LIBS) - add_custom_command(TARGET - ${target} - POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy ${IMPORT_LIBRARY} ${CMAKE_CURRENT_BINARY_DIR}) - endif() - endif() - endif() -endfunction() - -function(add_swift_library library) - add_swift_target(${library} LIBRARY ${ARGN}) -endfunction() - -function(add_swift_executable executable) - add_swift_target(${executable} ${ARGN}) -endfunction() - # Returns the current architecture name in a variable # # Usage: @@ -272,3 +33,4 @@ function(get_swift_host_arch result_var_name) message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}") endif() endfunction() + diff --git a/uuid/CMakeLists.txt b/uuid/CMakeLists.txt new file mode 100644 index 0000000000..19ca800fd0 --- /dev/null +++ b/uuid/CMakeLists.txt @@ -0,0 +1,18 @@ + +add_library(uuid STATIC + uuid.h + uuid.c) +set_target_properties(uuid PROPERTIES POSITION_INDEPENDENT_CODE YES) +# Add an include directory for the CoreFoundation framework headers to satisfy +# the dependency on TargetConditionals.h +target_include_directories(uuid PUBLIC + ${CMAKE_BINARY_DIR}/CoreFoundation.framework/Headers) +if(CMAKE_SYSTEM_NAME STREQUAL Windows) + target_compile_definitions(uuid PRIVATE + _CRT_NONSTDC_NO_WARNINGS + _CRT_SECURE_NO_DEPRECATE + _CRT_SECURE_NO_WARNINGS) + target_link_libraries(uuid PRIVATE Bcrypt) +endif() +add_dependencies(uuid CoreFoundation) +