Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override option in CMake subproject

I'm trying to reuse the CMakeLists.txt of a third-party project whose source I don't want to change (expat, to be exact). I've added the project as a subproject of the top level using add_subdirectory.

This works but now I would like to set the value of some of the subproject's options in the top level CMakeLists.txt. How do I do this?

like image 452
thehouse Avatar asked Dec 27 '12 21:12

thehouse


3 Answers

See the similar question with a good answer.

Answer in short:

SET(SOME_EXPAT_OPTION OFF CACHE BOOL "Use some expat option")
like image 73
ronkot Avatar answered Oct 19 '22 07:10

ronkot


If the sub-project uses option (not set) for its configuration settings, then you can specify values using option before adding the subdirectory:

option(LIB_OPTION1 "" OFF)
option(LIB_OPTION2 "" ON)
add_subdirectory(${CMAKE_SOURCE_DIRECTORY}/lib)
like image 43
Drew Noakes Avatar answered Oct 19 '22 05:10

Drew Noakes


You can define the options with the desired settings (ON or OFF) before calling ADD_SUBDIRECTORY. This will then take precedence over the OPTION commands in expat's CMakeLists.txt since the last parameter to OPTION is only a default value (which is neglected if that settings already exists).

like image 7
Johannes S. Avatar answered Oct 19 '22 07:10

Johannes S.