[CMake] What is the best way to *export* the transitive dependencies of a library?
Say the executable Exe uses some static library Foo which uses other libraries, e. g. Bar: Exe --> Foo --> Bar As the developer of Foo and I want to make it easy to link against: find_package(Foo REQUIRED) target_link_libraries(Exe PRIVATE Foo) The problem lies with the various dependencies of Foo necessary to use it: definitions, include directories, libraries. The Foo is a complex multimedia-processing library with a wide range of configuration options, so there is a reason why a lot of information may be necessary to use it in another project. The official (and quite neat) way to prepare a configuration module (FooConfig.cmake) is to use install/export commands: install(TARGETS Foo EXPORT FooExport DESTINATION lib) install(EXPORT FooExport DESTINATION lib/cmake/Foo FILE FooConfig.cmake) That, however does not export transitive properties of the target. If, for example there was some Bar dependency: find_package(Bar REQUIRED) target_link_libraries(Foo PUBLIC Bar) Then it will indeed use INTERFACE_xxx properties of Bar while building Foo. But FooConfig.cmake will only list a lone Bar dependency in the INTERFACE_LINK_LIBRARIES property of an imported Foo target: add_library(Foo STATIC IMPORTED) set_target_properties(Foo PROPERTIES ... INTERFACE_LINK_LIBRARIES "...;Bar") Which, obviously, is not enough to link against the Foo target in another project. This behavior is mentioned a bit in CMake documentation: "Note that it is not advisable to populate the INTERFACE_LINK_LIBRARIES of a target with paths for dependencies. That would hard-code into installed packages the include directory paths for dependencies as found on the machine the package was made on." Which is probably the reason why CMake does not export interface part of dependencies itself. But I do not see any way around it. By not including transitive dependencies in configuration module, the responsibility to search for those dependencies is shifted to the Exe project. But Exe cannot know which dependencies were enabled during particular Foo's configuration or where to search for them. Is this a bug? I'd expect there to be at least an option to include transitive dependencies during the export. There is EXPORT_LINK_INTERFACE_LIBRARIES option but it uses deprecated properties and has no visible effect. Or am I missing something here? What is the proper way to go around this issue? It is not hard to come up with a workaround, in fact. It should be enough to populate the INTERFACE_xxx (COMPILE_DEFINITIONS, INCLUDE_DIRECTORIES, LINK_LIBRARIES, maybe SYSTEM_INCLUDE_DIRECTORIES as well) properties of Foo with contents of respective INTERFACE_xxx properties of all Foo's dependencies. That, however, will require to include a rather noticeable piece of homebrew (and somewhat obscure) code to every project trying to export imported dependencies. Not elegant, will probably break in some corner case and hard to sell while advertising CMake to collegues. -- 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://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] gathering directory names in cmake
Alas, this has no effect. Consider the following shell script: - #!/bin/sh if [ -d attempt ] ; then rm -rf attempt ; fi mkdir attempt cd attempt for d in src src/app src/plugins/one ; do mkdir -p $d/xyz touch $d/xyz/one.txt touch $d/xyz/two.txt done PATTERN="\${CMAKE_SOURCE_DIR}/src/*xyz/" cat > CMakeLists.txt I have a source tree which contains multiple directories each of which has >a subdirectory called "xyz". I want to create a target that creates a zip >file with each of the xyz directories. So if the source tree looks like > src > src/xyz >src/application >src/application/xyz >src/plugins/one/xyz > >I want to end up with a zip file containing: >src/xyz/* >src/application/xyz/* >src/plugins/one/xyz/* > >On unix I could just generate the list of these directories with: > find src -type d -name test -print >alas, I need a cross-platform way to do this. > >I tried: > file(GLOB_RECURSE XYZFILES "${CMAKE_SOURCE_DIR}/src/*xyz) >and got nothing. > >At the moment, it looks like I cannot wildcard any portion of the >directory path. The following: > file(GLOB_RECURSE XYZFILES "${CMAKE_SOURCE_DIR}/src/*xyz*") > what about adding a backslash at end of expression ? file(GLOB_RECURSE XYZFILES "${CMAKE_SOURCE_DIR}/src/*xyz/") seems to only produce files which have xyz in their name. > >Lee >-- > -- Regards, Rashad -- 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://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] CXX_STANDARD and -std=c++14
At the risk of repeating myself... it's a non-intuitive "gotcha" that set_property(TARGET target PROPERTY CXX_STANDARD 14) results in something OTHER than the C++14 standard. The issue is likely to continue tripping people up, resulting in continued posts to this email list. If you want C++14 with GNU extensions, you should have to do something like: set_property(TARGET target PROPERTY CXX_STANDARD GNU14) which would throw an error if you try it with any non-GNU compiler. -- Elizabeth On Thu, Jun 23, 2016 at 8:37 AM, James Swift wrote: > Thanks, Nicholas. > > Might be worth adding a link to that from this page. > > > https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html?highlight=cxx_standard > > On 23 June 2016 at 14:34, Nicholas Braden > wrote: > >> This was asked recently - have a look at the CXX_EXTENSIONS property: >> https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html >> >> Previous discussion: >> http://public.kitware.com/pipermail/cmake/2016-June/063691.html >> >> On Thu, Jun 23, 2016 at 7:27 AM, James Swift wrote: >> > Hi, >> > >> > is there a way (or can it be added) to get set_property(TARGET target >> > PROPERTY CXX_STANDARD 14) to output -std=c++14 and not -std=gnu++14 when >> > needed? >> > >> > Thanks, >> > James Swift >> > >> > >> > -- >> > >> > 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://public.kitware.com/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://public.kitware.com/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://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] Compiling binaries with cmake -- help
Yep, if you have all the dependencies it should just work as I described in a previous message. On Thu, Jun 23, 2016 at 12:20 AM, Crest Christopher wrote: > I'll get the Python sipconfig module installed, then I hope we can continue > with getting it compiled ? > > Nicholas Braden > Thursday, June 23, 2016 1:15 AM > Yes, many projects do not include their dependencies and require you > to obtain them yourself. In this case it looks like you need the > Python sipconfig module installed. > > On Thu, Jun 23, 2016 at 12:10 AM, Crest Christopher > Nicholas Braden > Thursday, June 23, 2016 1:08 AM > It looks like the instructions are there in the README. I tried > building on my system but I'm missing some dependencies (e.g. at some > point it finds my Python 3 installation and tries to run some code but > fails due to a missing sipconfig module, which I am not familiar > with). > > Generally, to build a project that uses CMake, create an empty > directory for the build and open a terminal in it, then run CMake with > the path to the directory containing CMakeLists.txt and optionally > specify the generator to use if the default is not the one you want. > Then, if it completes without errors, you can use "cmake --build ." to > build it and "cmake --build . --target install" to install it, even if > you used an IDE generator. > > As for the project dependencies, you are own your own to get those. > > On Wed, Jun 22, 2016 at 11:56 PM, Crest Christopher > Martin Maurer > Thursday, June 23, 2016 12:45 AM > Hello, > > how about to share the github URL, > which file you have downloaded or project you want to compile? > > I think this would make it much easier for readers to help. > > Best regards, > > Martin > > Nicholas Braden > Wednesday, June 22, 2016 8:50 PM > Are you trying to use an existing CMakeLists.txt, or are you trying to > create your own? CMake doesn't just work on source files alone. > > On Wed, Jun 22, 2016 at 7:30 PM, Crest Christopher > Crest Christopher > Wednesday, June 22, 2016 8:30 PM > Hi, I'm hoping I can get some help on how to compile a repository from > github which is local on my machine with a series of folders which contain > CPP extension files. > > I have chosen the folders for which most likely contain the correct files to > compile the binaries followed by the folder to which to build the binaries > then I have chosen generate but I'm getting an error that the project files > are invalid ? > > -- 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://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] CXX_STANDARD and -std=c++14
Thanks, Nicholas. Might be worth adding a link to that from this page. https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html?highlight=cxx_standard On 23 June 2016 at 14:34, Nicholas Braden wrote: > This was asked recently - have a look at the CXX_EXTENSIONS property: > https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html > > Previous discussion: > http://public.kitware.com/pipermail/cmake/2016-June/063691.html > > On Thu, Jun 23, 2016 at 7:27 AM, James Swift wrote: > > Hi, > > > > is there a way (or can it be added) to get set_property(TARGET target > > PROPERTY CXX_STANDARD 14) to output -std=c++14 and not -std=gnu++14 when > > needed? > > > > Thanks, > > James Swift > > > > > > -- > > > > 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://public.kitware.com/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://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] CXX_STANDARD and -std=c++14
This was asked recently - have a look at the CXX_EXTENSIONS property: https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html Previous discussion: http://public.kitware.com/pipermail/cmake/2016-June/063691.html On Thu, Jun 23, 2016 at 7:27 AM, James Swift wrote: > Hi, > > is there a way (or can it be added) to get set_property(TARGET target > PROPERTY CXX_STANDARD 14) to output -std=c++14 and not -std=gnu++14 when > needed? > > Thanks, > James Swift > > > -- > > 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://public.kitware.com/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://public.kitware.com/mailman/listinfo/cmake
[CMake] CXX_STANDARD and -std=c++14
Hi, is there a way (or can it be added) to get set_property(TARGET target PROPERTY CXX_STANDARD 14) to output -std=c++14 and not -std=gnu++14 when needed? Thanks, James Swift -- 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://public.kitware.com/mailman/listinfo/cmake
Re: [CMake] C header file cross dependency
Hi Patrick, thank you for your answer and sorry that it took me a while to work on it. > > I forked your repo and played a little bit around. > > https://github.com/pboettch/test_cmake I pulled those changes and played aroud a bit myself. https://github.com/martinwag/test_cmake I'm now back at the point where I decided to use cmake's OBJECTS functionality. I didn't find any other way to pack all compiled products into an easy-to-include-and-link package for the application. I was unable to use target_link_libraries() because this actually wants to do linking instead of just packaging. The way you used it add_library(bsp INTERFACE) target_link_libraries(bsp INTERFACE drivers terminal) install(TARGETS bsp DESTINATION ${ARCHIVE_INSTALL_DIR}) the install command runs, but does not install anything, resulting in an archive with just the headers. I'm open to package the archive in a different way - install(EXPORT ...) seems promising. The important thing to me is that the consuming application doesn't need inside knowledge of the bsp package. > > Here are my conclusions: > > 1) Due to the use of add_libary(... OBJECTS ...) you cannot link > libraries with libraries or interfaces, this is a pity - especially for > a complex project with a lot of sub-dirs. > > There is a possibility to merge STATIC-libraries to generated one big > archive using external tools (libtool). If I were you I'd try to this > way to profit from the target_*-cmake-features. See above. > > 2) I created a log-dir with an interface-library - which only carries > the log.h and thus the printf-prototypes > > 3) Both, drivers and terminal link with this interface-library (to get > their hands on log.h) > This sounds good - I have to check if that works in the (more complex) production code. > 4) In addition I added two libraries to drivers/ uart-logging1 and uart- > logging2. This shows how you could compile-configure your printf- > function depending on the hardware used. In the main CMakeLists you just > need to select one of them - depending on the option's value. > > Basically I followed the idea of instantiating a print-function > 'somewhere' in the project (it could also be done outside) and then > select the one you want to use at the final link. > > Of course this way you could add other ways of printf'ing - logging1 and > logging2 are just stupid examples. This is -more or less- already in my production code. I want to do all this stuff in one configuration header file inside the application. However, I think it's a good idea to have the option to replace the printing function with "anything". I removed that part to keep the example as simple as possible. > > HTH and sorry for the delay, Obviously I'm not the fastest myself :-). Regards, Martin -- 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://public.kitware.com/mailman/listinfo/cmake