Skip to content

Use proper versioning on CMakeLists.txt - pkgconf versions are wrong otherwise #2310

@PerikiyoXD

Description

@PerikiyoXD

PREFACE

Bug report stacktrace (blame me)

xmake-io/xmake#4940
msys2/MINGW-packages#20581

What happens?

On MSYS2, CMake is used to build Capstone,
On ArchLinux, GNU Make is used to build Capstone.

Packaging in ArchLinux shows proper version in the pkgconf.
Packaging in MSYS2 shows bogus version in the pkgconf.

Why?

ArchLinux case

When built with GNU Make it uses pkconfig.mk to generate capstone.pc

# Package version of Capstone for Makefile.
# To be used to generate capstone.pc for pkg-config

# version major & minor 
PKG_MAJOR = 5
PKG_MINOR = 0

# version bugfix level. Example: PKG_EXTRA = 1
PKG_EXTRA = 1

# version tag. Examples: rc1, b2, post1 - or just comment out for no tag
PKG_TAG = 

If we grab out built package:
https://archlinux.org/packages/extra/x86_64/capstone/download/
It will show proper version (Extracted for convenience):

Name: capstone
Description: Capstone disassembly engine
Version: 5.0.1
libdir=/usr/lib
includedir=/usr/include/capstone
archive=${libdir}/libcapstone.a
Libs: -L${libdir} -lcapstone
Cflags: -I${includedir}
archs=arm aarch64 m68k mips powerpc sparc systemz x86 xcore tms320c64x m680x evm riscv mos65xx wasm bpf sh tricore

Version: 5.0.1
No problem for ArchLinux so far.

BUT...

MSYS case

When built with CMake it uses CMakeLists project version definition to generate capstone.pc
Here are the relevant bits:

# Version definition (Already see what happens?)
project(capstone
    VERSION 5.0
)

# Generation step (Added messages for debugging purposes)

## installation
if(CAPSTONE_INSTALL)
    include("GNUInstallDirs")

    install(FILES ${HEADERS_COMMON} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/capstone)

    message("PROJECT_VERSION_MAJOR: ${PROJECT_VERSION_MAJOR}")
    message("PROJECT_VERSION_MINOR: ${PROJECT_VERSION_MINOR}")
    message("PROJECT_VERSION_PATCH: ${PROJECT_VERSION_PATCH}")

    configure_file(capstone.pc.in ${CMAKE_BINARY_DIR}/capstone.pc @ONLY)

# All other code is irrelevant

Hmm... CMake says 5.0... It should be 5.0.1 Why?

Let's look at the generated capstone.pc!

If we grab out built package (CLANG64 variant, which is the one I found first and later confirmed it's across all MSYS2 Environments):
https://mirror.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-capstone-5.0.1-1-any.pkg.tar.zst
And see the contents of the capstone.pc:

prefix=/clang64
exec_prefix=${prefix}
libdir=/clang64/lib
includedir=/clang64/include

Name: capstone
Description: Capstone disassembly engine
Version: 5.0.
URL: https://www.capstone-engine.org/
archive=${libdir}/libcapstone.a
Libs: -L${libdir} -lcapstone
Cflags: -I${includedir}/capstone
archs=

Oh noes! It is 5.0!
But even worse, it's bogus because it's 5.0., caused by that missing variable... in CMake.

PROJECT_VERSION_PATCH wasn't defined.

It's required to use the PATCH version!

Metadata

Metadata

Assignees

No one assigned

    Labels

    build & packagingBuild system and packaging related

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions