<div dir="ltr"><span style="font-size:12.8px">> it would be nice to know if the usage of add_library(foo SHARED</span><br style="font-size:12.8px"><span style="font-size:12.8px">> IMPORTED) is the way to go in this case.</span><br><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I wouldn't think this is the way to go. One thing we love CMake for is that it separates the concerns of the library and the consumer target so it's best to stick to find_package.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">This is the usage pattern of ExternalProject with find_package:</span></div><div><span style="font-size:12.8px">Create a super project which contains the library and the consumer target in 2 separate ExternalProjects so the library can be installed before the main target's CMakeLists is configured.</span></div><div><br></div><div>In certain cases you can also clone, build and install the library in an init shell script of your project, outside of the main CMakeLists.txt. This can be achieved either in a separate CMakeLists.txt (e.g. ./dependencies/CMakeLists.txt) or by raw shell commands (calling curl, git, cmake, cmake --build directly)</div><div><br></div><div>Tamas</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 15, 2015 at 2:07 PM, Tino Mettler <span dir="ltr"><<a href="mailto:tino.mettler@alcnetworx.de" target="_blank">tino.mettler@alcnetworx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
it would be nice to know if the usage of add_library(foo SHARED<br>
IMPORTED) is the way to go in this case.<br>
<br>
find_package() seems to be useless, as it requires that the external<br>
library is already present when cmake is invoked, which is not the case<br>
with an external project.<br>
<br>
So it seems like I have to define everything via set_target_properies().<br>
<br>
What I see is that cmake uses rpath for linking using gcc/binutils. Is<br>
there a way to just use -L here? In the final installation (an embedded<br>
device), the libraries will be placed in the standard search path of the<br>
dynamic linker, so the rpath is just build system specific and not<br>
needed for the resulting binary.<br>
<br>
I also discovered that the build of the external project is not updated<br>
when the filesystem timestamp as well as the contents of external.tar.gz<br>
were changed. How can I achieve this?<br>
<br>
Here is my minimized example:<br>
<br>
cmake_minimum_required(VERSION 3.0.0)<br>
project (hello)<br>
add_executable(hello helloworld.cpp)<br>
include(ExternalProject)<br>
ExternalProject_Add(externalproject URL ../../../external.tar.gz)<br>
ExternalProject_Get_Property(externalproject binary_dir)<br>
add_library(externallib SHARED IMPORTED)<br>
set_target_properties(externallib PROPERTIES IMPORTED_LOCATION ${binary_dir}/install/lib/${CMAKE_SHARED_LIBRARY_PREFIX}mylib${CMAKE_SHARED_LIBRARY_SUFFIX} )<br>
include_directories(${binary_dir}/install/include/)<br>
target_link_libraries(hello externallib)<br>
add_dependencies(hello externalproject)<br>
<br>
Regards,<br>
Tino<br>
<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</blockquote></div><br></div>