Generate headers and inherit include_directories

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Generate headers and inherit include_directories

CMake mailing list

Hi!

 

I am a seasoned Cmake user but cannot solve a fairly simple problem, so I might be mistaking the forest for the trees.

 

I have a project in which there is a custom_command/custom_target pair that creates a header file as part of a (currently) header-only target. I want to create an imported target (or really, any kind of target), which is responsible for triggering header generation at build time AND relaying the include directory so consumers need not worry about the location where the generated header files go. My problem is:

 

  • I cannot invoke target_include_directories on a custom_target
  • Imported targets cannot have source files (for proper depending on the result header file)
  • Imported targets cannot link to a custom_target
  • Interface and Unkown libraries cannot be non-imported
  • All other library types result in objects/libraries (which I don’t need)

 

How can I create the dependency graph where my custom_command is invoked if the inputs to it change (or if its output doesn’t exist yet) and depending targets are rebuilt accordingly AND I also inherit build properties (include directories)?

 

Cheers,

Máté


--

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
Reply | Threaded
Open this post in threaded view
|

Re: Generate headers and inherit include_directories

Michael Ellery
maybe a CMake snippet of what you are trying would help clarify, but are you using an interface library for your header-only? I would assume yes - and then have to tried add_dependency() for that library to trigger the file generation? The dependency will only be resolved when the library is used by an exe or installed (I think), but that should be sufficient?

-Mike

> On Oct 3, 2017, at 6:54 AM, Nagy-Egri Máté Ferenc via CMake <[hidden email]> wrote:
>
> Hi!
>
> I am a seasoned Cmake user but cannot solve a fairly simple problem, so I might be mistaking the forest for the trees.
>
> I have a project in which there is a custom_command/custom_target pair that creates a header file as part of a (currently) header-only target. I want to create an imported target (or really, any kind of target), which is responsible for triggering header generation at build time AND relaying the include directory so consumers need not worry about the location where the generated header files go. My problem is:
>
> • I cannot invoke target_include_directories on a custom_target
> • Imported targets cannot have source files (for proper depending on the result header file)
> • Imported targets cannot link to a custom_target
> • Interface and Unkown libraries cannot be non-imported
> • All other library types result in objects/libraries (which I don’t need)
>
> How can I create the dependency graph where my custom_command is invoked if the inputs to it change (or if its output doesn’t exist yet) and depending targets are rebuilt accordingly AND I also inherit build properties (include directories)?
>
> Cheers,
> Máté
> --
>
> 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

signature.asc (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Generate headers and inherit include_directories

CMake mailing list

Hi Michael!

 

This is what I wanted to do (only relevant parts showing):

 

/// top-level CMakeLists.txt

add_subdirectory(Gripper)

add_subdirectory(examples)

 

 

/// Gripper/CmakeLists.txt

set(RESULT ${CMAKE_CURRENT_BINARY_DIR}/inc/Gripper/stl/stlYlms_dynamic.hpp)

add_custom_command(COMMAND ... ARGS ...

                  OUTPUT ${RESULT})

add_custom_target(Ylms

                  DEPENDS ${RESULT})

 

# What comes from HERE

add_library(Gripper::Ylms INTERFACE IMPORTED GLOBAL)

target_include_directories(Gripper::Ylms INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/inc

                                                   ${CMAKE_CURRENT_BINARY_DIR}/inc)

add_dependencies(Gripper::Ylms Ylms)

# to HERE? (Note, example does not work)

 

/// examples/CmakeLists.txt

add_executable(example1 main.cpp)

 

target_link_libraries(example1 Gripper::Ylms)

 

When specifying Gripper::Ylms as a link target for example1, I would like to pick up both the dependency of Ylms being processed first and also the include directory marking the location of the generated header file.

 

Note, the closes I got was using

 

set_target_properties (Gripper::Ylms PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/inc ${CMAKE_CURRENT_BINARY_DIR}/inc")

 

instead of

 

target_include_directories(Gripper::Ylms INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/inc

                                                   ${CMAKE_CURRENT_BINARY_DIR}/inc)

 

because set_target_properties wouldn’t let me specify multiple entries, but target_include_directories is not allowed on IMPORTED targets (but simple INTERFACE libraries cannot be global)… no combination of commands seem to work.

 

Feladó: [hidden email]
Elküldve: 2017. október 3., kedd 19:04
Címzett: [hidden email]
Másolatot kap: [hidden email]
Tárgy: Re: [CMake] Generate headers and inherit include_directories

 

maybe a CMake snippet of what you are trying would help clarify, but are you using an interface library for your header-only? I would assume yes - and then have to tried add_dependency() for that library to trigger the file generation? The dependency will only be resolved when the library is used by an exe or installed (I think), but that should be sufficient?

 

-Mike

 

> On Oct 3, 2017, at 6:54 AM, Nagy-Egri Máté Ferenc via CMake <[hidden email]> wrote:

>

> Hi!

>

> I am a seasoned Cmake user but cannot solve a fairly simple problem, so I might be mistaking the forest for the trees.

>

> I have a project in which there is a custom_command/custom_target pair that creates a header file as part of a (currently) header-only target. I want to create an imported target (or really, any kind of target), which is responsible for triggering header generation at build time AND relaying the include directory so consumers need not worry about the location where the generated header files go. My problem is:

>

>             • I cannot invoke target_include_directories on a custom_target

>             • Imported targets cannot have source files (for proper depending on the result header file)

>             • Imported targets cannot link to a custom_target

>             • Interface and Unkown libraries cannot be non-imported

>             • All other library types result in objects/libraries (which I don’t need)

>

> How can I create the dependency graph where my custom_command is invoked if the inputs to it change (or if its output doesn’t exist yet) and depending targets are rebuilt accordingly AND I also inherit build properties (include directories)?

>

> Cheers,

> Máté

> --

>

> 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
Reply | Threaded
Open this post in threaded view
|

Re: Generate headers and inherit include_directories

Michael Ellery
In reply to this post by Michael Ellery

> On Oct 5, 2017, at 3:50 AM, Nagy-Egri Máté Ferenc <[hidden email]> wrote:
>
> Hi Michael!
>
> This is what I wanted to do (only relevant parts showing):
>
> /// top-level CMakeLists.txt
> add_subdirectory(Gripper)
> add_subdirectory(examples)
>
>
> /// Gripper/CmakeLists.txt
> set(RESULT ${CMAKE_CURRENT_BINARY_DIR}/inc/Gripper/stl/stlYlms_dynamic.hpp)
> add_custom_command(COMMAND ... ARGS ...
>                   OUTPUT ${RESULT})
> add_custom_target(Ylms
>                   DEPENDS ${RESULT})
>
> # What comes from HERE
> add_library(Gripper::Ylms INTERFACE IMPORTED GLOBAL)
> target_include_directories(Gripper::Ylms INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/inc
>                                                    ${CMAKE_CURRENT_BINARY_DIR}/inc)
> add_dependencies(Gripper::Ylms Ylms)
> # to HERE? (Note, example does not work)
>
> /// examples/CmakeLists.txt
> add_executable(example1 main.cpp)
>
> target_link_libraries(example1 Gripper::Ylms)
>
> When specifying Gripper::Ylms as a link target for example1, I would like to pick up both the dependency of Ylms being processed first and also the include directory marking the location of the generated header file.
>
> Note, the closes I got was using
>
> set_target_properties (Gripper::Ylms PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/inc ${CMAKE_CURRENT_BINARY_DIR}/inc")
>
> instead of
>
> target_include_directories(Gripper::Ylms INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/inc
>                                                    ${CMAKE_CURRENT_BINARY_DIR}/inc)
>
> because set_target_properties wouldn’t let me specify multiple entries, but target_include_directories is not allowed on IMPORTED targets (but simple INTERFACE libraries cannot be global)… no combination of commands seem to work.
>
I think “IMPORTED” on your header library might be part of the problem…I would remove that.  I have an example I will send you privately that does what you want I think…

-Mike



--

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

signature.asc (849 bytes) Download Attachment