CMake include_directories for custom target type

Viewed 2192

I have a custom target with .cpp and .h source files. As normal, those files include other header files. I'd like to add a directory for header files to be looked from.

This might sounds easy so far, but here's the twist. I'm using a custom target and custom commands to compile and link the program. The actual compiler needs another type of project file, which is not compatible with CMake.

If I try to add include directories to my current target, I'm greeted with the following error:

target_include_directories called with non-compliant target type.

The reason I think that this might be possible is that you can add header file lookup paths in the Visual Studio project I'm creating from CMake. I would not like to do this, because it's not persistent and everyone on my team would have to do it too. And what's worse, I would have to explain it to them ... (shudders)


EDIT:

To answer comments, I'm generating Visual Studio 2017 project files. My custom target command is just:

add_custom_target(APP
DEPENDS ${APP_DEPENDENCIES}
SOURCES ${APP_DEPENDENCIES}
)

and my custom command is:

add_custom_command(
OUTPUT "${LIB_COMPILE_DIR}/libAPP.a"
DEPENDS ${LIB_COMPILE_SRCS}
COMMAND gbuild -top ${LIB_COMPILE_DIR}/App.gpj
WORKING_DIRECTORY ${LIB_COMPILE_DIR}
)

I'm aware that CMake has a generator for GHS MULTI but it is quite experimental and doesn't work in my case.

1 Answers

I've had a similar problem, in that I needed to supply the include directories to a custom target. My solution is not brilliant, but it seems to address the problem at hand. I obtained the paths in the include directories, and formatted them into the required inputs for my compiler (in this case ODB[1]).

    get_directory_property(dirs INCLUDE_DIRECTORIES)
    set(global_includes "")
    foreach(dir IN LISTS dirs)
        set(global_includes ${global_includes} -I ${dir})
    endforeach()

I then used ${global_includes} in the command of the custom target. I wanted to move to the new world of target_include_directories, but haven't managed to make it work in this scenario.

[1] https://www.codesynthesis.com/products/odb/download.xhtml

Related