0

I am trying to configure a CMakeLists.txt to include any external libraries. I have VSCode in Windows 10 compiling using g++. The compiler works. I have installed Poco (and others) using vcpkg to /src/vcpkg. I created the following CMakeLists.txt:

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_TOOLCHAIN_FILE "C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake"
    CACHE STRING "Vcpkg toolchain file")

# Add the directory where your packages are installed
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};C:/src/vcpkg/installed/x86-windows")

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)

# Set the path to the Poco package configuration files
# set(Poco_DIR "C:/src/vcpkg/")

find_package(poco REQUIRED COMPONENTS Foundation JSON) 

I have received various error stating that the PocoConfig.make could not be found before the last attempt above. I now get the following error

[cmake]   Could not find a configuration file for package "poco" that is compatible
[cmake]   with requested version "".
[cmake] 
[cmake]   The following configuration files were considered but not accepted:
[cmake] 
[cmake]     C:/src/vcpkg/installed/x86-windows/share/poco/pocoConfig.cmake, version: 1.12.4 (32bit)

I thought this might be related to x64 vs x32 compatibility? So tried forcing with set(CMAKE_GENERATOR_PLATFORM "x86") but this didn't help.

I have also downloaded the x64 library files using vcpkg and now have the following error:

[cmake] -- Found ZLIB: C:/src/vcpkg/installed/x64-windows/lib/zlib.lib (found version "1.2.13") 
[cmake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake]   Could NOT find PCRE2 (missing: PCRE2_LIBRARY)
[cmake] Call Stack (most recent call first):
[cmake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/FindPCRE2.cmake:94 (find_package_handle_standard_args)
[cmake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/PocoFoundationConfig.cmake:5 (find_dependency)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/PocoConfig.cmake:35 (find_package)
[cmake]   CMakeLists.txt:19 (find_package)

libs installed:

-a----        30/05/2023     14:43          20424 pcre2-16.lib
-a----        30/05/2023     14:43          20424 pcre2-32.lib
-a----        30/05/2023     14:42          19974 pcre2-8.lib
-a----        30/05/2023     14:43           2362 pcre2-posix.lib

I would appreciate some help point out why I am having such trouble with what should be a simple process.

Have tried the suggestions but still the same issues as below

[main] Configuring project: helloworld 
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE:STRING=c:/src/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\g++.exe "-SC:/Users/phild/Documents/C++ Projects/helloworld" "-Bc:/Users/phild/Documents/C++ Projects/helloworld/build" -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 12.2.0
[cmake] -- The CXX compiler identification is GNU 12.2.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Found ZLIB: optimized;C:/src/vcpkg/installed/x64-windows/lib/zlib.lib;debug;C:/src/vcpkg/installed/x64-windows/debug/lib/zlibd.lib (found version "1.2.13") 
[cmake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake]   Could NOT find PCRE2 (missing: PCRE2_LIBRARY)
[cmake] Call Stack (most recent call first):
[cmake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/FindPCRE2.cmake:94 (find_package_handle_standard_args)
[cmake]   C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake:853 (_find_package)
[cmake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/PocoFoundationConfig.cmake:5 (find_dependency)
[cmake]   C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake:853 (_find_package)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/PocoConfig.cmake:35 (find_package)
[cmake]   C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake:853 (_find_package)
[cmake]   CMakeLists.txt:13 (find_package)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!

PCRE2 library path is C:\src\vcpkg\installed\x64-windows\lib

  • You shouldn't be setting the toolchain file to use in the `CMakeLists.txt` file, especially not after the first `project()` command. Use `cmake --toolchain ... -S ... -B ...` instead. `find_package` should happen after the `project` command, should there be one below the code snippet you've shown... – fabian May 30 '23 at 21:36
  • Thanks for the reply. I haven't been down this route before so please could you point me to a step by step tutorial which explains using cmake --toochain ? in conjunction with the CMakeLists file the vscode IDE. – Phil Davies May 30 '23 at 22:02
  • "please could you point me to a step by step tutorial which explains using cmake --toochain ? in conjunction with the CMakeLists file the vscode IDE." - See e.g. [that question](https://stackoverflow.com/q/64838971/3440745) and its `setting.json` file. – Tsyvarev May 30 '23 at 22:19
  • "libs installed" - Where exactly pcre libraries are installed? What is **full path** to `pcre2-8.lib` file? (Exactly that file is searched in [FindPCRE2.cmake](https://github.com/pocoproject/poco/blob/a9ad1137420f38027ad4e1a35ff8e76e3e3487b9/cmake/FindPCRE2.cmake#L69) script shipped with Poco). – Tsyvarev May 30 '23 at 22:31

1 Answers1

0

To use the Poco lib installed via vcpkg, there are three steps should do in CMakeLists:

  • Firstly, specify your toolchain file, after setting CMAKE_TOOLCHAIN_FILE, you can use the standard CMake functions(find_package(), find_path(), and find_library()) to find libraries from vcpkg. There are two methods to specify your toolchain file:
    • place the set(CMAKE_TOOLCHAIN_FILE...) command before project command;
    • use the command cmake -S... -B... -DCMAKE_TOOLCHAIN_FILE=<vcpkg-root>/scripts/buildsystems/vcpkg.cmake.
  • Secondly, use the find_package(Poco REQUIRED COMPONENTS Foundation JSON) command to find the Poco lib.
  • Finally, add target_link_libraries(${PROJECT_NAME} PUBLIC Poco::Foundation Poco::JSON) command after add_executable() or add_library() command to link the Poco lib.
Tom
  • 177
  • 7