# cpack a source archive including a specific file in root

**URL:** https://discourse.cmake.org/t/cpack-a-source-archive-including-a-specific-file-in-root/12752
**Category:** Usage
**Created:** [October 10, 2024, 4:23pm UTC](https://discourse.cmake.org/t/cpack-a-source-archive-including-a-specific-file-in-root/12752 "2024-10-10T16:23:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Gornhoth](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gornhoth/32/4998_2.png) [@Gornhoth](https://discourse.cmake.org/u/Gornhoth)
#### Post date: [October 10, 2024, 4:23pm UTC](https://discourse.cmake.org/t/cpack-a-source-archive-including-a-specific-file-in-root/12752/1 "2024-10-10T16:23:19Z")

</div>

Hey, I am trying to explicitly introduce a cpack step to package a zip-archive with all my sources. I also want to include the root CMakeLists.txt file because the entire archive is supposed to be consumed via FetchContent from other projects.  
Previously i had a custom build target that handled this but I wanted to make it explicit that this is a step a developer may want to perform. For reference, this is how I did it before:

```auto
set(PACKAGE_ZIP ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-src.zip)
set(package_files MyLibrary/ CMakeLists.txt)
add_custom_target(${PROJECT_NAME}_package ALL
	COMMAND ${CMAKE_COMMAND} -E rm -f ${PACKAGE_ZIP}
	COMMAND ${CMAKE_COMMAND} -E tar c ${PACKAGE_ZIP} --format=zip -- ${package_files}
	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
	COMMENT "Removing old zip and creating new ${PACKAGE_ZIP}"
)

```

And this is how i tried to replace it:

```auto
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-src-${PROJECT_VERSION}")
set(CPACK_VERBATIM_VARIABLES YES)
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_OVERWRITE 1)
set(CPACK_SOURCE_INSTALLED_DIRECTORIES
	"${CMAKE_CURRENT_SOURCE_DIR}/MyLibrary;MyLibrary"
)
set(CPACK_SOURCE_FILES
	"${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
include(CPack)

```

However, the root CMakeLists.txt is NOT included in the archive when i invoke it via this preset:

```auto
"packagePresets": [
	{
		"name": "default-package",
		"configurePreset": "default",
		"configFile": "CPackSourceConfig.cmake",
		"generators": ["ZIP"]
	}
],

```

How can I make the cpack call include the root CMakeLists.txt file in the zip-archive?

---

<div class="post-metadata">

### Author: ![HackingPheasant](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hackingpheasant/32/1537_2.png) [@HackingPheasant](https://discourse.cmake.org/u/HackingPheasant)
#### Post date: [October 15, 2024, 6:21am UTC](https://discourse.cmake.org/t/cpack-a-source-archive-including-a-specific-file-in-root/12752/2 "2024-10-15T06:21:37Z")

</div>

Could it be because of `CMAKE_CURRENT_SOURCE_DIR` tripping you up?

Does it function if, lets say you instead used `CMAKE_SOURCE_DIR` or `PROJECT_SOURCE_DIR`?

I’d suggest turning up the verbosity of CMake to see what it’s doing to help narrow down the issue

---

<div class="post-metadata">

### Author: ![Gornhoth](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gornhoth/32/4998_2.png) [@Gornhoth](https://discourse.cmake.org/u/Gornhoth)
#### Post date: [October 22, 2024, 11:53am UTC](https://discourse.cmake.org/t/cpack-a-source-archive-including-a-specific-file-in-root/12752/3 "2024-10-22T11:53:28Z")

</div>

Thanks for the suggestion, I saw i made a mistake because CPACK\_SOURCE\_FILES does not exist, but I found no other way in the documentation to include a single file for cpack. I also tried --verbose and --debug output with this CPACK\_SOURCE\_INSTALLED\_DIRECTORIES:

```auto
set(CPACK_SOURCE_INSTALLED_DIRECTORIES
	"${CMAKE_CURRENT_SOURCE_DIR}/my_library;my_library"
	"${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;."
)

```

and while i can see that the single file appears in the logs “CPack: /builds/cmake ci/Source/CPack/cmCPackGenerator.cxx:378 - Install directory: /home/user/Repositories/MyProject/CMakeLists.txt” it is not contained in the resulting zip.
