tar "--exclude" option not working

I am running CMake v3.20.0 and trying to do the following:

# Create .zip archive of the project
    COMMAND ${CMAKE_COMMAND} -E tar -cfv "${PROJECT_NAME}-source.tar"
        --exclude="build" -C ${CMAKE_SOURCE_DIR}/*

Unfortunately, I’m getting this error:

CMake Error: Unknown option to -E tar: --exclude=build

I tried a lot of ways of re-arranging stuff - to no avail.
The command works outside of CMake so I’m not sure what I’m doing wrong here

That’s interesting because CMake documentation (https://cmake.org/cmake/help/v3.20/manual/cmake.1.html#run-a-command-line-tool) does not list --exclude as an option. Can it be that what you’ve tried outside CMake is tar... and not cmake -E tar...?

1 Like

Hi Jakub,

I got confused between “tar” and “cmake -E tar” because I thought that they were the same thing.
Now I understand the difference in the documentation.

After removing “cmake -E”, the --exclude option worked.