Poperton
Poperton

Reputation: 2148

How to disable a CMAKE option

On ${CMAKE_CURRENT_SOURCE_DIR}/JUCE, there is:

option(JUCE_BUILD_EXTRAS "Add build targets for the Projucer and other tools" OFF)

if(JUCE_BUILD_EXTRAS)
    add_subdirectory(extras)
endif()

link: https://github.com/juce-framework/JUCE/blob/master/CMakeLists.txt#L57

So this is what I did:

set(JUCE_BUILD_EXTRAS OFF)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/JUCE)

However it still tries to build extras. I'm on Android Studio.

What should I do?

I also tried set(JUCE_BUILD_EXTRAS OFF)

The default value is OFF and even then it tried to build.

I always get these errors when trying to disable something on Android CMAKE but it always fails

Upvotes: 2

Views: 5660

Answers (1)

Bitwize
Bitwize

Reputation: 11220

The easiest way to guarantee that this will be overridden correctly from a parent CMakeLists.txt is to set it as a CACHE variable with a FORCEd value:

set(JUCE_BUILD_EXTRAS OFF CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/JUCE)

This will ensure that any state that may already exist from a previous configuration of the project that defines the option will be overridden and picked up first.


Technically, the documentation for option states:

... If is already set as a normal or cache variable, then the command does nothing.

However, this is only true if there have been no prior configurations -- so this only works if the variable was set before the first configuration

In practice I've found that the FORCE-approach is much more reliable.

Upvotes: 4

Related Questions