[CMake] Problems loading and using external library

Gagnon, Joseph - 0553 - MITLL Joseph.Gagnon at ll.mit.edu
Wed Jul 1 12:54:25 EDT 2015


Let me describe the situation a little.  I have a small C++ project with the
source files distributed within a small directory hierarchy.  I am using
JetBrains CLion as the development IDE on a Linux (CentOS 6.6) platform.
CLion bundles CMake 3.2.2 in its distribution.  I have successfully built
the project and produced a static library (.a) file.  For identification
purposes, let's call this project LLXCC.

 

Now, I've created a separate project that will implement unit tests using
Google Test.  Let's call this project LLXCC_TEST.  I have set up the test
project to build with CMake as well.  I was not sure of the correct way to
make the header files and library file for the project described above
(LLXCC) available to the test project.  I finally came up with something
that CMake does not complain about, but I'm not sure if it's really the
right way to do it.  Below is what I am doing in the master CMakeLists.txt
of the test project:

 

The intent here is to import the project that will be tested.  The
set_target_properties call sets the path to the libLLXCC.a file.

 

# Add LLXCC.

add_library(LLXCC STATIC IMPORTED)

set_target_properties(LLXCC PROPERTIES IMPORTED_LOCATION
$ENV{HOME}/ClionProjects/llxcc/build/debug/Debug)

 

Adding the path to the project's header files root path.

 

# Add external include paths.

include_directories($ENV{HOME}/ClionProjects/llxcc)

 

Later, after adding the text executable (via add_executable), I provide the
LLXCC library for linking.

 

target_link_libraries(LLXCC_TEST LLXCC)

 

The problem I'm running into is that the compiler cannot find one of the
header files being included in the project being tested - LLXCC.  So, to be
clear, this is not an issue including a header file in one of the source
files in LLXCC_TEST, but in LLXCC which has already been built and provided
to LLXCC_TEST via a library file.

 

My first guess is that I'm missing some configuration in the CMakeLists.txt
file that resolves the include path problem in LLXCC.  The LLXCC project
compiles, links and builds just fine.  I shouldn't have to change how
headers are included in the LLXCC project just to make the LLXCC_TEST build
happy.

 

Should the LLXCC project be "packaged" in some way so that it can be
"imported" or referenced by LLXCC_TEST in a better way?  Is there a
different way to make LLXCC available (both header files and library files)
to LLXCC_TEST?  Although there seems to be a lot of information that can be
found regarding CMake, it is still difficult to find information for topics
that seem to be pretty basic and important.  I am open to any suggestions.

 

Thanks,

Joe Gagnon

 

Engineer II

Group 53 - Secure Resilient Systems and Technology

MIT Lincoln Laboratory

Lexington, MA

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150701/76e0633b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5625 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150701/76e0633b/attachment.bin>


More information about the CMake mailing list