[CMake] Consuming results of ExternalProject_Add

Andrey Pokrovskiy wonder.mice at gmail.com
Tue Feb 17 15:27:23 EST 2015


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?


More information about the CMake mailing list