3

The following command works for me well:

cmake ../ -DBoost_NO_BOOST_CMAKE=BOOL:ON

i.e., cmake ignores system BoostConfig.cmake, which is what I need. But if I try to do the same via an environment variable:

Boost_NO_BOOST_CMAKE=ON cmake ../

cmake still reads BoostConfig.cmake and I got the following error:

CMake Error at /usr/lib64/boost/BoostConfig.cmake:64 (get_target_property):

I've tried also setting to TRUE, BOOL:ON, etc. as well. Using cmake version 3.3.1. Any hint?

UPDATE

Adding

set(Boost_NO_BOOST_CMAKE TRUE)

into CMakeList.txt works well, but the same line added into PreLoad.cmake does not. In the second case, running cmake with trace and debug options gives the following first few log lines:

Configuring Debug su3-dense ...
Running with debug output on.
Running with trace output on.
/home/langr/projects/su3dense/PreLoad.cmake(1):  set(Boost_NO_BOOST_CMAKE TRUE )
/home/langr/projects/su3dense/CMakeLists.txt(1):  cmake_minimum_required(VERSION 3.0.0 )
...

So, the PreLoad.cmake file is apparently processed and the variable Boost_NO_BOOST_CMAKE is set. Why is this setting then ignored?

UPDATE 2

I finally got it working by writing

set(Boost_NO_BOOST_CMAKE TRUE CACHE BOOL "" FORCE)

into PreLoad.cmake.

Daniel Langr
  • 22,196
  • 3
  • 50
  • 93
  • If I look at the [`FindBoost.cmake`](https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake#L231) source code this check is not meant for environment variables, but for `Boost_NO_BOOST_CMAKE` CMake variable only. Can you please give a reference for why this should work with an environment variable? Your first `-D` call seems to be the valid solution. – Florian Mar 02 '16 at 15:00
  • @Florian: In fact I cannot, I'm new to cmake and thought it considers environment variables for all internal variables automatically. My first `-D` call is a valid solution, but unfortunately it requires me to change some build script being a part of a Git project. Setting an environment variable in my `.bashrc` would be a much more elegant solution here. – Daniel Langr Mar 02 '16 at 15:59
  • Could one of the solutions I've posted in my answer [here](http://stackoverflow.com/questions/33758798/using-constant-folder-with-cmake/33790663#33790663) be feasible? You could e.g. extend your main `CMakeLists.txt` to transfer the content of the environment variable into a CMake cached variable. Or if you don't want to change your `CMakeLists.txt` you could put the code into `PreLoad.cmake` (for details see [here](http://stackoverflow.com/questions/30503631/cmake-in-which-order-are-files-parsed-cache-toolchain)). – Florian Mar 02 '16 at 16:24
  • @Florian: I've tried the `PreLoad.cmake` solution but it does not work for me. Please, see the updated question. – Daniel Langr Mar 08 '16 at 07:32

2 Answers2

0

Creating a PreLoad.cmake file with the following contents finally works for me:

set(Boost_NO_BOOST_CMAKE TRUE CACHE BOOL "" FORCE)

Thanks Florian for help.

Daniel Langr
  • 22,196
  • 3
  • 50
  • 93
  • You're welcome. And I appologize that I forgot to mention the scope of `PreLoad.cmake`. Since it's not included in your main `CMakeLists.txt` but rather loaded before your main `CMakeLists.txt`, all variables set in `PreLoad.cmake` have to be cached variables - if they should also be visible in your main `CMakeLists.txt`. – Florian Mar 10 '16 at 21:06
0

I had a very similar problem but with a different cause and solution.

In my case CMake ignored Boost_NO_BOOST_CMAKE because I used the full signature of find_package in which config mode is used.

This did NOT work:

set(Boost_NO_BOOST_CMAKE ON)
find_package(BOOST_LIB 1.66 NAMES Boost REQUIRED)  # full signature

This did work:

set(Boost_NO_BOOST_CMAKE ON)
find_package(Boost 1.66 REQUIRED)  # basic signature
Simpl
  • 1,938
  • 1
  • 10
  • 21