Swift: Incompatible with THREADS_PREFER_PTHREAD_FLAG = ON (error: unknown argument: '-pthread')
When building a small test of Swift and C++ together on Linux I noticed that setting THREADS_PREFER_PTHREAD_FLAG=ON adds -pthread
to the swiftc arguments, which causes it to fail.
cmake_minimum_required(VERSION 3.22)
project(swifttest)
enable_language(Swift)
find_package(Threads)
add_library(librarytest SHARED
test.cpp
test.swift
)
target_link_libraries(librarytest PRIVATE
Threads::Threads
)
This compiles with cmake -GNinja -DTHREADS_PREFER_PTHREAD_FLAG=OFF ../
, but not with cmake -GNinja -DTHREADS_PREFER_PTHREAD_FLAG=ON ../
. I get error: unknown argument: '-pthread'
Edited by Harry Mallon