CMake: How do I add a function to an installed config?

后端 未结 2 1774
长发绾君心
长发绾君心 2020-12-04 04:02

I am creating a library which I am building and installing with CMake. In the CMakeLists.txt is install(TARGETS mylib ...) to install the library i

相关标签:
2条回答
  • 2020-12-04 04:12

    It is misconception that CMake should generate XXXConfig.cmake script. As opposite, intended behavior that CMake generates every other script (names can be any):

    • XXXConfigTargets.cmake with install(EXPORT)
    • XXXConfigVersion.cmake with write_basic_package_version_file()

    and these scripts are included in the XXXConfig.cmake script written by hands, where you may define additional things:

    # File: XXXConfig.cmake
    
    include(${CMAKE_CURRENT_LIST_DIR}/XXXConfigVersion.cmake)
    include(${CMAKE_CURRENT_LIST_DIR}/XXXConfigTargets.cmake)
    # Here you may provide additional functions and other things.
    function(my_func)
      ...
    endfunction()
    

    See more in the CMake packaging documentation.

    0 讨论(0)
  • 2020-12-04 04:26

    To clarify further, there is a module that helps your configure valid and relocatable config file.

    See macro configure_package_config_file provided by CMakePackageConfigHelpers module.

    As mentioned by @Tsyvarev, the XXXConfig.cmake file should still be written by hand but configured with configure_package_config_file instead of configure_file.

    0 讨论(0)
提交回复
热议问题