[CMake] How can I automatically optionally build a submodule?

Andreas Naumann Andreas-Naumann at gmx.net
Wed Mar 27 15:45:30 EDT 2019


For me, this sounds more like foo is an independent thing and not a
subdirectory.

In this case, I think about two solutions:
     1) Use a macro/function "check_yada", which sets a variable
"yada_usable". If you extract this logic in an extra .cmake file, you
can reuse it in your yada CMakelists.txt
     2) Use foo as an external project. But thats looks like a major
change in the project structure.


Am 27.03.19 um 20:05 schrieb Steve Keller:
> "Albrecht Schlosser" <AlbrechtS.fltk at online.de> wrote:
>
>> If you want yadda to be optional then don't use REQUIRED.
>>
>> find_package(yadda)
>> if (yadda_FOUND)
>>     message(STATUS "found yadda, building bar ...")
>>
>>     # add your code to build bar here
>>
>> endif ()
>>
>> This should do what you want - unless I misunderstood your question.
> This will roughly do what I want, but I think it does not correctly
> express things.  For the sub-project, yadda is not optional, and if I
> call cmake in that sub-project's directory, it should fail.
>
> What I think would be appropriate would be a command
> add_subdirectory_optional(...) or add_subdirectory_and_ignore_errors(...)
> or something similar.
>
> Steve




More information about the CMake mailing list