I do not think that you can achieve that after using CPACK_SOURCE_IGNORE_FILES (although I'm not sure). As you rightly pointed out, CMake regex processing allows you to exclude groups of characters, but I don't think it allows you to negate whole patterns. [Cm. Updated answer at the end of editing.]
At the same time, I think you can list all the folders that you want to exclude into the install command. Not as reliable as an exception to everything except "projectA", but still the syntax is:
install(DIRECTORY . DESTINATION the_install_subdir REGEX "build|extrafiles|temp+" EXCLUDE)
Regarding an empty tarball, I suppose you probably have <name of my project> both your project root directory and subdir as well? Therefore, in your example, if you named your project "projectA", then you will have "projectA / build", "projectA / projectA", etc.
If so, the regex will work the full path, and therefore all files in your project will contain projectA/ in their paths.
As for crying ... well, I can only advise you to grab hold and pull yourself together !:-)
Edit: In response to the comments, here is a brief example of using install to achieve the goal:
install(DIRECTORY projectA DESTINATION the_install_subdir) install(FILES CMakeLists.txt README DESTINATION the_install_subdir)
Further editing:
Well, your example helps a lot - I really misunderstood what you are doing. I did not understand that you are actually doing two different goals ("package" and "package_source"). I thought you were creating a binary package by doing something like
cpack -G DEB
and that you created another package by running
cpack -G TGZ
Both will build a binary package. My mistake - I should have paid more attention. Excuse me!
Regarding your specific questions:
Question 1
It seems to me that setting files / directories that are not compiled, but at the same level as the folder containing all the compiled files (i.e. bin), and then ignoring the bin folder with CPACK_SOURCE_IGNORE_FILES leads to an empty tarball - this is correct ?
I believe this means: "Should set(CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}") in an empty tarball?" The answer is probably not that.
Since CPACK_SOURCE_IGNORE_FILES is a regular expression, I am sure that there are cases where the resulting regular expression can match every file in the project, and this will result in an empty tarball. However, I assume this is rather unlikely.
If instead of using the full path to the bin file via the variable ${CMAKE_BINARY_DIR} , you just had to specify the name of the folder, the probability of an empty tarball is much more. Say you call your bin dir "build" and have set(CPACK_SOURCE_IGNORE_FILES "build") . If your project lived in the word ~/test_builds/projectA , then the "assembly" of the regular expression will correspond to each file in the project, since each contains "test_builds"; the result is an empty archive.
I think this is the essence of the problem every time you create an empty tarball. No matter what the regular expression is trying to do, it actually ends in a match and excludes all files.
Question 2
It also seems that files in CMAKE_SOURCE_DIR that are not installed do not fall into the binary archive, but ultimately are in the original tarball
Yes, "package_source" is indeed another target for a binary package. By default, it contains all the files in ${CMAKE_SOURCE_DIR} , while the "package" target contains only items added with install commands. Here, the term "source files" is probably a little incorrect, as it means all the files in the source tree - not only .c, .cc, .cxx, etc.
Original question
I think there is a reasonably safe way to achieve your original goal! If you use file(GLOB ...) to create a non-recursive list of all the files / folders in your root, and then delete the ones you want to keep in the source package, you should be able to use the remaining list as the value of the regular expression CPACK_SOURCE_IGNORE_FILES :
file(GLOB SourceIgnoreFiles "${CMAKE_SOURCE_DIR}/*") set(SourceKeepFiles "${CMAKE_SOURCE_DIR}/projectA" "${CMAKE_SOURCE_DIR}/CMakeLists.txt" "${CMAKE_SOURCE_DIR}/README") list(REMOVE_ITEM SourceIgnoreFiles ${SourceKeepFiles})
Hope this works for you now. Sorry again for the incorrect instructions.