skip to Main Content

I’m trying to build PROJ from source. I don’t have many of its dynamic dependencies on Centos 7, nor is it possible for me to obtain these dependencies through the system package manager.

In order to skirt these issues, I sought to use VCPKG. However VCPKG is in a lot of turmoil over PROJ and I cannot physically use any version past 7.2.x in VCPKG (I need newer features) and I can’t load geo tiffs either (so most non trivial projections will straight up not work). So I can’t use VCPKG and PROJ together at all.

However I can still comfortably get the dependencies required to run PROJ through VCPKG.

I tried to convert PROJ source into a subdirectory, however to my suprise it was still trying to use my system libraries despite -DCMAKE_TOOLCHAIN_FILE=... -DVCPKG_TARGET_TRIPLET=x64-linux being set.

I tried using the directory as a standalone library, but with the VCPKG variables set, and… it worked.

So I tried setting cache variables to see if somehow that wasn’t propagated downwards, and it didn’t work (error message same as below)

set(CMAKE_TOOLCHAIN_FILE "/home/user/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "TEST")
set(VCPKG_TARGET_TRIPLET "x64-linux" CACHE STRING "TEST")
add_subdirectory(external/PROJ)

My project is setup like this:

- CMakeLists.txt
- main.cpp
- external
    - PROJ 
        ...
    

my cmake is like this:

cmake_minimum_required(VERSION 3.13)
project(test)
set(CMAKE_CXX_STANDARD 17)

add_subdirectory(external/PROJ)
add_executable(test main.cpp)
target_link_libraries(test PRIVATE PROJ::proj)

and I keep getting

-- Found Sqlite3: /usr/lib64/libsqlite3.so
-- Sqlite3 version: 3.7.17
CMake Error at external/PROJ/CMakeLists.txt:180 (message):
  sqlite3 >= 3.11 required!

when PROJ is a subdirectory

and I get the correct thing:

-- Found Sqlite3: /home/user/Documents/vcpkg/installed/x64-linux/debug/lib/libsqlite3.a
-- Sqlite3 version: 3.36.0

when I don’t use it as a sub-directory.

2

Answers


  1. Chosen as BEST ANSWER

    After fiddling around with this answer and wondering why it still wasn't working, I tried making an exact copy of the current MCVE in a different directory. To my surprise, it worked, and even worked with out caching (normal CMake command line variables). When using PROJ as a sub_directory, it actually only exposes PROJ as a target. However, I was trying to use PROJ::proj, a target apparently made by VCPKG to link against their install. Well I had uninstalled that, and wasn't using it as a dependency. Despite that, left over files in a separate build folder apparently were messing with my install, my directory originally looked like this:

    - CMakeLists.txt
    - main.cpp
    - external
        - PROJ 
    - cmake-build-debug
    - cmake-build-release
    

    Well, VCPKG stores some meta information about package caches and such in these directories. But with out completely deleting the whole directory I was not able to get it to "forget" about this old install. What's more, it took deleting both directories to get it to "fully" forget about proj.

    So I deleted these files, like this:

    - CMakeLists.txt
    - main.cpp
    - external
        - PROJ 
    

    And reset/reloaded the CMake cache and file, and re-generated those build directories.

    After doing this, I no longer had to worry about this extra target.


  2. After the first project() call, it is much too late for CMAKE_TOOLCHAIN_FILE to do anything useful. Indeed, it won’t even be read if it changes after the first project() call. Vcpkg, Conan, and the like must be used globally or not at all.

    You could get away with writing something like this:

    cmake_minimum_required(VERSION 3.21) # upgrade!! 3.13 is ancient
    
    # Use vcpkg by default
    if (EXISTS "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
      set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
          CACHE STRING "TEST")
      set(VCPKG_TARGET_TRIPLET "x64-linux"
          CACHE STRING "default vcpkg triplet")
    endif ()
    
    project(test)
    
    set(CMAKE_CXX_STANDARD 17
        CACHE STRING "C++ standard to use")
    
    if (CMAKE_CXX_STANDARD LESS 17)
      message(FATAL_ERROR "Must compile `test` with C++17 or newer")
    endif ()
    
    add_subdirectory(external/PROJ)
    add_executable(test main.cpp)
    target_link_libraries(test PRIVATE PROJ::proj)
    

    It is customary to set the environment variable VCPKG_ROOT to point to your vcpkg installation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search