CMake (version 3.5.2) surprised me with how it's passing values to
sub-projects, so I was wondering if this is expected behavior. Here's an
example of what I mean. Let's say I have a project Foo in a directory of
the same name. It contains a third-party library called Bar which has a
CMakeLists.txt file that looks like:
cmake_minimum_required(VERSION 2.8.12)
option(OPT1
"Set to OFF|ON (default is OFF) to control build of Bar library" OFF)
if(OPT1)
message("Bar: OPT1 is on")
else(OPT1)
message("Bar: OPT1 is off")
endif(OPT1)
I then create CMakeLists.txt for Foo that sets OPT1 to ON and includes Bar:
cmake_minimum_required(VERSION 2.8.12)
set(OPT1 ON FORCE)
if(OPT1)
message("Foo: OPT1 is on")
else(OPT1)
message("Foo: OPT1 is off")
endif(OPT1)
add_subdirectory(Bar)
The first time I run cmake the message output is:
Foo: OPT1 is on
Bar: OPT1 is off
If I run cmake again, I get:
Foo: OPT1 is on
Bar: OPT1 is on
If this is expected behavior, is there any way I can ensure Bar receives
the value of OPT1 the first time? It makes a huge difference when the
option controls, for example, whether a static or dynamic library will be
built.
Thanks,
Doug
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake