user3041202
user3041202

Reputation: 533

cmake set subdirectory options

Is there anyway to set the options of a subdirectory?

So I have a project that depends on a subproject, the subproject has an option:

OPTION(WITH_FUNCTION_X "enable X functionality" ON)

And in my parent project I want to include the subproject, but without functionality X.

thanks!

Upvotes: 53

Views: 29478

Answers (1)

ComicSansMS
ComicSansMS

Reputation: 54589

CMake's option command more or less adds a boolean variable to the cache.

If you want to override the default value of an option, simply add a variable of the same name to the cache yourself before pulling in the subproject:

set(WITH_FUNCTION_X OFF CACHE BOOL "enable X functionality")
add_subdirectory(subproject)

Note that the set command does nothing if there is already a value of that name in the cache. If you want to overwrite any existing value, add the FORCE option to that command.

Sample with FORCE

set(WITH_FUNCTION_X OFF CACHE BOOL "enable X functionality" FORCE)
add_subdirectory(subproject)

Upvotes: 59

Related Questions