Swift: add_library is failing to compile anything
I am working on a swift library integrating with the ROS Colcon/Ament build system, based on CMake. For my basic packages, using swift with cmake is simply a breeze, but I'm running into issues with a more complicated example. This is a generic CMake file that is included by other packages for the purpose of message generation, and somehow things are behaving differently there. I'm setting up my library as usual:
add_library(${PROJECT_NAME}_swift SHARED "${_generated_swift_files}")
set_target_properties(${PROJECT_NAME}_swift PROPERTIES LINKER_LANGUAGE Swift)
target_link_libraries(${PROJECT_NAME}_swift ${_target_name})
install(TARGETS ${PROJECT_NAME}_swift
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
Example output:
[0/1] Linking Swift shared library libunique_identifier_msgs_swift.so
[1/1] Linking Swift shared library libunique_identifier_msgs_swift.so
CMake Error at cmake_install.cmake:261 (file):
file INSTALL cannot find
"/home/alex/ros2/build/unique_identifier_msgs/libunique_identifier_msgs_swift.so":
No such file or directory.
And nothing is being generated. Install fails because it cannot find the .so file, and it seems as though the compiler isn't even being invoked. Just as a test, I've purposely added invalid syntax to the swift files, and no errors are shown during compilation. I've also verified that the source files variable, ${_generated_swift_files}, is not empty. My first instinct is that this is a problem with the ROS build system. But sure enough, if I replace these swift files with C files, the library is built and installed just fine. I don't think I can provide an easily reproducible example, as that would require getting the whole ROS2 CMake environment setup, but I thought I'd see if anyone has suggestions for what could be causing this strange behavior.
EDIT: I think I found the issue. The sole difference i can find is since this CMake is pulled in from a template, I cannot set the project languages directly. Thus the need for setting LINKER_LANGUAGE. However, even with LINKER_LANGUAGE set, I don't see the output for finding the swiftc compiler in cmake output, like I do in other packages that declare swift as a language in the project definition. Could this be the source of my issue? And if so is there a way to make swift compile correctly without adding it in the project definition?