3

I have a chicken-and-egg situation. I am using vcpkg, which requires me to set a cmake toolchain file from the command line. But I also have some cmake_policy statements which need to be set in CMakeLists.txt prior to the toolchain file.

Here is how cmake is called:

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-linux ..

But the projects uses some packages which requires the following two policies immediately after CMAKE_MINIMUM_REQUIRED:

CMAKE_POLICY ( SET CMP0003 NEW ) # libs linked via full path
CMAKE_POLICY ( SET CMP0011 NEW ) # push/pop instead of no_policy_scope

My question: Is there a way to specify the toolchain from within CMakeLists.txt -- presumably immediately after having set the two cmake policies -- instead of at the command line?

The warning I get which I'd like to solve is this one:

CMake Warning (dev) at vcpkg/scripts/buildsystems/vcpkg.cmake:221 (_add_executable):
  Policy CMP0003 should be set before this line.  Add code such as
    if(COMMAND cmake_policy)
      cmake_policy(SET CMP0003 NEW)
    endif(COMMAND cmake_policy)
Stéphane
  • 19,459
  • 24
  • 95
  • 136

1 Answers1

7

You should be able to set the policies from the command line as well:

cmake -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_POLICY_DEFAULT_CMP0003=NEW \
      -DCMAKE_POLICY_DEFAULT_CMP0011=NEW \
      -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake \
      -DVCPKG_TARGET_TRIPLET=x64-linux \
      ..

See How do I set CMake policy and property on an external project added using ExternalProject_Add