[CMake] Do not build targets whose dependencies are not available

Chris Stankevitz chrisstankevitz at gmail.com
Thu Mar 28 16:02:55 EDT 2013


On Tue, Mar 19, 2013 at 3:13 AM, Ansis Māliņš <ansis.malins at gmail.com> wrote:
>>
>> Q: Can cmake automatically not build "b" when "a" is not available?
>
> find_package(a)
> if(a_FOUND)
>     ExternalProject_Add(b PREFIX blabla ...)
> endif()

Hello,

If I understand correctly, this is what just happened:

Chris: Is there a pretty solution to problem X?  An ugly solution is Y.

Ansis: Why don't you try Y?

I include solution Y below which I think is too ugly.  I hope there is
another solution that is not ugly.

Thank you,

Chris
==

ADD_LIBRARY(b b.cpp)
TARGET_LINK_LIBRARIES(b ${Boost_THREAD_LIBRARY})

ADD_LIBRARY(c c.cpp)
TARGET_LINK_LIBRARIES(c ${wxWidgets_LIBRARIES})

ADD_EXECUTABLE(App App.cpp)
TARGET_LINK_LIBRARIES(App b c d e f g)

===

To this:

IF(Boost_FOUND)
ADD_LIBRARY(b b.cpp)
TARGET_LINK_LIBRARIES(b ${Boost_THREAD_LIBRARY})
SET(b_FOUND 1)
ENDIF()

IF(wxWIDGETS_FOUND)
ADD_LIBRARY(c c.cpp)
TARGET_LINK_LIBRARIES(c ${wxWidgets_LIBRARIES})
SET(c_FOUND 1)
ENDIF()

IF(b_FOUND)
IF(c_FOUND)
IF(d_FOUND)
IF(e_FOUND)
IF(f_FOUND)
IF(g_FOUND)
ADD_EXECUTABLE(App App.cpp)
TARGET_LINK_LIBRARIES(App b c d e f g)
SET(App_FOUND 1)
ENDIF()
ENDIF()
ENDIF()
ENDIF()
ENDIF()
ENDIF()

>>
>> I hope the answer is "yes" otherwise I will have to add IF(HAVE_A)
>> code throughout my CMakeLists.txt file.  Worse, in my complex file I
>> will have to add lots of IF(HAVE_C), IF(HAVE_D) etc.
>>
>> Thank you,
>>
>> Chris
>> --
>>
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>


More information about the CMake mailing list