Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake set subdirectory options

Tags:

cmake

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!

like image 656
user3041202 Avatar asked Nov 27 '13 10:11

user3041202


1 Answers

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) 
like image 68
ComicSansMS Avatar answered Sep 19 '22 16:09

ComicSansMS