CMake install (TARGETS in subdirectories)

后端 未结 3 462
梦毁少年i
梦毁少年i 2020-12-06 04:14

Consider the following CMakeLists.txt file:

add_subdirectory(execA)
add_subdirectory(libB)

install(TARGETS execA libB
        RUNTIME DESTINATI         


        
3条回答
  •  情深已故
    2020-12-06 05:17

    This still seems to be a pain point in CMake 3.11.

    In our codebase, we have many targets defined in subdirectories and need to create an assortment of installers with different configurations and (potentially overlapping) combinations of targets.

    Here's my solution:

    • Before calling add_subdirectory in your root CMakeLists.txt file, create a GLOBAL property with the names of the target(s) you want to include in your installer.
    • Wrap target creation functions (add_executable, etc.) in your own custom functions. Within those functions check if the target is present in the global property, and invoke install accordingly.

    That approach allows you to centralize installer configuration.

    Also: To support creation of multiple installers, we populate our global list along with other installer properties in separate .cmake files. When we invoke cmake, we pass the name of the installer configuration CMake file as a command-line argument. Our root CMakeLists.txt file simply calls include with that file.

提交回复
热议问题