[CMake] Faking a library

Magnus Therning magnus at therning.org
Sat Oct 19 15:41:44 EDT 2013


On Sat, Oct 19, 2013 at 08:11:52PM +0100, Nick Hutchinson wrote:
> As of 2.8.12, you can set target properties on an imported library
> to specify its include directories, compile options etc, and these
> will be automatically propagated to any other target that links to
> it via target_link_libraries(). No more tedious faffing about with
> global variables like GTEST_INCLUDE_DIRS, GTEST_LIBRARIES etc. It's
> really quite nice.
> 
> Check the 2.8.12 CMake docs for target properties that start with
> "INTERFACE".

That's very nice indeed :)

My complete configuration for the external library is now

~~~~
externalproject_add(gtest-external
    SOURCE_DIR ${PROJECT_SOURCE_DIR}/gtest
    BINARY_DIR gtest-build
    INSTALL_COMMAND "" # omit installation
    )
add_library(gtest STATIC IMPORTED)
set_target_properties(gtest PROPERTIES
    IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/gtest-build/libgtest.a
    IMPORTED_LINK_INTERFACE_LIBRARIES -lpthread
    INTERFACE_INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/gtest/include
    )
~~~~

And all I need a user of the library to do is

~~~~
target_link_libraries(one_test gtest)
~~~~

Sweet!

Thanks for all the help.

/M

-- 
Magnus Therning                      OpenPGP: 0xAB4DFBA4 
email: magnus at therning.org   jabber: magnus at therning.org
twitter: magthe               http://therning.org/magnus

The early bird may get the worm, but the second mouse gets the cheese.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20131019/f8491215/attachment.pgp>


More information about the CMake mailing list