Skip to content

Commit

Permalink
cmake: Fix building capstone as sub-project (#2629)
Browse files Browse the repository at this point in the history
* cmake: Use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR

capstone can be built as sub-project through cmake's fetch_content
mechanism. In this case, `CMAKE_SOURCE_DIR` refers to the parent project
(that has nothing to do with capstone), while `PROJECT_SOURCE_DIR` refers
to the root of the capstone source tree.

Recently introduced changes to enable CPack (#2590) are using the wrong
variable and are hence breaking builds that use capstone through
fetch_content. Use the correct variable to fix this issue.

* cmake: Only include cpack in top-level builds

Do not include cpack in builds where capstone is used through
fetch_content.
  • Loading branch information
imphil authored Mar 3, 2025
1 parent cd8dd20 commit dc0c090
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -988,5 +988,7 @@ if(CAPSTONE_BUILD_CSTEST)
endif()

# Include CPack
set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackConfig.cmake")
include(CPackConfig.txt)
if(PROJECT_IS_TOP_LEVEL)
set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_SOURCE_DIR}/CPackConfig.cmake")
include(CPackConfig.txt)
endif()
12 changes: 6 additions & 6 deletions CPackConfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(CPACK_PACKAGE_DESCRIPTION "Capstone is a lightweight multi-platform, multi-a
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Lightweight multi-architecture disassembly framework - devel files")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.capstone-engine.org/")
set(CPACK_STRIP_FILES false)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSES/LICENSE.TXT")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSES/LICENSE.TXT")

# Set Debian-specific package variables
set(CPACK_DEBIAN_PACKAGE_NAME "libcapstone-dev")
Expand Down Expand Up @@ -37,17 +37,17 @@ else()
endif()

# Include additional file to run 'ldconfig' after install
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/packages/deb/triggers")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJECT_SOURCE_DIR}/packages/deb/triggers")

# RPM package settings
set(CPACK_RPM_PACKAGE_NAME "capstone-devel")
set(CPACK_RPM_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
set(CPACK_RPM_PACKAGE_REQUIRES "glibc >= 2.2.5")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packages/rpm/postinstall.sh")
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packages/rpm/postinstall.sh")
set(CPACK_RPM_CHANGELOG_FILE "${CMAKE_SOURCE_DIR}/ChangeLog")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/packages/rpm/postinstall.sh")
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/packages/rpm/postinstall.sh")
set(CPACK_RPM_CHANGELOG_FILE "${PROJECT_SOURCE_DIR}/ChangeLog")
set(CPACK_RPM_PACKAGE_LICENSE "BSD3, LLVM")
set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")

Expand All @@ -56,4 +56,4 @@ set(CPACK_DEBIAN_PACKAGE_FILE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE
set(CPACK_RPM_PACKAGE_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_DMG_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")

include(CPack)
include(CPack)

0 comments on commit dc0c090

Please # to comment.