Re: [CMake] Specify extra files for display in IDE
Hi, I tried to add interface sources to interface libraries with both, the CMake 3.11.18040201-MSVC_2 integration of Visual Studio (with Ninja), which I’m using most of the time, and the “Visual Studio 15 2017 Win64” generator of CMake 3.12.1: - The Visual Studio integration shows the target in the “CMake Targets View”, but it contains only one file: CMakeLists.txt. There is no difference if I set header only interface sources or no sources. If this differs from the intended behavior of the CMake generators then I will follow this up with the Visual Studio team. - The Visual Studio generator doesn’t show interface libraries at all. Is this the intended behavior of the Visual Studio generator? Unclear to me is, what the semantics of header only interface sources are? Should headers be INTERFACE_SOURCES? I don’t see a point in propagating them to targets which link to the interface library. To my understanding this is what interface source means. Maybe there is more to it. When headers of the public interface of a library are supposed to be interface sources, then this means, that I should put headers of regular libraries in the PUBLIC section, right? Daniel From: Eric Noulard [mailto:eric.noul...@gmail.com] Sent: Mittwoch, 5. September 2018 11:22 To: Daniel Eiband Cc: CMake Mailinglist Subject: Re: [CMake] Specify extra files for display in IDE Le mer. 5 sept. 2018 à 11:00, Daniel Eiband mailto:daniel.eib...@brainlab.com>> a écrit : Hi, I managed to solve the presentation of object libraries by renaming the targets and hiding certain targets in folders. I think this solution is acceptable. The issue with the display of header only libraries in IDEs, which are implemented as interface libraries, is still unsolved. The add_library() command doesn’t accept any sources. For an interface library you can add sources with target_sources(yourlib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/whatever.h) You need the INTERFACE keyword though: https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries is this not working for you? Could you provide a strip-down archive which exhibit this issue I may try it on my side? Also setting the SOURCES property of an interface library target is rejected by CMake. This is because you can only populate INTERFACE_SOURCES on an INTERFACE target: https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_SOURCES.html https://cmake.org/cmake/help/latest/command/target_sources.html#command:target_sources I haven’t found any other way of adding the files to the interface library so that they are presented in the IDE. Like I said in a previous email on my side, interface library (INTERFACE) sources are displayed in vscode and qtcreator, may be the fact that they are not displayed by Visual Studio is a Visual Studio bug? By the way there is an old issue on this subject: https://gitlab.kitware.com/cmake/cmake/issues/15234 I know the workaround of adding an empty custom target. This is however not really satisfying, because Visual Studio for example displays them with a completely different icon and the suffix “(utility target)”. Doesn’t look like a C++ library any longer. It also sort of highlights the library because of the non-C++ icon and I have to hide even more targets (the real interface libraries). From a CMake interface perspective this is also an asymmetry: Why can I add arbitrary files to executable and static/shared library targets being displayed in IDEs without contributing to the build artifact while this is not possible for interface libraries? I think, the restriction on interface libraries should not be that they don’t have any source files. Interface libraries must not have source files which produce build artifacts. Agreed and I think it would more "natural" to be able to simply target_sources / add_library "as usual" and promote SOURCES to INTERFACE_SOURCES automatically since the target is an INTERFACE lib. Is this worth an enhancement bug or has this already been discussed? The only one I am aware of is this one: https://gitlab.kitware.com/cmake/cmake/issues/15234 -- Eric -- 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: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] Specify extra files for display in IDE
Le mer. 5 sept. 2018 à 11:00, Daniel Eiband a écrit : > Hi, > > > > I managed to solve the presentation of object libraries by renaming the > targets and hiding certain targets in folders. I think this solution is > acceptable. > > > > The issue with the display of header only libraries in IDEs, which are > implemented as interface libraries, is still unsolved. The add_library() > command doesn’t accept any sources. > For an interface library you can add sources with target_sources(yourlib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/whatever.h) You need the INTERFACE keyword though: https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries is this not working for you? Could you provide a strip-down archive which exhibit this issue I may try it on my side? > Also setting the SOURCES property of an interface library target is > rejected by CMake. > This is because you can only populate INTERFACE_SOURCES on an INTERFACE target: https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_SOURCES.html https://cmake.org/cmake/help/latest/command/target_sources.html#command:target_sources > I haven’t found any other way of adding the files to the interface library > so that they are presented in the IDE. > Like I said in a previous email on my side, interface library (INTERFACE) sources are displayed in vscode and qtcreator, may be the fact that they are not displayed by Visual Studio is a Visual Studio bug? By the way there is an old issue on this subject: https://gitlab.kitware.com/cmake/cmake/issues/15234 > I know the workaround of adding an empty custom target. This is however > not really satisfying, because Visual Studio for example displays them with > a completely different icon and the suffix “(utility target)”. Doesn’t look > like a C++ library any longer. It also sort of highlights the library > because of the non-C++ icon and I have to hide even more targets (the real > interface libraries). > > > > From a CMake interface perspective this is also an asymmetry: Why can I > add arbitrary files to executable and static/shared library targets being > displayed in IDEs without contributing to the build artifact while this is > not possible for interface libraries? I think, the restriction on interface > libraries should not be that they don’t have any source files. Interface > libraries must not have source files which produce build artifacts. > Agreed and I think it would more "natural" to be able to simply target_sources / add_library "as usual" and promote SOURCES to INTERFACE_SOURCES automatically since the target is an INTERFACE lib. > > Is this worth an enhancement bug or has this already been discussed? > The only one I am aware of is this one: https://gitlab.kitware.com/cmake/cmake/issues/15234 -- Eric -- 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: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] Specify extra files for display in IDE
Hi, I managed to solve the presentation of object libraries by renaming the targets and hiding certain targets in folders. I think this solution is acceptable. The issue with the display of header only libraries in IDEs, which are implemented as interface libraries, is still unsolved. The add_library() command doesn’t accept any sources. Also setting the SOURCES property of an interface library target is rejected by CMake. I haven’t found any other way of adding the files to the interface library so that they are presented in the IDE. I know the workaround of adding an empty custom target. This is however not really satisfying, because Visual Studio for example displays them with a completely different icon and the suffix “(utility target)”. Doesn’t look like a C++ library any longer. It also sort of highlights the library because of the non-C++ icon and I have to hide even more targets (the real interface libraries). From a CMake interface perspective this is also an asymmetry: Why can I add arbitrary files to executable and static/shared library targets being displayed in IDEs without contributing to the build artifact while this is not possible for interface libraries? I think, the restriction on interface libraries should not be that they don’t have any source files. Interface libraries must not have source files which produce build artifacts. Is this worth an enhancement bug or has this already been discussed? Daniel From: CMake [mailto:cmake-boun...@cmake.org] On Behalf Of Daniel Eiband Sent: Donnerstag, 30. August 2018 15:47 To: Eric Noulard Cc: CMake Mailinglist Subject: Re: [CMake] Specify extra files for display in IDE Hi Eric, Thank you for your answers! Visual Studio supports the source_group command, but it cannot be used to add sources. It only controls where source files of targets are displayed. > I do very often add non source file (like README.md) to any targets This is what I also do for non-build related files such as readme files. It works except for interface libraries (read below). In the object library case I can add non-build related files, but for let's say 'logical' reasons I would like to show the build related files such as cpp files also in the shared library target which links to the object library. > At least the "never displayed" header only library looks like a bug of the > Visual Studio generator to me. The situation for interface libraries (header only) is different: CMake won't allow me to add any sources to the target, not even headers. As a result configure fails with an error. I'm pretty sure if I could add headers to interface libraries then they will show up in Visual Studio with this target. So I think it's not a generator bug, but a short-coming of CMake itself. Daniel From: Eric Noulard [mailto:eric.noul...@gmail.com] Sent: Donnerstag, 30. August 2018 14:40 To: Daniel Eiband mailto:daniel.eib...@brainlab.com>> Cc: CMake Mailinglist mailto:cmake@cmake.org>> Subject: Re: [CMake] Specify extra files for display in IDE Le jeu. 30 août 2018 à 12:32, Daniel Eiband mailto:daniel.eib...@brainlab.com>> a écrit : Hi, I’m currently migrating a code base from a proprietary MSBuild based generator to CMake 3.11 which is shipped with Visual Studio. There are two aspects to this task: 1) Integration of custom build steps 2) Presentation in the IDE The first aspect of integrating all of our custom build steps as custom commands works really well. At one point I use an object library to be able to use the object files as input to such a custom tool and to link a shared library. Both the object library and the shared library are from the programmers perspective one logical unit. The object library is just an implementation detail. However, as for the second point, the source files are displayed with the object library target in the IDE while the shared library has no sources. This makes sense from the build targets point of view, but surprises the developers. My approach is to hide all targets which are sort of implementation detail into a folder. To make this work I would like to display the sources with the shared library which consumes the object files of the object library. Currently this seems to be impossible. Another inconsistency I noticed regarding the second point is the following: I implemented header only libraries as interface libraries in CMake. This works fine from the build perspective. Interface libraries however don’t allow me to list sources, not even headers. As a result, the headers of this header only library are not displayed anywhere in the IDE. This is odd, because in executable targets for example I can list all headers even if they don’t contribute to the build process directly and they are displayed in the IDE. Using empty custom targets to present the header files works, but they are not displayed as C++ libraries in Visual
Re: [CMake] Specify extra files for display in IDE
Hi Eric, Thank you for your answers! Visual Studio supports the source_group command, but it cannot be used to add sources. It only controls where source files of targets are displayed. > I do very often add non source file (like README.md) to any targets This is what I also do for non-build related files such as readme files. It works except for interface libraries (read below). In the object library case I can add non-build related files, but for let's say 'logical' reasons I would like to show the build related files such as cpp files also in the shared library target which links to the object library. > At least the "never displayed" header only library looks like a bug of the > Visual Studio generator to me. The situation for interface libraries (header only) is different: CMake won't allow me to add any sources to the target, not even headers. As a result configure fails with an error. I'm pretty sure if I could add headers to interface libraries then they will show up in Visual Studio with this target. So I think it's not a generator bug, but a short-coming of CMake itself. Daniel From: Eric Noulard [mailto:eric.noul...@gmail.com] Sent: Donnerstag, 30. August 2018 14:40 To: Daniel Eiband Cc: CMake Mailinglist Subject: Re: [CMake] Specify extra files for display in IDE Le jeu. 30 août 2018 à 12:32, Daniel Eiband mailto:daniel.eib...@brainlab.com>> a écrit : Hi, I’m currently migrating a code base from a proprietary MSBuild based generator to CMake 3.11 which is shipped with Visual Studio. There are two aspects to this task: 1) Integration of custom build steps 2) Presentation in the IDE The first aspect of integrating all of our custom build steps as custom commands works really well. At one point I use an object library to be able to use the object files as input to such a custom tool and to link a shared library. Both the object library and the shared library are from the programmers perspective one logical unit. The object library is just an implementation detail. However, as for the second point, the source files are displayed with the object library target in the IDE while the shared library has no sources. This makes sense from the build targets point of view, but surprises the developers. My approach is to hide all targets which are sort of implementation detail into a folder. To make this work I would like to display the sources with the shared library which consumes the object files of the object library. Currently this seems to be impossible. Another inconsistency I noticed regarding the second point is the following: I implemented header only libraries as interface libraries in CMake. This works fine from the build perspective. Interface libraries however don’t allow me to list sources, not even headers. As a result, the headers of this header only library are not displayed anywhere in the IDE. This is odd, because in executable targets for example I can list all headers even if they don’t contribute to the build process directly and they are displayed in the IDE. Using empty custom targets to present the header files works, but they are not displayed as C++ libraries in Visual Studio any longer. This also litters the solution with lots of extra empty targets. I’m going to rephrase both described presentation problems into one more fundamental question, solutions or workarounds for either of both presentation problems are of course welcome: Can I specify sources used for builds and files used for display in IDEs separately? I think they are two different things. For my use case it would also be sufficient to be able to add extra files for display in IDEs to any target. I'm afraid that your question may be generator-specific and I'm no sure Visual Studio generator behaves in the same way as others I'm using. I do very often add non source file (like README.md) to any targets (add_executable, add_library, add_custom_target) in order to make them editable in the IDE. Since those file are guessed as not being compilable they inherit the HEADER_FILE_ONLY (https://cmake.org/cmake/help/v3.11/prop_sf/HEADER_FILE_ONLY.html) automatically and they show up in IDE just fine. My particular IDE being either qtcreator, vscode+cmaketools or eclipse and this works well for those. Moreover, in qtcreator (for example) header only libraries appear on their own with editable header file AND as subdir of every other targets their are used by. This subdir contains the headers. This is not the case with object libraries though :-( Concerning the visual grouping you must already being using source_group (https://cmake.org/cmake/help/latest/command/source_group.html) source_group does not seems to have any effect in my favorite IDEs... In the end I don't know if there is currently any ways to do what you want. At least the "never displayed" header only library looks like a bug of the Visua
Re: [CMake] Specify extra files for display in IDE
Le jeu. 30 août 2018 à 12:32, Daniel Eiband a écrit : > Hi, > > > > I’m currently migrating a code base from a proprietary MSBuild based > generator to CMake 3.11 which is shipped with Visual Studio. There are two > aspects to this task: > > > > 1) Integration of custom build steps > > 2) Presentation in the IDE > > > > The first aspect of integrating all of our custom build steps as custom > commands works really well. At one point I use an object library to be able > to use the object files as input to such a custom tool and to link a shared > library. Both the object library and the shared library are from the > programmers perspective one logical unit. The object library is just an > implementation detail. However, as for the second point, the source files > are displayed with the object library target in the IDE while the shared > library has no sources. This makes sense from the build targets point of > view, but surprises the developers. > > My approach is to hide all targets which are sort of implementation detail > into a folder. To make this work I would like to display the sources with > the shared library which consumes the object files of the object library. > Currently this seems to be impossible. > > > > Another inconsistency I noticed regarding the second point is the > following: I implemented header only libraries as interface libraries in > CMake. This works fine from the build perspective. Interface libraries > however don’t allow me to list sources, not even headers. As a result, the > headers of this header only library are not displayed anywhere in the IDE. > This is odd, because in executable targets for example I can list all > headers even if they don’t contribute to the build process directly and > they are displayed in the IDE. Using empty custom targets to present the > header files works, but they are not displayed as C++ libraries in Visual > Studio any longer. This also litters the solution with lots of extra empty > targets. > > > > I’m going to rephrase both described presentation problems into one more > fundamental question, solutions or workarounds for either of both > presentation problems are of course welcome: Can I specify sources used for > builds and files used for display in IDEs separately? I think they are two > different things. For my use case it would also be sufficient to be able to > add extra files for display in IDEs to any target. > I'm afraid that your question may be generator-specific and I'm no sure Visual Studio generator behaves in the same way as others I'm using. I do very often add non source file (like README.md) to any targets (add_executable, add_library, add_custom_target) in order to make them editable in the IDE. Since those file are guessed as not being compilable they inherit the HEADER_FILE_ONLY ( https://cmake.org/cmake/help/v3.11/prop_sf/HEADER_FILE_ONLY.html) automatically and they show up in IDE just fine. My particular IDE being either qtcreator, vscode+cmaketools or eclipse and this works well for those. Moreover, in qtcreator (for example) header only libraries appear on their own with editable header file AND as subdir of every other targets their are used by. This subdir contains the headers. This is not the case with object libraries though :-( Concerning the visual grouping you must already being using source_group ( https://cmake.org/cmake/help/latest/command/source_group.html) source_group does not seems to have any effect in my favorite IDEs... In the end I don't know if there is currently any ways to do what you want. At least the "never displayed" header only library looks like a bug of the Visual Studio generator to me. -- Eric -- 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: https://cmake.org/mailman/listinfo/cmake
[CMake] Specify extra files for display in IDE
Hi, I'm currently migrating a code base from a proprietary MSBuild based generator to CMake 3.11 which is shipped with Visual Studio. There are two aspects to this task: 1) Integration of custom build steps 2) Presentation in the IDE The first aspect of integrating all of our custom build steps as custom commands works really well. At one point I use an object library to be able to use the object files as input to such a custom tool and to link a shared library. Both the object library and the shared library are from the programmers perspective one logical unit. The object library is just an implementation detail. However, as for the second point, the source files are displayed with the object library target in the IDE while the shared library has no sources. This makes sense from the build targets point of view, but surprises the developers. My approach is to hide all targets which are sort of implementation detail into a folder. To make this work I would like to display the sources with the shared library which consumes the object files of the object library. Currently this seems to be impossible. Another inconsistency I noticed regarding the second point is the following: I implemented header only libraries as interface libraries in CMake. This works fine from the build perspective. Interface libraries however don't allow me to list sources, not even headers. As a result, the headers of this header only library are not displayed anywhere in the IDE. This is odd, because in executable targets for example I can list all headers even if they don't contribute to the build process directly and they are displayed in the IDE. Using empty custom targets to present the header files works, but they are not displayed as C++ libraries in Visual Studio any longer. This also litters the solution with lots of extra empty targets. I'm going to rephrase both described presentation problems into one more fundamental question, solutions or workarounds for either of both presentation problems are of course welcome: Can I specify sources used for builds and files used for display in IDEs separately? I think they are two different things. For my use case it would also be sufficient to be able to add extra files for display in IDEs to any target. Regards, Daniel -- 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: https://cmake.org/mailman/listinfo/cmake