How can I automatically optionally build a submodule?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I automatically optionally build a submodule?

Steve Keller
How can I build a module in a subdirectory automatically if a required
package is available, but not fail if it's not. Say I have a
top-level CMakeLists.txt with

    add_subdirectory(foo)
    add_subdirectory(bar)

and in directory foo I have in CMakeLists.txt

    find_package(yadda, REQUIRED)

I want the submodule foo to be build automatically if the package
yadda is found. Otherwise, foo should be left out and the top-level
build should not fail but continue.

Steve
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How can I automatically optionally build a submodule?

Albrecht Schlosser
On 12.03.2019 06:37 Steve Keller wrote:

> How can I build a module in a subdirectory automatically if a required
> package is available, but not fail if it's not. Say I have a
> top-level CMakeLists.txt with
>
>      add_subdirectory(foo)
>      add_subdirectory(bar)
>
> and in directory foo I have in CMakeLists.txt
>
>      find_package(yadda, REQUIRED)
>
> I want the submodule foo to be build automatically if the package
> yadda is found. Otherwise, foo should be left out and the top-level
> build should not fail but continue.

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.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How can I automatically optionally build a submodule?

Simon Richter
In reply to this post by Steve Keller
Hi,

On 12.03.19 06:37, Steve Keller wrote:

> How can I build a module in a subdirectory automatically if a required
> package is available, but not fail if it's not. Say I have a
> top-level CMakeLists.txt with

With my Debian Developer hat on: please also add a mechanism to manually
specify whether the optional component should be built. If the
dependency changes and suddenly a component goes missing without
triggering a build failure, that can be rather annoying for users.

Without a package system, this also means that old files may stick
around after installation, so your program should be aware that
installed plugins could be built against an older API and weren't
updated during the last install run.

   Simon


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How can I automatically optionally build a submodule?

Steve Keller
In reply to this post by Albrecht Schlosser
"Albrecht Schlosser" <[hidden email]> 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
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How can I automatically optionally build a submodule?

Steve Keller
In reply to this post by Simon Richter
"Simon Richter" <[hidden email]> wrote:

> With my Debian Developer hat on: please also add a mechanism to manually
> specify whether the optional component should be built. If the
> dependency changes and suddenly a component goes missing without
> triggering a build failure, that can be rather annoying for users.
>
> Without a package system, this also means that old files may stick
> around after installation, so your program should be aware that
> installed plugins could be built against an older API and weren't
> updated during the last install run.

I'd like to do that if I'd know how to achieve that using cmake.  But I find
cmake is much too large and is incapable of many things I'd expect from
a build system tool.  It also makes development ugly for the Unix accustomed
developer, only to make things portable to Windows, which I don't want anyway.

Currently, we have a shell script wrapper around cmake that does something like

    if [ <dependencies for foo available> ]; then
        BUILD_FOO=true
    else
        BUILD_FOO=false
    fi

and in CMakeLists.txt

    set(BUILD_FOO "true" CACHE BOOL "description")
    ...
    if (BUILD_FOO)
        add_subdirectory(foo)
    endif()

This is *ugly* but I don't know how to do this in cmake.

Steve
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How can I automatically optionally build a submodule?

Andreas Naumann
In reply to this post by Steve Keller
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" <[hidden email]> 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


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake