Repository: argtable/argtable3
Pull request #107: build: generate .pc file and supprot cpack
Author: login: tomghuang
Created: 2025-05-22T21:12:30Z | Merged: 2025-05-23T01:00:47Z

This pull request is based on the one (https://github.com/argtable/argtable3/pull/71) from @KOLANICH, which added the `.pc` file and CPack settings. I've improve the patch so the CPack settings can follow the best practices.


Diff:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 67cee27..be45cd5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
 ################################################################################
 # This file is part of the argtable3 library.
 #
-# Copyright (C) 2016-2021 Tom G. Huang
+# Copyright (C) 2016-2025 Tom G. Huang
 # <tomghuang@gmail.com>
 # All rights reserved.
 #
@@ -30,10 +30,23 @@
 
 cmake_minimum_required(VERSION 3.5)
 
+################################################################################
+# Project metadata and build options
+################################################################################
+
 set(ARGTABLE3_PROJECT_NAME "argtable3")
 set(ARGTABLE3_PACKAGE_NAME "Argtable3")
 
 project(${ARGTABLE3_PROJECT_NAME} "C")
+set(PROJECT_DESCRIPTION "ANSI C command-line parsing library")
+set(PROJECT_HOMEPAGE_URL "https://www.argtable.org")
+set(COMPANY_NAME "The Argtable3 Project")
+set(FILE_DESC "${PROJECT_DESCRIPTION}")
+set(INTERNAL_NAME "${PROJECT_NAME}")
+set(LEGAL_COPYRIGHT "Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann. All rights reserved.")
+set(ORIGINAL_FILE_NAME "${PROJECT_NAME}")
+set(PRODUCT_NAME "${PROJECT_NAME}")
+set(MAINTAINER_CONTACT "tomghuang@gmail.com")
 
 option(BUILD_SHARED_LIBS "Build shared library" OFF)
 option(ARGTABLE3_ENABLE_CONAN "Enable Conan dependency manager" OFF)
@@ -43,9 +56,16 @@ option(ARGTABLE3_ENABLE_ARG_REX_DEBUG "Enable arg_rex debug output" OFF)
 option(ARGTABLE3_REPLACE_GETOPT "Replace getopt in the system C library" ON)
 option(ARGTABLE3_LONG_ONLY "Use getopt_long_only instead of getopt_long" OFF)
 
+include(GNUInstallDirs)
+
+################################################################################
+# Version handling: read from version.tag if present, otherwise use defaults.
+# version.tag format: major.minor.patch.build (e.g., 3.2.1.0)
+################################################################################
+
 get_filename_component(VERSION_TAG_PATH "version.tag" ABSOLUTE)
-if(EXISTS ${VERSION_TAG_PATH})
-  file(READ version.tag VERSION_TAG OFFSET 1)
+if(EXISTS "${VERSION_TAG_PATH}")
+  file(READ "${VERSION_TAG_PATH}" VERSION_TAG OFFSET 1) # Skip the first "v" character.
   string(REPLACE "." ";" VERSION_LIST ${VERSION_TAG})
   list(GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
   list(GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
@@ -57,9 +77,14 @@ else()
   set(PROJECT_VERSION_PATCH 0)
   set(PROJECT_VERSION_BUILD "mainline")
 endif()
+set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
 set(PROJECT_VERSION_TWEAK 0)
-set(ARGTABLE3_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK})
-set(ARGTABLE3_FULL_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_BUILD})
+set(ARGTABLE3_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}")
+set(ARGTABLE3_FULL_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_BUILD}")
+
+################################################################################
+# Conan dependency manager integration (optional)
+################################################################################
 
 if(ARGTABLE3_ENABLE_CONAN AND EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
   include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
@@ -69,6 +94,10 @@ if(ARGTABLE3_ENABLE_CONAN AND EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,${LINK_FLAGS}")
 endif()
 
+################################################################################
+# Source files for the argtable3 library
+################################################################################
+
 set(ARGTABLE3_AMALGAMATION_SRC_FILE ${PROJECT_SOURCE_DIR}/dist/argtable3.c)
 set(ARGTABLE3_SRC_FILES
   ${PROJECT_SOURCE_DIR}/src/arg_cmd.c
@@ -88,10 +117,26 @@ set(ARGTABLE3_SRC_FILES
   ${PROJECT_SOURCE_DIR}/src/arg_getopt_long.c
 )
 
+################################################################################
+# Packaging configuration (CPack)
+################################################################################
+
+set(PackagingTemplatesDir "${CMAKE_CURRENT_SOURCE_DIR}/packaging")
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
+set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
+
+################################################################################
+# Platform-specific settings
+################################################################################
+
 if(APPLE)
   set(CMAKE_MACOSX_RPATH ON)
 endif()
 
+################################################################################
+# Add subdirectories for library, examples, and tests
+################################################################################
+
 add_subdirectory(src)
 
 if(ARGTABLE3_ENABLE_EXAMPLES)
@@ -102,3 +147,51 @@ if(ARGTABLE3_ENABLE_TESTS)
   enable_testing()
   add_subdirectory(tests)
 endif()
+
+################################################################################
+# Pkg-config file generation and installation
+################################################################################
+
+set(PKG_CONFIG_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
+configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
+install(FILES "${PKG_CONFIG_FILE_NAME}"
+	DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
+)
+
+################################################################################
+# Packaging (CPack) configuration
+################################################################################
+
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
+set(CPACK_PACKAGE_VENDOR "${COMPANY_NAME}")
+set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
+set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
+set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
+set(CPACK_PACKAGE_CONTACT "${MAINTAINER_CONTACT}")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CPACK_RESOURCE_FILE_README}")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION}")
+
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}")
+set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev")
+set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
+set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6-dev")
+set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config")
+set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}")
+
+set(CPACK_RPM_PACKAGE_NAME "lib${PROJECT_NAME}-devel")
+set(CPACK_RPM_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}")
+set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
+set(CPACK_RPM_PACKAGE_URL "${CPACK_PACKAGE_HOMEPAGE_URL}")
+set(CPACK_RPM_PACKAGE_RELEASE 1)
+
+set(CPACK_DEB_COMPONENT_INSTALL ON)
+set(CPACK_RPM_COMPONENT_INSTALL ON)
+set(CPACK_NSIS_COMPONENT_INSTALL ON)
+set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
+
+################################################################################
+# Enable CPack
+################################################################################
+
+include(CPack)
diff --git a/packaging/pkgconfig.pc.in b/packaging/pkgconfig.pc.in
new file mode 100644
index 0000000..ffbb893
--- /dev/null
+++ b/packaging/pkgconfig.pc.in
@@ -0,0 +1,9 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+
+Name: @PROJECT_NAME@
+Description: @PROJECT_DESCRIPTION@
+Version: @PROJECT_VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -l@PROJECT_NAME@ -lm
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 22bbc7f..8ea5334 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,7 +1,7 @@
 ################################################################################
 # This file is part of the argtable3 library.
 #
-# Copyright (C) 2016-2021 Tom G. Huang
+# Copyright (C) 2016-2025 Tom G. Huang
 # <tomghuang@gmail.com>
 # All rights reserved.
 #
@@ -28,6 +28,10 @@
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ################################################################################
 
+################################################################################
+# Compiler and build options
+################################################################################
+
 if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4820")
@@ -62,13 +66,10 @@ endif()
 
 add_definitions(-D_XOPEN_SOURCE=700)
 
-if(BUILD_SHARED_LIBS AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"))
-  set(COMPANY_NAME "The Argtable3 Project")
-  set(FILE_DESC "ANSI C command-line parsing library")
-  set(INTERNAL_NAME "${PROJECT_NAME}")
-  set(LEGAL_COPYRIGHT "Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann. All rights reserved.")
-  set(ORIGINAL_FILE_NAME "${PROJECT_NAME}")
-  set(PRODUCT_NAME "${PROJECT_NAME}")
+################################################################################
+# Library target definition
+################################################################################
+if(BUILD_SHARED_LIBS AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC"))
   configure_file(
     "${PROJECT_SOURCE_DIR}/src/version.rc.in"
     "${PROJECT_BINARY_DIR}/src/version.rc"
@@ -86,12 +87,16 @@ target_include_directories(argtable3 PUBLIC
 )
 
 set_target_properties(argtable3 PROPERTIES
-  VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
-  SOVERSION ${PROJECT_VERSION_MAJOR}
+  VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
+  SOVERSION "${PROJECT_VERSION_MAJOR}"
   DEBUG_POSTFIX "d"
+  PUBLIC_HEADER "${PROJECT_SOURCE_DIR}/src/argtable3.h"
 )
 
-include(GNUInstallDirs)
+################################################################################
+# Install rules
+################################################################################
+
 if(UNIX OR MSYS OR MINGW OR PSP)
   set(ARGTABLE3_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/argtable3)
 elseif(WIN32)
@@ -100,14 +105,10 @@ endif()
 
 install(TARGETS argtable3
   EXPORT ${ARGTABLE3_PACKAGE_NAME}Config
-  INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
   RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
   LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
   ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
-)
-
-install(FILES "${PROJECT_SOURCE_DIR}/src/argtable3.h"
-  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+  PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
 )
 
 install(EXPORT ${ARGTABLE3_PACKAGE_NAME}Config


Reviews:
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This pull request enhances the build system for argtable3 by introducing pkg-config (.pc) file generation and improved CPack packaging configuration while updating project metadata.  
- Updated copyright information  
- Added a metadata block in src/CMakeLists.txt and integrated CPACK packaging settings  
- Improved version handling and metadata configuration in the root CMakeLists.txt

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

| File                       | Description                                                            |
| -------------------------- | ---------------------------------------------------------------------- |
| src/CMakeLists.txt         | Adds project metadata, install rules updates, and CPACK integration    |
| packaging/pkgconfig.pc.in  | Introduces a new pkg-config template for packaging                     |
| CMakeLists.txt             | Updates project metadata, version handling, and packaging configuration |


<details>
<summary>Comments suppressed due to low confidence (1)</summary>

**src/CMakeLists.txt:107**
* [nitpick] Confirm that the public header path is correct and aligns with the intended installation layout for users of the library.
```
PUBLIC_HEADER "${PROJECT_SOURCE_DIR}/src/argtable3.h"
```
</details>


state: COMMENTED
author_association: NONE
submitted_at: 2025-05-22T21:14:18Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-22T23:10:22Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

Adds full packaging support including a pkg-config `.pc` file and CPack configuration to streamline distribution.

- Introduces CPack settings and version/metadata handling in both root and `src` CMakeLists.
- Generates and installs `argtable3.pc` via a new `pkgconfig.pc.in` template.
- Updates install rules to use `PUBLIC_HEADER` and bumps copyright years.

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

| File                      | Description                                                |
|---------------------------|------------------------------------------------------------|
| src/CMakeLists.txt        | Added install rules, CPack configuration, and pkg-config generation. |
| packaging/pkgconfig.pc.in | New pkg-config template for `argtable3.pc`.                |
| CMakeLists.txt            | Defined project metadata, version parsing, and packaging scaffolding. |


<details>
<summary>Comments suppressed due to low confidence (2)</summary>

**src/CMakeLists.txt:67**
* [nitpick] Instead of the global `add_definitions`, it’s more modern to use `target_compile_definitions(argtable3 PUBLIC -D_XOPEN_SOURCE=700)` to scope the macro to the target.
```
add_definitions(-D_XOPEN_SOURCE=700)
```
**CMakeLists.txt:44**
* [nitpick] Variables like `FILE_DESC`, `INTERNAL_NAME`, `ORIGINAL_FILE_NAME`, and `PRODUCT_NAME` are set here but never used; consider removing them to keep the project configuration clean.
```
set(FILE_DESC "${PROJECT_DESCRIPTION}")
```
</details>


state: COMMENTED
author_association: NONE
submitted_at: 2025-05-22T23:18:12Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-22T23:56:50Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This PR enhances the build configuration by updating metadata, introducing CPACK packaging support, and generating a pkg-config file. Key changes include:
- Updating copyright dates.
- Refactoring build and installation rules with added CPACK settings.
- Adding project metadata and version handling in the root CMakeLists.txt.

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

| File                    | Description                                                          |
| ----------------------- | -------------------------------------------------------------------- |
| src/CMakeLists.txt      | Updated for CPACK integration, installation improvements, and metadata refactoring. |
| packaging/pkgconfig.pc.in | New pkg-config template for library packaging.                      |
| CMakeLists.txt          | Enhanced project metadata, version handling, and packaging configuration.  |


<details>
<summary>Comments suppressed due to low confidence (1)</summary>

**src/CMakeLists.txt:167**
* [nitpick] Consider verifying that PackagingTemplatesDir is valid and accessible to prevent potential configuration errors during pkg-config file generation.
```
configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
```
</details>


state: COMMENTED
author_association: NONE
submitted_at: 2025-05-22T23:58:16Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:07:38Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:10:13Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This PR enhances the build configuration by generating a .pc file and improving the CPack settings to better follow best practices.  
- Updates copyright year to 2025.  
- Adds compiler/build options and installs a public header for the library.  
- Introduces comprehensive CPack packaging configuration and pkg-config file generation.

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

| File                     | Description                                                           |
| ------------------------ | --------------------------------------------------------------------- |
| src/CMakeLists.txt       | Updates copyright, build options, and packaging configuration.        |
| packaging/pkgconfig.pc.in| Adds the template file for generating the pkg-config (.pc) file.       |
| CMakeLists.txt           | Sets project metadata, version handling, and integrates packaging and Conan configuration. |




state: COMMENTED
author_association: NONE
submitted_at: 2025-05-23T00:11:08Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:16:22Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This PR adds pkg-config file generation and CPack packaging support while updating project metadata and install rules.

- Extended project metadata and version handling for packaging
- Introduced CPack configuration in the library’s CMakeLists
- Added a `pkgconfig.pc.in` template and install rules for a `.pc` file

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

| File                        | Description                                                                                      |
| --------------------------- | ------------------------------------------------------------------------------------------------ |
| src/CMakeLists.txt          | Added CPack configuration, pkg-config generation, updated install rules, and public header setup |
| packaging/pkgconfig.pc.in   | New pkg-config template for generating the `.pc` file                                            |
| CMakeLists.txt              | Defined project metadata, version parsing, and CPack resource file variables                     |


<details>
<summary>Comments suppressed due to low confidence (1)</summary>

**src/CMakeLists.txt:166**
* [nitpick] Consider adding CI or local tests to verify that the `.pc` file is generated correctly and that CPack packaging outputs match expectations.
```
set(PKG_CONFIG_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
```
</details>


state: COMMENTED
author_association: NONE
submitted_at: 2025-05-23T00:19:14Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:24:12Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:32:31Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:33:24Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This PR enhances the build system by adding pkg-config file generation and CPack packaging support, while updating metadata and install rules.

- Generate a `.pc` file from a template and install it under `lib/pkgconfig`
- Introduce CPack configuration with Debian and RPM settings
- Update CMake metadata, version handling, and modernize install directives

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

| File                   | Description                                                   |
| ---------------------- | ------------------------------------------------------------- |
| src/CMakeLists.txt     | Reorganized MSVC resource generation, updated target properties, and refined install rules |
| packaging/pkgconfig.pc.in | New pkg-config template defining prefix, include/lib dirs, and basic flags |
| CMakeLists.txt         | Expanded project metadata, version parsing, added CPack and pkg-config integration |


<details>
<summary>Comments suppressed due to low confidence (2)</summary>

**src/CMakeLists.txt:67**
* Instead of global add_definitions, prefer target_compile_definitions(argtable3 PRIVATE XOPEN_SOURCE=700) for a modern, target-scoped approach.
```
add_definitions(-D_XOPEN_SOURCE=700)
```
**CMakeLists.txt:122**
* [nitpick] Variable names in CMake are typically uppercase with underscores. Rename PackagingTemplatesDir to PACKAGING_TEMPLATES_DIR for consistency.
```
set(PackagingTemplatesDir "${CMAKE_CURRENT_SOURCE_DIR}/packaging")
```
</details>


state: COMMENTED
author_association: NONE
submitted_at: 2025-05-23T00:34:41Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:37:08Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

Adds pkg-config file generation and CPack packaging support, and improves CMake install/export rules for the argtable3 library.

- Refactors `src/CMakeLists.txt` to use `PUBLIC_HEADER`, quotes version properties, and reorganizes install rules.
- Introduces `packaging/pkgconfig.pc.in` and integrates `.pc` file generation in the top-level CMake build.
- Adds comprehensive CPack configuration for Debian, RPM, NSIS, and generic packaging.

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

| File                             | Description                                          |
|----------------------------------|------------------------------------------------------|
| src/CMakeLists.txt               | Structured compiler options and install rules        |
| packaging/pkgconfig.pc.in        | New pkg-config template                              |
| CMakeLists.txt                   | Top-level metadata, version parsing, pkg-config & CPack |


<details>
<summary>Comments suppressed due to low confidence (2)</summary>

**CMakeLists.txt:122**
* [nitpick] The variable `PackagingTemplatesDir` uses camelCase but most CMake variables follow an uppercase snake_case style. Consider renaming it to `PACKAGING_TEMPLATES_DIR` for consistency.
```
set(PackagingTemplatesDir "${CMAKE_CURRENT_SOURCE_DIR}/packaging")
```
**CMakeLists.txt:154**
* [nitpick] The new pkg-config generation logic isn't covered by existing tests. Consider adding a CTest or CI check to verify that the generated `.pc` file contains the expected prefix, version, and paths.
```
configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
```
</details>


state: COMMENTED
author_association: NONE
submitted_at: 2025-05-23T00:41:26Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:43:38Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:50:23Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T00:59:09Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This pull request improves the build system by generating a pkg-config (.pc) file and refining the CPack configuration to follow best practices.  
- Updated copyright notices  
- Enhanced CMakeLists.txt with improved compiler/build options and packaging settings  
- Added a new pkg-config template file for proper pkg-config file generation

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

| File                       | Description                                                                |
| -------------------------- | -------------------------------------------------------------------------- |
| src/CMakeLists.txt         | Updated compiler/build sections and shared library install rules           |
| packaging/pkgconfig.pc.in  | Added a new pkg-config template file                                       |
| CMakeLists.txt             | Enhanced project metadata, version handling, packaging configuration, and CPack settings |




state: COMMENTED
author_association: NONE
submitted_at: 2025-05-23T00:59:47Z
user: login: tomghuang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-23T01:00:23Z

Review comments:
diff_hunk: @@ -30,10 +30,16 @@
 
 cmake_minimum_required(VERSION 3.5)
 
+################################################################################
+# Project metadata and build options
+################################################################################
+
 set(ARGTABLE3_PROJECT_NAME "argtable3")
 set(ARGTABLE3_PACKAGE_NAME "Argtable3")
 
 project(${ARGTABLE3_PROJECT_NAME} "C")
+set(PROJECT_DESCRIPTION "ANSI C command-line parsing library")
path: CMakeLists.txt
user: login: Copilot
body: Consider consolidating project metadata definitions into a single location to reduce duplication between the root and src/CMakeLists.txt files.
created_at: 2025-05-22T21:14:18Z
author_association: NONE
diff_hunk: @@ -30,10 +30,16 @@
 
 cmake_minimum_required(VERSION 3.5)
 
+################################################################################
+# Project metadata and build options
+################################################################################
+
 set(ARGTABLE3_PROJECT_NAME "argtable3")
 set(ARGTABLE3_PACKAGE_NAME "Argtable3")
 
 project(${ARGTABLE3_PROJECT_NAME} "C")
+set(PROJECT_DESCRIPTION "ANSI C command-line parsing library")
path: CMakeLists.txt
user: login: tomghuang
body: I've consolidated project metadata definitions into the main `CMakeLists.txt`. Please help to check again.
created_at: 2025-05-22T23:10:21Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,7 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+
+Name: @PROJECT_NAME@
+Description: @PROJECT_DESCRIPTION@
+Version: @PROJECT_VERSION@
+Cflags: -I${includedir}
path: packaging/pkgconfig.pc.in
user: login: Copilot
body: The pkg-config file is missing a `Libs:` entry. You should add something like `Libs: -L${libdir} -l${PROJECT_NAME}` so that consumers can correctly link against argtable3.
```suggestion
Cflags: -I${includedir}
Libs: -L${libdir} -l@PROJECT_NAME@
```
created_at: 2025-05-22T23:18:12Z
author_association: NONE
diff_hunk: @@ -0,0 +1,7 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+
+Name: @PROJECT_NAME@
+Description: @PROJECT_DESCRIPTION@
+Version: @PROJECT_VERSION@
+Cflags: -I${includedir}
path: packaging/pkgconfig.pc.in
user: login: tomghuang
body: I've done the improvement, so pkg-config can provide libs command-line options now.
created_at: 2025-05-22T23:56:50Z
author_association: CONTRIBUTOR
diff_hunk: @@ -43,9 +56,14 @@ option(ARGTABLE3_ENABLE_ARG_REX_DEBUG "Enable arg_rex debug output" OFF)
 option(ARGTABLE3_REPLACE_GETOPT "Replace getopt in the system C library" ON)
 option(ARGTABLE3_LONG_ONLY "Use getopt_long_only instead of getopt_long" OFF)
 
+################################################################################
+# Version handling: read from version.tag if present, otherwise use defaults.
+# version.tag format: major.minor.patch.build (e.g., 3.2.1.0)
+################################################################################
+
 get_filename_component(VERSION_TAG_PATH "version.tag" ABSOLUTE)
-if(EXISTS ${VERSION_TAG_PATH})
-  file(READ version.tag VERSION_TAG OFFSET 1)
+if(EXISTS "${VERSION_TAG_PATH}")
+  file(READ "${VERSION_TAG_PATH}" VERSION_TAG OFFSET 1)
path: CMakeLists.txt
user: login: Copilot
body: [nitpick] Add a comment explaining the use of OFFSET 1 when reading version.tag to clarify its purpose.
created_at: 2025-05-22T23:58:15Z
author_association: NONE
diff_hunk: @@ -124,3 +126,51 @@ write_basic_package_version_file("${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME
 install(FILES "${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME}ConfigVersion.cmake"
   DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR}
 )
+
+################################################################################
+# Packaging (CPack) configuration
+################################################################################
+
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
path: src/CMakeLists.txt
user: login: Copilot
body: [nitpick] Ensure that COMPANY_NAME is consistently defined across all CMakeLists files to avoid discrepancies in CPACK packaging metadata.
```suggestion
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(COMPANY_NAME "YourCompanyName")
```
created_at: 2025-05-22T23:58:15Z
author_association: NONE
diff_hunk: @@ -124,3 +126,51 @@ write_basic_package_version_file("${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME
 install(FILES "${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME}ConfigVersion.cmake"
   DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR}
 )
+
+################################################################################
+# Packaging (CPack) configuration
+################################################################################
+
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
path: src/CMakeLists.txt
user: login: tomghuang
body: The `COMPANY_NAME` is defined in the main `CMakeLists.txt`, which is shared by all CMake scripts in sub-directories, so it should be fine.
created_at: 2025-05-23T00:07:38Z
author_association: CONTRIBUTOR
diff_hunk: @@ -43,9 +56,14 @@ option(ARGTABLE3_ENABLE_ARG_REX_DEBUG "Enable arg_rex debug output" OFF)
 option(ARGTABLE3_REPLACE_GETOPT "Replace getopt in the system C library" ON)
 option(ARGTABLE3_LONG_ONLY "Use getopt_long_only instead of getopt_long" OFF)
 
+################################################################################
+# Version handling: read from version.tag if present, otherwise use defaults.
+# version.tag format: major.minor.patch.build (e.g., 3.2.1.0)
+################################################################################
+
 get_filename_component(VERSION_TAG_PATH "version.tag" ABSOLUTE)
-if(EXISTS ${VERSION_TAG_PATH})
-  file(READ version.tag VERSION_TAG OFFSET 1)
+if(EXISTS "${VERSION_TAG_PATH}")
+  file(READ "${VERSION_TAG_PATH}" VERSION_TAG OFFSET 1)
path: CMakeLists.txt
user: login: tomghuang
body: Done. I've added a comment explaining the purpose of this statement.
created_at: 2025-05-23T00:10:13Z
author_association: CONTRIBUTOR
diff_hunk: @@ -124,3 +126,51 @@ write_basic_package_version_file("${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME
 install(FILES "${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME}ConfigVersion.cmake"
   DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR}
 )
+
+################################################################################
+# Packaging (CPack) configuration
+################################################################################
+
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
+set(CPACK_PACKAGE_VENDOR "${COMPANY_NAME}")
+set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
+set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
+set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
+set(CPACK_PACKAGE_CONTACT "${MAINTAINER_CONTACT}")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CPACK_RESOURCE_FILE_README}")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION}")
+
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}")
+set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev")
+set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
+set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6-dev")
+set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config, pkg-conf")
path: src/CMakeLists.txt
user: login: Copilot
body: There appears to be a typo in the CPACK_DEBIAN_PACKAGE_SUGGESTS value. Consider replacing 'pkg-conf' with 'pkg-config' for consistency.
```suggestion
set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config")
```
created_at: 2025-05-23T00:11:08Z
author_association: NONE
diff_hunk: @@ -124,3 +126,51 @@ write_basic_package_version_file("${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME
 install(FILES "${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME}ConfigVersion.cmake"
   DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR}
 )
+
+################################################################################
+# Packaging (CPack) configuration
+################################################################################
+
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
+set(CPACK_PACKAGE_VENDOR "${COMPANY_NAME}")
+set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
+set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
+set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
+set(CPACK_PACKAGE_CONTACT "${MAINTAINER_CONTACT}")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CPACK_RESOURCE_FILE_README}")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION}")
+
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}")
+set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev")
+set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
+set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6-dev")
+set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config, pkg-conf")
path: src/CMakeLists.txt
user: login: tomghuang
body: Done. I've removed the unnecessary `pkg-conf` package.
created_at: 2025-05-23T00:16:22Z
author_association: CONTRIBUTOR
diff_hunk: @@ -124,3 +126,51 @@ write_basic_package_version_file("${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME
 install(FILES "${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME}ConfigVersion.cmake"
   DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR}
 )
+
+################################################################################
+# Packaging (CPack) configuration
path: src/CMakeLists.txt
user: login: Copilot
body: [nitpick] Consider moving the CPack packaging logic from `src/CMakeLists.txt` into the top-level `CMakeLists.txt` to centralize and simplify packaging configuration.
created_at: 2025-05-23T00:19:13Z
author_association: NONE
diff_hunk: @@ -30,10 +30,23 @@
 
 cmake_minimum_required(VERSION 3.5)
 
+################################################################################
+# Project metadata and build options
+################################################################################
+
 set(ARGTABLE3_PROJECT_NAME "argtable3")
 set(ARGTABLE3_PACKAGE_NAME "Argtable3")
 
 project(${ARGTABLE3_PROJECT_NAME} "C")
+set(PROJECT_DESCRIPTION "ANSI C command-line parsing library")
+set(PROJECT_HOMEPAGE_URL "https://www.argtable.org")
+set(COMPANY_NAME "The Argtable3 Project")
+set(FILE_DESC "${PROJECT_DESCRIPTION}")
+set(INTERNAL_NAME "${PROJECT_NAME}")
+set(LEGAL_COPYRIGHT "Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann. All rights reserved.")
+set(ORIGINAL_FILE_NAME "${PROJECT_NAME}")
+set(PRODUCT_NAME "${PROJECT_NAME}")
path: CMakeLists.txt
user: login: Copilot
body: [nitpick] The variables `FILE_DESC`, `INTERNAL_NAME`, `ORIGINAL_FILE_NAME`, and `PRODUCT_NAME` are defined but not evidently used in this scope; consider removing or relocating them closer to their consumers (e.g., `version.rc.in`).
```suggestion
# set(FILE_DESC "${PROJECT_DESCRIPTION}")
# set(INTERNAL_NAME "${PROJECT_NAME}")
set(LEGAL_COPYRIGHT "Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann. All rights reserved.")
# set(ORIGINAL_FILE_NAME "${PROJECT_NAME}")
# set(PRODUCT_NAME "${PROJECT_NAME}")
```
created_at: 2025-05-23T00:19:13Z
author_association: NONE
diff_hunk: @@ -0,0 +1,9 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+
+Name: @PROJECT_NAME@
+Description: @PROJECT_DESCRIPTION@
+Version: @PROJECT_VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -l@PROJECT_NAME@ -lm
path: packaging/pkgconfig.pc.in
user: login: Copilot
body: [nitpick] The `-lm` link flag may be unnecessary if the library doesn't use math functions; consider removing it or documenting why it's required.
```suggestion
Libs: -L${libdir} -l@PROJECT_NAME@ -lm # The -lm flag links the math library. Remove if math functions are not used.
```
created_at: 2025-05-23T00:19:14Z
author_association: NONE
diff_hunk: @@ -30,10 +30,23 @@
 
 cmake_minimum_required(VERSION 3.5)
 
+################################################################################
+# Project metadata and build options
+################################################################################
+
 set(ARGTABLE3_PROJECT_NAME "argtable3")
 set(ARGTABLE3_PACKAGE_NAME "Argtable3")
 
 project(${ARGTABLE3_PROJECT_NAME} "C")
+set(PROJECT_DESCRIPTION "ANSI C command-line parsing library")
+set(PROJECT_HOMEPAGE_URL "https://www.argtable.org")
+set(COMPANY_NAME "The Argtable3 Project")
+set(FILE_DESC "${PROJECT_DESCRIPTION}")
+set(INTERNAL_NAME "${PROJECT_NAME}")
+set(LEGAL_COPYRIGHT "Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann. All rights reserved.")
+set(ORIGINAL_FILE_NAME "${PROJECT_NAME}")
+set(PRODUCT_NAME "${PROJECT_NAME}")
path: CMakeLists.txt
user: login: tomghuang
body: Copilot within VSCode suggests that I should put all the metadata definitions together. That's why I put these variables in the main `CMakeLists.txt` file. I will keep it in the current way.
created_at: 2025-05-23T00:24:12Z
author_association: CONTRIBUTOR
diff_hunk: @@ -124,3 +126,51 @@ write_basic_package_version_file("${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME
 install(FILES "${PROJECT_BINARY_DIR}/${ARGTABLE3_PACKAGE_NAME}ConfigVersion.cmake"
   DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR}
 )
+
+################################################################################
+# Packaging (CPack) configuration
path: src/CMakeLists.txt
user: login: tomghuang
body: Done. I've moved both the CPack logic and pkg-config logic to the main `CMakeLists.txt` file.
created_at: 2025-05-23T00:32:31Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,9 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+
+Name: @PROJECT_NAME@
+Description: @PROJECT_DESCRIPTION@
+Version: @PROJECT_VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -l@PROJECT_NAME@ -lm
path: packaging/pkgconfig.pc.in
user: login: tomghuang
body: The library does use the `ceil` function. That's why it needs the `-lm` command-line option.
created_at: 2025-05-23T00:33:24Z
author_association: CONTRIBUTOR
diff_hunk: @@ -62,13 +66,10 @@ endif()
 
 add_definitions(-D_XOPEN_SOURCE=700)
 
-if(BUILD_SHARED_LIBS AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"))
-  set(COMPANY_NAME "The Argtable3 Project")
-  set(FILE_DESC "ANSI C command-line parsing library")
-  set(INTERNAL_NAME "${PROJECT_NAME}")
-  set(LEGAL_COPYRIGHT "Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann. All rights reserved.")
-  set(ORIGINAL_FILE_NAME "${PROJECT_NAME}")
-  set(PRODUCT_NAME "${PROJECT_NAME}")
+################################################################################
+# Library target definition
+################################################################################
+if(BUILD_SHARED_LIBS AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC"))
path: src/CMakeLists.txt
user: login: Copilot
body: The generated version.rc file isn’t added to the argtable3 target, so the resource won’t be compiled into the library. Consider adding it via target_sources(argtable3 PRIVATE "${PROJECT_BINARY_DIR}/src/version.rc").
created_at: 2025-05-23T00:34:40Z
author_association: NONE
diff_hunk: @@ -62,13 +66,10 @@ endif()
 
 add_definitions(-D_XOPEN_SOURCE=700)
 
-if(BUILD_SHARED_LIBS AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"))
-  set(COMPANY_NAME "The Argtable3 Project")
-  set(FILE_DESC "ANSI C command-line parsing library")
-  set(INTERNAL_NAME "${PROJECT_NAME}")
-  set(LEGAL_COPYRIGHT "Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann. All rights reserved.")
-  set(ORIGINAL_FILE_NAME "${PROJECT_NAME}")
-  set(PRODUCT_NAME "${PROJECT_NAME}")
+################################################################################
+# Library target definition
+################################################################################
+if(BUILD_SHARED_LIBS AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC"))
path: src/CMakeLists.txt
user: login: tomghuang
body: The `version.rc` file is only needed when we need to build a DLL library under Windows. Therefore, the current implementation should be fine.
created_at: 2025-05-23T00:37:07Z
author_association: CONTRIBUTOR
diff_hunk: @@ -43,9 +56,14 @@ option(ARGTABLE3_ENABLE_ARG_REX_DEBUG "Enable arg_rex debug output" OFF)
 option(ARGTABLE3_REPLACE_GETOPT "Replace getopt in the system C library" ON)
 option(ARGTABLE3_LONG_ONLY "Use getopt_long_only instead of getopt_long" OFF)
 
+################################################################################
+# Version handling: read from version.tag if present, otherwise use defaults.
+# version.tag format: major.minor.patch.build (e.g., 3.2.1.0)
+################################################################################
+
 get_filename_component(VERSION_TAG_PATH "version.tag" ABSOLUTE)
-if(EXISTS ${VERSION_TAG_PATH})
-  file(READ version.tag VERSION_TAG OFFSET 1)
+if(EXISTS "${VERSION_TAG_PATH}")
+  file(READ "${VERSION_TAG_PATH}" VERSION_TAG OFFSET 1) # Skip the first "v" character.
path: CMakeLists.txt
user: login: Copilot
body: Reading the entire file with OFFSET 1 will include a trailing newline in VERSION_TAG, which can break parsing. Consider running `string(STRIP "${VERSION_TAG}" VERSION_TAG)` before splitting or use `file(STRINGS)` to strip whitespace.
```suggestion
  file(READ "${VERSION_TAG_PATH}" VERSION_TAG OFFSET 1) # Skip the first "v" character.
  string(STRIP "${VERSION_TAG}" VERSION_TAG) # Remove any trailing newline or whitespace.
```
created_at: 2025-05-23T00:41:25Z
author_association: NONE
diff_hunk: @@ -102,3 +145,51 @@ if(ARGTABLE3_ENABLE_TESTS)
   enable_testing()
   add_subdirectory(tests)
 endif()
+
+################################################################################
+# Pkg-config file generation and installation
+################################################################################
+
+set(PKG_CONFIG_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
+configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
+install(FILES "${PKG_CONFIG_FILE_NAME}"
+	DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
+)
+
+################################################################################
+# Packaging (CPack) configuration
+################################################################################
+
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
+set(CPACK_PACKAGE_VENDOR "${COMPANY_NAME}")
+set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
+set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
+set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
+set(CPACK_PACKAGE_CONTACT "${MAINTAINER_CONTACT}")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CPACK_RESOURCE_FILE_README}")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION}")
+
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}")
path: CMakeLists.txt
user: login: Copilot
body: Debian policy expects the package maintainer field to include an email address rather than the vendor name. You should set `CPACK_DEBIAN_PACKAGE_MAINTAINER` to `${CPACK_PACKAGE_CONTACT}` (or `MAINTAINER_CONTACT`) instead of `${CPACK_PACKAGE_MAINTAINER}`.
```suggestion
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_CONTACT}")
```
created_at: 2025-05-23T00:41:26Z
author_association: NONE
diff_hunk: @@ -102,3 +145,51 @@ if(ARGTABLE3_ENABLE_TESTS)
   enable_testing()
   add_subdirectory(tests)
 endif()
+
+################################################################################
+# Pkg-config file generation and installation
+################################################################################
+
+set(PKG_CONFIG_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
+configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
+install(FILES "${PKG_CONFIG_FILE_NAME}"
path: CMakeLists.txt
user: login: Copilot
body: [nitpick] It’s more clear to include `include(GNUInstallDirs)` at the top-level `CMakeLists.txt` so that `CMAKE_INSTALL_LIBDIR` and `CMAKE_INSTALL_INCLUDEDIR` are defined project-wide, rather than relying on the `src` subdirectory to load it.
created_at: 2025-05-23T00:41:26Z
author_association: NONE
diff_hunk: @@ -43,9 +56,14 @@ option(ARGTABLE3_ENABLE_ARG_REX_DEBUG "Enable arg_rex debug output" OFF)
 option(ARGTABLE3_REPLACE_GETOPT "Replace getopt in the system C library" ON)
 option(ARGTABLE3_LONG_ONLY "Use getopt_long_only instead of getopt_long" OFF)
 
+################################################################################
+# Version handling: read from version.tag if present, otherwise use defaults.
+# version.tag format: major.minor.patch.build (e.g., 3.2.1.0)
+################################################################################
+
 get_filename_component(VERSION_TAG_PATH "version.tag" ABSOLUTE)
-if(EXISTS ${VERSION_TAG_PATH})
-  file(READ version.tag VERSION_TAG OFFSET 1)
+if(EXISTS "${VERSION_TAG_PATH}")
+  file(READ "${VERSION_TAG_PATH}" VERSION_TAG OFFSET 1) # Skip the first "v" character.
path: CMakeLists.txt
user: login: tomghuang
body: The content of `version.tag` is generated by scripts, so it won't have whitespace issue.
created_at: 2025-05-23T00:43:38Z
author_association: CONTRIBUTOR
diff_hunk: @@ -102,3 +145,51 @@ if(ARGTABLE3_ENABLE_TESTS)
   enable_testing()
   add_subdirectory(tests)
 endif()
+
+################################################################################
+# Pkg-config file generation and installation
+################################################################################
+
+set(PKG_CONFIG_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
+configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
+install(FILES "${PKG_CONFIG_FILE_NAME}"
+	DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
+)
+
+################################################################################
+# Packaging (CPack) configuration
+################################################################################
+
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
+set(CPACK_PACKAGE_VENDOR "${COMPANY_NAME}")
+set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
+set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
+set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
+set(CPACK_PACKAGE_CONTACT "${MAINTAINER_CONTACT}")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CPACK_RESOURCE_FILE_README}")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION}")
+
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}")
path: CMakeLists.txt
user: login: tomghuang
body: The current practice should be fine.
created_at: 2025-05-23T00:50:23Z
author_association: CONTRIBUTOR
diff_hunk: @@ -102,3 +145,51 @@ if(ARGTABLE3_ENABLE_TESTS)
   enable_testing()
   add_subdirectory(tests)
 endif()
+
+################################################################################
+# Pkg-config file generation and installation
+################################################################################
+
+set(PKG_CONFIG_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
+configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
+install(FILES "${PKG_CONFIG_FILE_NAME}"
path: CMakeLists.txt
user: login: tomghuang
body: Done. I've moved `include(GNUInstallDirs)` to the top-level `CMakeLists.txt`.
created_at: 2025-05-23T00:59:09Z
author_association: CONTRIBUTOR
diff_hunk: @@ -102,3 +147,51 @@ if(ARGTABLE3_ENABLE_TESTS)
   enable_testing()
   add_subdirectory(tests)
 endif()
+
+################################################################################
+# Pkg-config file generation and installation
+################################################################################
+
+set(PKG_CONFIG_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
+configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
+install(FILES "${PKG_CONFIG_FILE_NAME}"
+	DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
+)
+
+################################################################################
+# Packaging (CPack) configuration
+################################################################################
+
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
+set(CPACK_PACKAGE_VENDOR "${COMPANY_NAME}")
+set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
+set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
+set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
path: CMakeLists.txt
user: login: Copilot
body: CPACK_PACKAGE_MAINTAINER is being set to the company name, which may be misleading. Consider setting it to a dedicated maintainer identifier (e.g., an email address) and using MAINTAINER_CONTACT for the actual contact information.
created_at: 2025-05-23T00:59:47Z
author_association: NONE
diff_hunk: @@ -102,3 +147,51 @@ if(ARGTABLE3_ENABLE_TESTS)
   enable_testing()
   add_subdirectory(tests)
 endif()
+
+################################################################################
+# Pkg-config file generation and installation
+################################################################################
+
+set(PKG_CONFIG_FILE_NAME "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
+configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
+install(FILES "${PKG_CONFIG_FILE_NAME}"
+	DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
+)
+
+################################################################################
+# Packaging (CPack) configuration
+################################################################################
+
+set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
+set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
+set(CPACK_PACKAGE_VENDOR "${COMPANY_NAME}")
+set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
+set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
+set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
path: CMakeLists.txt
user: login: tomghuang
body: As I said before, the current practice should be fine.
created_at: 2025-05-23T01:00:23Z
author_association: CONTRIBUTOR

PR comments:
user: login: heitbaum
created_at: 2025-05-23T05:42:10Z
body: minor nit: https://github.com/argtable/argtable3/pull/71#issuecomment-2241138273

version is showing as 0.0.0 instead of 3.x.x

```
more /var/media/DATA/home-rudi/LibreELEC.tv/build.LibreELEC-Generic.x86_64-13.0-devel/install_pkg/argtable3-df6b98ea4a16108128300bec20040a25ccab1d2c/usr/lib/pkgconfig/argtable3.pc
prefix=/usr
includedir=${prefix}/include
libdir=${prefix}/lib

Name: argtable3
Description: ANSI C command-line parsing library
Version: 0.0.0
Cflags: -I${includedir}
Libs: -L${libdir} -largtable3 -lm
```
author_association: CONTRIBUTOR
user: login: tomghuang
created_at: 2025-05-23T07:05:36Z
body: @heitbaum : This is intentional: The master branch uses the version `0.0.0` so that whenever I see this version number, I can immediately recognize it as coming from the master branch. The release from a tag will show the correct version number.

The logic is from the top-level `CMakeLists.txt`:
```
################################################################################
# Version handling: read from version.tag if present, otherwise use defaults.
# version.tag format: major.minor.patch.build (e.g., 3.2.1.0)
################################################################################

get_filename_component(VERSION_TAG_PATH "version.tag" ABSOLUTE)
if(EXISTS "${VERSION_TAG_PATH}")
  file(READ "${VERSION_TAG_PATH}" VERSION_TAG OFFSET 1) # Skip the first "v" character.
  string(REPLACE "." ";" VERSION_LIST ${VERSION_TAG})
  list(GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
  list(GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
  list(GET VERSION_LIST 2 PROJECT_VERSION_PATCH)
  list(GET VERSION_LIST 3 PROJECT_VERSION_BUILD)
else()
  set(PROJECT_VERSION_MAJOR 0)
  set(PROJECT_VERSION_MINOR 0)
  set(PROJECT_VERSION_PATCH 0)
  set(PROJECT_VERSION_BUILD "mainline")
endif()
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(PROJECT_VERSION_TWEAK 0)
set(ARGTABLE3_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}")
set(ARGTABLE3_FULL_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_BUILD}")
```
We only generate the `version.tag` file when we run `make co TAG=<TAG_NAME>`. With `version.tag`, the `CMakeLists.txt` script will generate the correct version number in the `.pc` file.
author_association: CONTRIBUTOR