diff --git a/CMakeLists.txt b/CMakeLists.txt index 94d6c2c..348e755 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,3 +20,25 @@ target_link_libraries(cpackexamplelib Boost::filesystem ${YAML_CPP_LIBRARIES}) DEAL_II_SETUP_TARGET("${PROJECT_NAME}") DEAL_II_SETUP_TARGET(cpackexamplelib) + +include(GNUInstallDirs) + +install(TARGETS cpackexample + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +install(TARGETS cpackexamplelib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +install(FILES + fem/fem.hpp + filesystem/filesystem.hpp + flatset/flatset.hpp + yamlParser/yamlParser.hpp + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpackexamplelib) + +# Include our packaging module +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(CPackConfig) + + diff --git a/README.md b/README.md index 8e950e4..434754d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,75 @@ # Packaging with CPack Repository for the [CPack exercise](https://github.com/Simulation-Software-Engineering/Lecture-Material/blob/main/03_building_and_packaging/cpack_exercise.md). The code is a slightly modified version of the [code used in the CMake exercise](https://github.com/Simulation-Software-Engineering/cmake-exercise). + +## How to Test the Code + +0. **Clone the directory and go inside the root of the directory** + ```bash + git clone https://github.com/jkhanGitHub/cpack-exercise-wt2526.git + cd cpack-exercise-wt2526 + ``` + +To test the changes made for the CPack exercise, follow these steps: + +1. **Build the Docker Image:** + First, build the Docker image which provides the necessary build environment. + ```bash + docker build -t cpack-exercise . + ``` + +2. **Run the Docker Container:** + Run the Docker container, mounting the current directory to `/mnt/cpack-exercise`. + ```bash + docker run --rm -it --mount type=bind,source="$(pwd)",target=/mnt/cpack-exercise cpack-exercise + ``` + inside the Docker container cd into `/mnt/cpack-exercise`. + ```bash + cd /mnt/cpack-exercise + ``` + +4. **Configure and Build the Project (Inside the Container):** + Once inside the container, configure CMake and build the project. + ```bash + cmake -B build -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release + cmake --build build + ``` + +5. **Install the Project (Inside the Container):** + Run the install target to place the executable, library, and headers in the designated installation directories. + ```bash + cmake --install build + ``` + You can verify the installation by checking the `/usr/local/bin`, `/usr/local/lib`, and `/usr/local/include/cpackexamplelib` directories. + +6. **Generate Packages (Inside the Container):** + Build the `package` target to generate both `.tar.gz` and Debian (`.deb`) packages. + ```bash + cmake --build build --target package + ``` + The generated packages will be in the `build/` directory, e.g., `cpackexample-0.1.0-Linux.tar.gz` and `cpackexample_0.1.0_amd64.deb`. + +7. **Install the Debian Package (Inside the Container):** + Install the generated Debian package using `apt`. + ```bash + apt install ./build/cpackexample_0.1.0_amd64.deb + ``` + +8. **Run the Installed Executable (Inside the Container):** + Verify that the executable is in the system's PATH and runs correctly. + ```bash + which cpackexample + cpackexample yamlParser/config.yml + ``` + The output should show the program executing its various modules. + +9. **Check the Debian Package with Lintian (Inside the Container):** + Inspect the generated Debian package for common errors and policy violations using `lintian`. + ```bash + lintian build/cpackexample_0.1.0_amd64.deb + ``` + *Note: Several warnings and errors are expected from `lintian` as per the exercise instructions, and no fixes for these were implemented as they were optional tasks.* + +## Optional Tasks + +No optional tasks were completed as part of this exercise. diff --git a/cmake/CPackConfig.cmake b/cmake/CPackConfig.cmake new file mode 100644 index 0000000..da50351 --- /dev/null +++ b/cmake/CPackConfig.cmake @@ -0,0 +1,17 @@ +set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") +set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") +set(CPACK_PACKAGE_VENDOR "Gemini") +set(CPACK_PACKAGE_CONTACT "gemini@google.com") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A CPack exercise to demonstrate packaging a C++ application.") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/Simulation-Software-Engineering/cpack-exercise-wt2526") + +set(CPACK_GENERATOR "TGZ;DEB") + +# Debian packaging section +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS YES) + +# strip really all Debug symbols +set(CPACK_STRIP_FILES TRUE) + +include(CPack)