microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.74k stars 6.29k forks source link

simdjson in project complains about missing threads #13761

Closed AntonioCS closed 3 years ago

AntonioCS commented 3 years ago

Describe the bug I installed simdjson (x64) and when I add the provided Cmake config to my CMakeLists.txt

 find_package(simdjson CONFIG REQUIRED)
    # Note: 2 target(s) were omitted.
    target_link_libraries(main PRIVATE simdjson::simdjson simdjson::simdjson-flags simdjson::simdjson-source simdjson::simdjson-headers)

I get the following error:

LINK : fatal error LNK1104: cannot open file 'Threads::Threads.lib'

I reported this in the vcpkg channel and @Neumann-A mentioned that it might be missing find_dependency(Threads) in simdjsonConfig.cmake

Environment

To Reproduce Steps to reproduce the behavior:

  1. ./vcpkg install simdjson (I have set the env var for x64)
  2. Grab the cmake commands
  3. Put in your CMakeLists.txt
  4. Compile
  5. See the LINK : fatal error LNK1104: cannot open file 'Threads::Threads.lib' in msvc ouput pane

Expected behavior For it to compile without issues

Additional context Switched to rapidjson so I there is no urgency :relaxed:

Journeyman1337 commented 3 years ago

Same issue I posted on simdjson repository: https://github.com/simdjson/simdjson/issues/1375

lemire commented 3 years ago

The simdjson library definitively support Microsoft Visual Studio Community 2019 under a 64-bit Windows.

Here is the relevant code in our CMake build...

option(SIMDJSON_ENABLE_THREADS "Link with thread support" ON)
if(SIMDJSON_ENABLE_THREADS)
  set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  set(THREADS_PREFER_PTHREAD_FLAG TRUE)
  find_package(Threads REQUIRED)
  target_link_libraries(simdjson-flags INTERFACE Threads::Threads)
  target_link_libraries(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
  target_compile_options(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
  target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_THREADS_ENABLED=1) # This will be set in the code automatically.
endif()
lemire commented 3 years ago

Ping @myd7349

lemire commented 3 years ago

@JonLiu1993 Posted an issue downstream regarding the port.

https://github.com/simdjson/simdjson/issues/1383

It seems that provided CMake instructions are incorrect.

The following works for me:

cmake_minimum_required(VERSION 3.0)
project(test)

add_executable(test test.cpp)

find_package(simdjson CONFIG REQUIRED)
find_package(Threads REQUIRED)
target_link_libraries(test PRIVATE simdjson::simdjson)

The provided instructions do not make sense to me. For example, simdjson::simdjson-source does not get installed (nor should it), so I do not see how you could establish a dependency with this target.

Neumann-A commented 3 years ago

@lemire That is an automatically generated usage extracted from the provided targets in the simdjson-config.cmake. As it seems simdjson exports a lot of targets which are unnecessary to be exported or even unuseable if exported. The only reason they are getting exported is because of the misuse of targets in simdjson and cmake giving and error otherwise.

lemire commented 3 years ago

@Neumann-A Ah. Let us see what we can do about that.

lemire commented 3 years ago

I am confident that we will resolve whatever we have to resolve upstream with release 0.8.

JonLiu1993 commented 3 years ago

I am confident that we will resolve whatever we have to resolve upstream with release 0.8.

thank you for the help

lemire commented 3 years ago

Release 0.8 is out. It should solve this issue.

JonLiu1993 commented 3 years ago

@lemire ,Thank you for your effort. I will update to the latest version for local testing. I will close the issue after success.

JonLiu1993 commented 3 years ago

Solved by #17200