[CMake] Shared library from ExternalProject

Tino Mettler tino.mettler at alcnetworx.de
Tue Sep 15 08:07:42 EDT 2015


Hi,

it would be nice to know if the usage of add_library(foo SHARED
IMPORTED) is the way to go in this case.

find_package() seems to be useless, as it requires that the external
library is already present when cmake is invoked, which is not the case
with an external project.

So it seems like I have to define everything via set_target_properies().

What I see is that cmake uses rpath for linking using gcc/binutils. Is
there a way to just use -L here? In the final installation (an embedded
device), the libraries will be placed in the standard search path of the
dynamic linker, so the rpath is just build system specific and not
needed for the resulting binary.

I also discovered that the build of the external project is not updated
when the filesystem timestamp as well as the contents of external.tar.gz
were changed. How can I achieve this?

Here is my minimized example:

cmake_minimum_required(VERSION 3.0.0)
project (hello)
add_executable(hello helloworld.cpp)
include(ExternalProject)
ExternalProject_Add(externalproject URL ../../../external.tar.gz)
ExternalProject_Get_Property(externalproject binary_dir)
add_library(externallib SHARED IMPORTED)
set_target_properties(externallib PROPERTIES IMPORTED_LOCATION ${binary_dir}/install/lib/${CMAKE_SHARED_LIBRARY_PREFIX}mylib${CMAKE_SHARED_LIBRARY_SUFFIX} )
include_directories(${binary_dir}/install/include/)
target_link_libraries(hello externallib)
add_dependencies(hello externalproject)

Regards,
Tino



More information about the CMake mailing list