Skip to content

install components from directories marked EXCLUDE_FROM_ALL still populate COMPONENTS, breaking CPack WIX generator.

Given the following snippet, where lib1 and lib2 are projects that declare install targets:

add_subdirectory(lib1 EXCLUDE_FROM_ALL)
add_subdirectory(lib2 EXCLUDE_FROM_ALL)

add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE lib1 lib2)
install(TARGETS myapp
    CONFIGURATIONS Release
    RUNTIME DESTINATION bin
    COMPONENT myapp_Runtime
)

get_cmake_property(LIST_OF_COMPONENTS COMPONENTS)
message("DEBUG: Component List: ${LIST_OF_COMPONENTS}")

Assuming both lib1 and lib2 are defining their install targets with component names the output will be DEBUG: Component List: lib1;lib2;myapp_Runtime

I expected the output to be DEBUG: Component List: myapp_Runtime since all install targets are in directories marked EXCLUDE_FROM_ALL, specifically to avoid those install targets leaking into my application. cmake --install . works as expected but if I then try to package this program:

set(CPACK_PACKAGE_NAME wc-programmer)
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)
message("DEBUG: CPack Component List: ${CPACK_COMPONENTS_ALL}")

the output is again DEBUG: CPack Component List: lib1;lib2;myapp_Runtime

This causes the CPack WIX generator to fail (and I suspect other similar generators?) since the number of components is > 1, but most are empty.

CPack Error: Problem running WiX candle. Please check 'C:/Users/name/myapp/cmake-build-release/_CPack_Packages/win32/WIX/wix.log' for errors.
CPack Error: Fatal WiX Generator Error
CPack Error: Problem compressing the directory
CPack Error: Error when generating package: myapp

with the relevant error in wix.log:

error LGHT0091 : Duplicate symbol 'Component:CM_C_EMPTY_INSTALL_ROOT' found. This typically means that an Id is duplicated. Check to make sure all your identifiers of a given type (File, Component, Feature) are unique.

files.wxs contains the following, clearly showing the duplicate components:

<DirectoryRef Id="CM_DP_Unspecified.bin">
    <Component Id="CM_CP_Unspecified.bin.wc_programmer.exe" Guid="*">
        <File Id="CM_FP_Unspecified.bin.wc_programmer.exe" Source="C:/Users/Ethan/working/wc-comm/cmake-build-release/_CPack_Packages/win32/WIX/wc-programmer-0.1.0-win32/Unspecified/bin/wc-programmer.exe" KeyPath="yes"/>
    </Component>
</DirectoryRef>
<DirectoryRef Id="INSTALL_ROOT">
    <Component Id="CM_C_EMPTY_INSTALL_ROOT" Guid="FA0B26C2-E168-4D82-89F6-638E24126BB0">
        <CreateFolder/>
    </Component>
</DirectoryRef>
<DirectoryRef Id="INSTALL_ROOT">
    <Component Id="CM_C_EMPTY_INSTALL_ROOT" Guid="71E9C0B9-8009-4A5D-9A05-CA7AAF1E69E7">
        <CreateFolder/>
    </Component>
</DirectoryRef>

It seems like the components from install commands in directories marked EXCLUDE_FROM_ALL shouldn't be in COMPONENTS. If that is expected behavior for some reason then the WIX generator should be able to handle this.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information