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

Steve Keller keller.steve at gmx.de
Wed Mar 27 15:05:47 EDT 2019


"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