Re: [CMake] Faking a library

2013-10-19 Thread Magnus Therning
On Wed, Oct 16, 2013 at 11:36:53PM +0200, Alexander Neundorf wrote:
 On Wednesday 16 October 2013, Magnus Therning wrote:
 When defining a library via add_library() it's possible to link
 against it by just putting its name into target_link_libraries().
 Is there some way of wrapping up an external library in a similar
 way?
 
 As a concrete example I'm playing around with gtest[1] via
 externalproject_add() like this:
 
 externalproject_add(gtest
 SOURCE_DIR ${PROJECT_SOURCE_DIR}/gtest
 BINARY_DIR gtest-build
 INSTALL_COMMAND  # omit installation
 )
 
 Then to link to it I need to use
 
 target_link_libraries(test
 -L${CMAKE_BINARY_DIR}/gtest-build -lgtest -lpthread
 )
 
 Is there some way to wrap that all up in a target that I can pass
 straight to target_link_libraries()?
 
 Or is my only option to create a variable that expands to those
 compiler flags?
 
 You may create an imported target, and set some properties on it:
 
 add_library(gtest STATIC IMPORTED)
 set_target_properties(gtest PROPERTIES
  IMPORTED_LOCATION  ${CMAKE_BINARY_DIR}/libgtest-build.a)
 
 You may need to set a few more properties like
 IMPORTED_LINK_INTERFACE_LIBRARIES, and you may want to use
 ${CMAKE_STATIC_LIBRARY_PREFIX}libgtest-build.${CMAKE_STATIC_LIBRARY_SUFFIX}
 instead of hardcoding lib and a.

Thanks, it works to add the following:

add_library(gtest STATIC IMPORTED)
set_target_properties(gtest PROPERTIES
IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/gtest-build/libgtest.a
IMPORTED_LINK_INTERFACE_LIBRARIES -lpthread
)

Now the only thing remaining is that all targets using this lib also
needs to find its header files.  At the moment I'm defining a variable
for it:

set(GTEST_INCDIR ${PROJECT_SOURCE_DIR}/gtest/include)

and then I need to put that into a target_include_directories(), e.g.:

target_include_directories(test_one PRIVATE
${GTEST_INCDIR}
...
)

Is it possible to put the include path in some property on the library
as well, to avoid using a separate variable for that?

If there's no standard property for it, would it be possible to use a
custom one, say INC_DIR, and then use the generator
$TARGET_PROPERTY:gtest,INC_DIR to extract it?  (I'm at all sure I've
understood generators though ;-)

/M

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

The right to search for truth implies also a duty; one must not
conceal any part of what one has recognized to be true.
 -- Albert Einstein


pgpeWUwWcJotf.pgp
Description: PGP signature
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Faking a library

2013-10-19 Thread Игорь Пашев
2013/10/19 Magnus Therning mag...@therning.org:
 Is it possible to put the include path in some property on the library
 as well, to avoid using a separate variable for that?

SET_TARGET_PROPERTIES (target PROPERTIES VARIABLE-NAME VARIABLE-VALUE)
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Faking a library

2013-10-19 Thread Magnus Therning
On Sat, Oct 19, 2013 at 11:28:53AM +0400, Игорь Пашев wrote:
 2013/10/19 Magnus Therning mag...@therning.org:
  Is it possible to put the include path in some property on the library
  as well, to avoid using a separate variable for that?
 
 SET_TARGET_PROPERTIES (target PROPERTIES VARIABLE-NAME VARIABLE-VALUE)

Of course, but then how do I use it conveniently?

Would it be possible, by choosing a good property name, to simply do

target_include_directories(one_test PRIVATE
target
)

Or would I have to

get_target_property(INC_DIR target variable-name)
target_include_directories(one_test PRIVATE
${INC_DIR}
)

in which case using a property wouldn't give me very much.

/M

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

The British have the perfect temperament to be hackers--technically
skilled, slightly disrespectful of authority, and just a touch of
criminal behavior.
 -- Mary Ann Davidson, Oracle's Security Chief


pgpq1S3NF1_dR.pgp
Description: PGP signature
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Faking a library

2013-10-19 Thread Nick Hutchinson
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.

Nick


On 19 October 2013 08:59, Magnus Therning mag...@therning.org wrote:

 On Sat, Oct 19, 2013 at 11:28:53AM +0400, Игорь Пашев wrote:
  2013/10/19 Magnus Therning mag...@therning.org:
   Is it possible to put the include path in some property on the library
   as well, to avoid using a separate variable for that?
 
  SET_TARGET_PROPERTIES (target PROPERTIES VARIABLE-NAME
 VARIABLE-VALUE)

 Of course, but then how do I use it conveniently?

 Would it be possible, by choosing a good property name, to simply do

 target_include_directories(one_test PRIVATE
 target
 )

 Or would I have to

 get_target_property(INC_DIR target variable-name)
 target_include_directories(one_test PRIVATE
 ${INC_DIR}
 )

 in which case using a property wouldn't give me very much.

 /M

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

 The British have the perfect temperament to be hackers--technically
 skilled, slightly disrespectful of authority, and just a touch of
 criminal behavior.
  -- Mary Ann Davidson, Oracle's Security Chief

 --

 Powered by www.kitware.com

 Please keep messages on-topic and check the CMake FAQ at:
 http://www.cmake.org/Wiki/CMake_FAQ

 Kitware offers various services to support the CMake community. For more
 information on each offering, please visit:

 CMake Support: http://cmake.org/cmake/help/support.html
 CMake Consulting: http://cmake.org/cmake/help/consulting.html
 CMake Training Courses: http://cmake.org/cmake/help/training.html

 Visit other Kitware open-source projects at
 http://www.kitware.com/opensource/opensource.html

 Follow this link to subscribe/unsubscribe:
 http://www.cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Faking a library

2013-10-19 Thread Alexander Neundorf
On Saturday 19 October 2013, you wrote:
 On Sat, Oct 19, 2013 at 11:28:53AM +0400, Игорь Пашев wrote:
  2013/10/19 Magnus Therning mag...@therning.org:
   Is it possible to put the include path in some property on the library
   as well, to avoid using a separate variable for that?
  
  SET_TARGET_PROPERTIES (target PROPERTIES VARIABLE-NAME
  VARIABLE-VALUE)
 
 Of course, but then how do I use it conveniently?
 
 Would it be possible, by choosing a good property name, to simply do
 
 target_include_directories(one_test PRIVATE
 target
 )
 
 Or would I have to
 
 get_target_property(INC_DIR target variable-name)
 target_include_directories(one_test PRIVATE
 ${INC_DIR}
 )
 
 in which case using a property wouldn't give me very much.

This depends on which version of cmake you are using.
If you require a very recent one, i.e. 2.8.11 or newer, you can set 
INTERFACE_INCLUDE_DIRECTORIES, and then you'll get the include dirs 
automatically when linking against the target, I think.

Alex
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Faking a library

2013-10-19 Thread Magnus Therning
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: mag...@therning.org   jabber: mag...@therning.org
twitter: magthe   http://therning.org/magnus

The early bird may get the worm, but the second mouse gets the cheese.


pgp62eZTeKd5C.pgp
Description: PGP signature
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Faking a library

2013-10-16 Thread Alexander Neundorf
On Wednesday 16 October 2013, Magnus Therning wrote:
 When defining a library via add_library() it's possible to link
 against it by just putting its name into target_link_libraries().  Is
 there some way of wrapping up an external library in a similar way?
 
 As a concrete example I'm playing around with gtest[1] via
 externalproject_add() like this:
 
 externalproject_add(gtest
 SOURCE_DIR ${PROJECT_SOURCE_DIR}/gtest
 BINARY_DIR gtest-build
 INSTALL_COMMAND  # omit installation
 )
 
 Then to link to it I need to use
 
 target_link_libraries(test
 -L${CMAKE_BINARY_DIR}/gtest-build -lgtest -lpthread
 )
 
 Is there some way to wrap that all up in a target that I can pass
 straight to target_link_libraries()?
 
 Or is my only option to create a variable that expands to those
 compiler flags?

You may create an imported target, and set some properties on it:

add_library(gtest STATIC IMPORTED)
set_target_properties(gtest PROPERTIES
 IMPORTED_LOCATION  ${CMAKE_BINARY_DIR}/libgtest-build.a)

You may need to set a few more properties like 
IMPORTED_LINK_INTERFACE_LIBRARIES, and you may want to use 
${CMAKE_STATIC_LIBRARY_PREFIX}libgtest-build.${CMAKE_STATIC_LIBRARY_SUFFIX}
instead of hardcoding lib and a.

Alex

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake