On Sun, Jul 10, 2016 at 1:23 PM, Robert Dailey <rcdailey.li...@gmail.com> wrote:
> I am exporting/installing a header-only INTERFACE library and I run
> into difficulty with target_sources() because I can't use relative
> paths to the files. So I do this:
>
>
>
> set(project_name fubar)
>
> set(source_files
>     myfile.h
> )
>
> # Include dir for installed targets
> set(INCLUDE_DIR include/${project_name}-${upstream_version})
>
> foreach(source_file ${source_files})
>     get_filename_component(abs_source_file ${source_file} ABSOLUTE)
>     list(APPEND absolute_source_files
>         $<BUILD_INTERFACE:${abs_source_file}>
>         $<INSTALL_INTERFACE:${INCLUDE_DIR}/${source_file}>
>     )
> endforeach()
>
> add_library(${project_name} INTERFACE)
> target_sources(${project_name} INTERFACE ${absolute_source_files})
>
>
>
> Without the separate generator expressions for BUILD_INTERFACE and
> INSTALL_INTERFACE, CMake complains that absolute paths are not inside
> INSTALL_PREFIX in my install() command later:
>
>
>
> CMake Error in CMakeLists.txt:
> Target "better-enums" INTERFACE_SOURCES property contains path:
>
> "C:/code/fubar/myfile.h"
>
> which is prefixed in the source directory.
>
>
>
> Corresponding install() command is:
>
>
> install(TARGETS ${project_name} EXPORT ${project_name}-targets
>     INCLUDES DESTINATION ${INCLUDE_DIR}
> )
>
> export(EXPORT ${project_name}-targets
>     FILE ${CMAKE_CURRENT_BINARY_DIR}/${project_name}-targets.cmake
> )
>
> install(EXPORT ${project_name}-targets
>     FILE ${project_name}-targets.cmake
>     DESTINATION ${package_config_dir}
> )
>
> For INTERFACE_INCLUDE_DIRECTORIES, this same problem exists except
> CMake provides a convenience toggle called
> INTERFACE_SYSTEM_INCLUDE_DIRECTORIES. Is there a similar convenience
> for interface sources? Or maybe I'm going about this all the wrong
> way?
>
> Honestly the only reason interface sources are specified is because I
> have a header-only library and I want that header to show up in only
> MY targets during development so I can edit those header files through
> my IDE. I do not expect the header files to appear in targets that
> simply import my target as a dependency.
>
> So it's possible I'm going about this the wrong way. Advice is greatly
> appreciated.

So after I posted this, I made a minor change so that my
INTERFACE_SOURCES property (modified via the target_sources() command)
simply doesn't specify a listing for INSTALL_INTERFACE. Basically only
the BUILD_INTERFACE is populated.

I think this gives me the desired output, since I do not want
downstream targets to inherit my library's public headers in their own
project's file listing. They only get the public include directories
instead.

I still feel like I'm doing things wrong or sub-optimally, so feedback
is still very much appreciated.
-- 

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 via email to