Since switching to CMake 3.21 we are getting a host of errors relating to “Threads::Threads”
This is happening on Windows/MSVC.
I get multiple error message like this after configuration is done
-- Configuring done
CMake Error at CMakeLists.txt:33 (add_library):
Target "foobar" links to target "Threads::Threads" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
And when I check the VS solution I found this in it.
It’s trying to link a library called “Threads::Threads.lib”
CMake Error at CMakeLists.txt:5 (add_executable):
Target "baz" links to target "Threads::Threads" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
Not sure if this helps but, if I change the project slightly it works now.
temp/CMakeLists.txt
add_library(foo STATIC)
add_subdirectory(src)
# Move these 2 calls out of the 'src' dir CMakeLists.txt
find_package(Threads REQUIRED)
target_link_libraries(foo PRIVATE Threads::Threads)
temp\src\CMakeLists.txt
target_sources(foo PRIVATE foo.cpp)
target_include_directories(foo PUBLIC .)