simdjson / simdjson

Parsing gigabytes of JSON per second : used by Facebook/Meta Velox, the Node.js runtime, ClickHouse, WatermelonDB, Apache Doris, Milvus, StarRocks
https://simdjson.org
Apache License 2.0
19.22k stars 1.02k forks source link

[usage] Can't find simdjson.cpp when using simdjson on cmake #1383

Closed JonLiu1993 closed 3 years ago

JonLiu1993 commented 3 years ago

Hi guys, I'm vcpkg maintainer. Recently I tried to update simdjson in vcpkg but some issues happend when I tried to use it after build.

Host Environment

To Reproduce Steps to reproduce the behavior:

  1. git clone https://github.com/microsoft/vcpkg.git
  2. ./vcpkg install simdjson:x86-windows
  3. Write sample CMakeLists.txt:
    
    cmake_minimum_required(VERSION 3.0)
    project(test)

add_executable(test test.cpp)

find_package(simdjson CONFIG REQUIRED) target_link_libraries(test PRIVATE simdjson::simdjson simdjson::simdjson-flags simdjson::simdjson-source simdjson::simdjson-headers)

4. Configure the sample project

**Failure logs** 
-Cut and past the appropriate build messages from the console output.

1> CMake generation started for configuration: 'x86-Debug'. 1> Command line: "cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Visual Studio 16 2019" -A Win32 -DCMAKE_CONFIGURATION_TYPES:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\usr\source\repos\CMakeProject20\out\install\x86-Debug" -DCMAKE_TOOLCHAIN_FILE=F:/test6/vcpkg/scripts/buildsystems/vcpkg.cmake "C:\Users\usr\source\repos\CMakeProject20" 2>&1" 1> Working directory: C:\Users\usr\source\repos\CMakeProject20\out\build\x86-Debug 1> [CMake] -- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.17134. 1> [CMake] -- Configuring done 1> [CMake] CMake Error at F:/test6/vcpkg/scripts/buildsystems/vcpkg.cmake:454 (_add_executable): 1> [CMake] Cannot find source file: 1> [CMake] 1> [CMake] //simdjson.cpp 1> [CMake] 1> [CMake] Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm 1> [CMake] .hpp .hxx .in .txx 1> [CMake] Call Stack (most recent call first): 1> [CMake] CMakeProject20/CMakeLists.txt:4 (add_executable) 1> [CMake] -- Generating done 1> [CMake] CMake Generate step failed. Build files cannot be regenerated correctly. 1> 'cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Visual Studio 16 2019" -A Win32 -DCMAKE_CONFIGURATION_TYPES:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\usr\source\repos\CMakeProject20\out\install\x86-Debug" -DCMAKE_TOOLCHAIN_FILE=F:/test6/vcpkg/scripts/buildsystems/vcpkg.cmake "C:\Users\usr\source\repos\CMakeProject20" 2>&1"' execution failed with error: ''cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Visual Studio 16 2019" -A Win32 -DCMAKE_CONFIGURATION_TYPES:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\usr\source\repos\CMakeProject20\out\install\x86-Debug" -DCMAKE_TOOLCHAIN_FILE=F:/test6/vcpkg/scripts/buildsystems/vcpkg.cmake "C:\Users\usr\source\repos\CMakeProject20" 2>&1"' returned with exit code: 1'.


**Additional context**
1. 
https://github.com/simdjson/simdjson/blob/920f5355001f053ae98f87d391d69bda0a886a5e/src/CMakeLists.txt#L20
Here, the `INTERFACE` target set the property `BUILD_TARGET` but missing `INSTALL_TARGET` (or it should be `INSTALL_TARGET`?), that caused the expoted `simdjson-config.cmake` missing the source file `simdjson.cpp`'s absoutly path:
```cmake
add_library(simdjson::simdjson-source INTERFACE IMPORTED)

set_target_properties(simdjson::simdjson-source PROPERTIES
  INTERFACE_LINK_LIBRARIES "simdjson::simdjson-include-source"
  INTERFACE_SOURCES "/simdjson.cpp"
)
  1. The source file simdjson.cpp isn't installed to the install directory, that caused the user can't use that source file.

Can anyone take a look?

Thanks.

JonLiu1993 commented 3 years ago

Relate to #13761

lemire commented 3 years ago

I think this should be reported upstream at https://github.com/microsoft/vcpkg

We are happy to help, but we don't control vcpkg packaging.

lemire commented 3 years ago

@myd7349 can you help?

lemire commented 3 years ago

The source file simdjson.cpp isn't installed to the install directory, that caused the user can't use that source file.

Why would we install the source file simdjson.cpp? We install the compiled sources and the header (simdjson.h), but not the source files.

You configure your project with...

find_package(simdjson CONFIG REQUIRED)
target_link_libraries(test PRIVATE simdjson::simdjson simdjson::simdjson-flags simdjson::simdjson-source simdjson::simdjson-headers)

I am not a vcpkg expert but this looks wrong. I think it should be something like

target_link_libraries(test PRIVATE simdjson)

or maybe

target_link_libraries(test PRIVATE simdjson::simdjson)
lemire commented 3 years ago

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)

I am going to close this issue and open an issue with downstream.

lemire commented 3 years ago

So I commented at https://github.com/microsoft/vcpkg/issues/13761 instead of opening a new issue.

I think that the instructions that users receive need to be updated.

lemire commented 3 years ago

Reopening because I think our CMake build is bad.

cc @Neumann-A

myd7349 commented 3 years ago

Sorry for the long delay. I will look into it this weekend.

lemire commented 3 years ago

@myd7349 I think we solve it via https://github.com/simdjson/simdjson/pull/1385

Please have a look at the PR if you can. I will take all the advice I can get.