Post

Replies

Boosts

Views

Activity

Reply to CMake, Xcode, and Swift and Objective-C
There is now a better solution as the solution suggested here does not work with other build systems other than XCode. I would recommend following or contributing to: https://github.com/apple/swift-cmake-examples/blob/main/3_bidirectional_cxx_interop/cmake/modules/AddSwift.cmake There are some issues with the function but the general solution is to create a custom command and add a target to execute the command. function(_swift_generate_cxx_header_target target module header) cmake_parse_arguments(ARG "" "" "SOURCES;SEARCH_PATHS;DEPENDS" ${ARGN}) if(NOT ARG_SOURCES) message(FATAL_ERROR "No sources provided to 'swift_generate_cxx_header_target'") endif() if(ARG_SEARCH_PATHS) list(TRANSFORM ARG_SEARCH_PATHS PREPEND "-I") endif() if(APPLE) set(SDK_FLAGS "-sdk" "${CMAKE_OSX_SYSROOT}") elseif(WIN32) set(SDK_FLAGS "-sdk" "$ENV{SDKROOT}") endif() add_custom_command( OUTPUT "${header}" COMMAND ${CMAKE_Swift_COMPILER} -frontend -typecheck ${ARG_SEARCH_PATHS} ${ARG_SOURCES} ${SDK_FLAGS} -module-name "${module}" -cxx-interoperability-mode=default -emit-clang-header-path "${header}" DEPENDS ${ARG_DEPENDS} COMMENT "Generating '${header}'" ) add_custom_target("${target}" DEPENDS "${header}" ) endfunction()
Mar ’24