[CMake] ExternalProject with target_link_library produces incorrect linking?

J. Caleb Wherry calebwherry at gmail.com
Tue Dec 9 12:26:01 EST 2014


Let's try again...

I submitted a question last week but got no responses so I have assumed my
question and/or example was not explicit enough. I have stripped out all
unnecessary structure from the code and am posing the question better (I
hope)...

The functionality that I am using is expressed in this old bug:
http://public.kitware.com/Bug/view.php?id=10395. I am adding dependencies
in my project based on an imported library which is built by
ExternalProject_add. Everything works but the linking is not as I would
expect. I add my imported library like so (see code for ExternalProject_add
statement):

add_library(ExtLib SHARED IMPORTED)
set_property(TARGET ExtLib PROPERTY IMPORTED_LOCATION
"${CMAKE_BINARY_DIR}/${EXT_LIB_NAME}")
add_dependencies(ExtLib ExtLibBuild)

I then link against this in my binary like so:

add_executable(testApp testApp.cpp)
target_link_libraries(testApp LINK_PUBLIC TestLib ExtLib)

However, when I do this, the binray that comes out has a relative path to
the 'ExtLib' which means I can only run it from the directory CMake builds
it in. When I change the linking to be the below with the full path to
ExtLib, it works just fine and I can run it from anywhere:

target_link_libraries(testApp LINK_PUBLIC TestLib
"${CMAKE_BINARY_DIR}/${EXT_LIB_NAME}")

I gave the full path to the imported library in the
"set_property..IMPORTED_LOCATION..." so I am unsure why the first one does
not work?

In this previous post from Brad in 2010 (
http://www.cmake.org/pipermail/cmake/2010-September/039639.html), it seems
that the first way should work like I want, correct?

A few other notes:
* I have my RPATH properties set which has been a factor in getting this to
work but I haven't tested enough to known which ones are actually helping
or not.
* The (more) SSCCE project is here:
https://github.com/calebwherry/cmake-SO-question-main.git
* I have also attached a tar'ed version.
* System specs: Debian Wheezy 64-bit, CMake 3.0.2, GCC 4.9.2.

Thanks,
Caleb

-- 
J. Caleb Wherry
*Scientific Software Engineer*

<http://www.calebwherry.com>
http://www.calebwherry.com
+1 (615) 708-5651
calebwherry at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141209/6655cba8/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmake-SO-question-main.tar.gz
Type: application/x-gzip
Size: 36550 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141209/6655cba8/attachment-0001.bin>


More information about the CMake mailing list