How to force install into custom dir under project

I have project structure with custom install dir under the project dir (build dir is at the same level as install dir) which I’d like to install to my librray (with library and public include objects). However I am getting error Target “mylib” INTERFACE_INCLUDE_DIRECTORIES property contains path:

"/home/myproject/install/include"

which is prefixed in the source directory.
The actual source is in different dir, but the top level project directory is referenced by ${CMAKE_SOURCE_DIR} so maybe this is causing error?
Anyway how to I allow generation to proceed for this case.
Note, this error occurs after Configuration done so install target for make is configured and running so running cmake script with make install completes successfully wrinting cmake targets to under install dir.

If I understand your issue correctly, you need to use the BUILD_INTERFACE and INSTALL_INTERFACE generator expressions to differentiate between building the library and using the library from the install dir.

From https://cmake.org/cmake/help/latest/command/target_include_directories.html:

Include directories usage requirements commonly differ between the build-tree and the install-tree. The BUILD_INTERFACE and INSTALL_INTERFACE generator expressions can be used to describe separate usage requirements based on the usage location. Relative paths are allowed within the INSTALL_INTERFACE expression and are interpreted relative to the installation prefix. For example:

target_include_directories(mylib PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/mylib>
  $<INSTALL_INTERFACE:include/mylib>  # <prefix>/include/mylib
)
1 Like

Thank you for the response. This issue has been resolved by specifying relative path - removing “/home/myproject/” whih tells me the error message is not quite accurate and should rather indicate that installation should not be targeting fixed path on the the build system which maybe invalid on the system using my install dir.