1

how come cmake does not give an error when not specifying FILE name? I understand that when FILE name not specified, cmake gives it the project's name...by this logic should be mandatory to specify path...

no error:

install(FILES 
    ${CMAKE_CURRENT_SOURCE_DIR}/include/my_math/addition.h
    ${CMAKE_CURRENT_SOURCE_DIR}/include/my_math/division.h
    DESTINATION ${CMAKE_INSTALL_PREFIX}/include/my_math)

install(TARGETS my_math EXPORT my_export DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/my_math)
install(EXPORT my_export DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/my_math)

INTERFACE_INCLUDE_DIRECTORIES error:

install(TARGETS my_math EXPORT my_export DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/my_math)
    install(EXPORT my_export 
        DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/my_math
        FILE my_math-config.cmake)

complete error message:

CMake Error in my_math/CMakeLists.txt:
  Target "my_math" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/alon/cmake/sandbox/Install/my_math/include"

  which is prefixed in the source directory.


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
Alon212
  • 51
  • 10
  • CMake Error in my_math/CMakeLists.txt: Target "my_math" INTERFACE_INCLUDE_DIRECTORIES property contains path: "/home/alon/cmake/sandbox/Install/my_math/include" which is prefixed in the source directory. -- Generating done CMake Generate step failed. Build files cannot be regenerated correctly. – Alon212 Jan 28 '21 at 10:39
  • just did ! thanks for the tip – Alon212 Jan 28 '21 at 10:44
  • Ok, but what is your question? Do you want to know how to handle this error message? If so, then see [that question](https://stackoverflow.com/questions/25676277/cmake-target-include-directories-prints-an-error-when-i-try-to-add-the-source). – Tsyvarev Jan 28 '21 at 10:47
  • actually i am trying to understand why ,when cmake uses its default name (project), there is not error but only with custom export names – Alon212 Jan 28 '21 at 11:09
  • I would find strange that checking for `INTERFACE_INCLUDE_DIRECTORIES` property is performed only when `FILE` option is given to `install(EXPORT)` command. It smells like your tests (with `FILE` option and without it) have **something else** to be different. E.g. different build or install directories. – Tsyvarev Jan 28 '21 at 12:42
  • Note also, that while **export file** (`YYY.cmake`, created with `install(EXPORT)`) could be used as a **config file** (`XXXConfig.cmake` or `xxx-config.cmake`, consumed by `find_package()`), the most flexible usage is achieved when config file is created by different approach. See the tutorial about creating a package file in CMake [documention](https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-packages). – Tsyvarev Jan 28 '21 at 12:45

0 Answers0