[CMake] Consuming results of ExternalProject_Add

Andrey Pokrovskiy wonder.mice at gmail.com
Tue Feb 17 17:52:13 EST 2015


Thanks for your reply, Jean-Christophe.

I don't see how External_OpenSSL.cmake is used in Slicer (probably
some weird scheme is involved).
But from what I see, it supposed to be used like that:

  include(External_OpenSSL)
  add_executable(my_executable main.cpp ...)
  target_include_directories(my_executable ${OPENSSL_INCLUDE_DIR})
  target_link_libraries(my_executable ${OPENSSL_LIBRARIES})

That means that I will need to include External_OpenSSL in every
CMakeLists.txt that uses OpenSSL. That doesn't sounds right to me.

And if not, then something adds OPENSSL_INCLUDE_DIR and
OPENSSL_LIBRARIES to CACHE which is also doesn't sounds right.

Also this will not setup build dependency between target and OpenSSL.
I know, I could use additional add_dependencies() for that, but that's
clumsy. 3 lines instead of just:

  target_link_libraries(my_executable crypto ssl)

CMake already has a concept of "libraries" (added with add_library).
There should be a way of saying "Hey, this static library comes from
that external project. It also requires such and such include
directories".

On Tue, Feb 17, 2015 at 1:53 PM, Jean-Christophe Fillion-Robin
<jchris.fillionr at kitware.com> wrote:
> Hi Andrey,
>
> Since there is already a FindOpenSSL.cmake module [1], configuring the
> consumer project with the variable expected by the FindOpenSSL.cmake module
> is the easiest.
>
> See
> https://github.com/Slicer/Slicer/blob/ee84fba523d85be3539bf8c83c8eb73d4f59cfff/SuperBuild/External_OpenSSL.cmake#L231-L239
>
>
> [1] https://github.com/Kitware/CMake/blob/master/Modules/FindOpenSSL.cmake
>
> Hth
> Jc
>
> On Tue, Feb 17, 2015 at 3:27 PM, Andrey Pokrovskiy <wonder.mice at gmail.com>
> wrote:
>>
>> Hi,
>>
>> I'm using ExternalProject_Add() to build OpenSLL library. After
>> install step I have following artifacts available:
>> * libcrypto.a
>> * libssl.a
>> * include/openssl/*.h
>>
>> I wonder, what is the "canonical" way to make those artifacts
>> available for other targets in the project?
>>
>> FindPackage style thing with OPENSSL_LIBRARIES and OPENSSL_INCLUDE_DIR
>> variables will not work, because OpenSSL target and executable that
>> uses it are on the same level (I think using CACHE to propagate
>> variable value up is a dirty hack):
>> * src/openssl/CMakeLists.txt
>> * src/my_executable/CMakeLists.txt
>>
>> Ideally I would like to use add_library() with
>> target_include_directories() and
>> target_link_libraries(). But the only way to do that is to use
>> IMPORTED libraries, like that:
>>
>> add_library(crypto STATIC IMPORTED GLOBAL)
>> add_dependencies(crypto openssl_external_project)
>> set_property(TARGET crypto PROPERTY INTERFACE_LINK_LIBRARIES
>> ${OPENSSL_PREFIX}/lib/libcrypto.a)
>> set_property(TARGET crypto PROPERTY INTERFACE_INCLUDE_DIRECTORIES
>> ${OPENSSL_PREFIX}/include)
>>
>> But then I get an error:
>> $ cmake ..
>>
>> CMake Error in src/my_executable/CMakeLists.txt:
>>
>>   Imported target "crypto" includes non-existent path
>>
>>  "<...>/build.dir/src/openssl/openssl-1.0.2.install/include"
>>
>> Obviously, that happens because include directory was not created yet
>> (it will after make).
>>
>> I understand that from general CMake standpoint - IMPORTED libraries
>> are something that already exists and not part of the build. But then
>> I don't understand how this ExternalProject_Add thing is supposed to
>> be used.
>>
>> Any ideas what I'm doing wrong?
>> --
>>
>> 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:
>> http://public.kitware.com/mailman/listinfo/cmake
>
>
>
>
> --
> +1 919 869 8849


More information about the CMake mailing list