From 43c0ffb8b81a9cd4731d03db89e23cf896b52720 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 01:26:59 +0000 Subject: [PATCH 1/8] Initial plan From d02e5839005361c5f38215a795281ac0e72296a1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 01:35:31 +0000 Subject: [PATCH 2/8] Refactor CMakeLists directory settings to use GNUInstallDirs variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Apply PR #1062 changes: DIR_INCLUDE → CMAKE_INSTALL_INCLUDEDIR, DIR_ETC → CMAKE_INSTALL_SYSCONFDIR, DIR_LIBRARY → CMAKE_INSTALL_LIBDIR - Similarly update DIR_SHARE → CMAKE_INSTALL_FULL_DATAROOTDIR (absolute, required because it feeds PKGDATADIR/LOCALEDIR compile-time definitions) - Remove LIB_INSTALL_DIR CACHE variable and LIB_SUFFIX dead code (LIB_SUFFIX was only used to compute DIR_LIBRARY which now uses CMAKE_INSTALL_LIBDIR directly; LIB_INSTALL_DIR was a CACHE variable always overriding DIR_LIBRARY with the same value) - Remove LIB_INSTALL_DIR override block - Fix opencc.pc.in: use CMAKE_INSTALL_FULL_LIBDIR and CMAKE_INSTALL_FULL_INCLUDEDIR for absolute pkg-config paths (GNUInstallDirs relative paths would produce broken -L/-I flags) - Add comments explaining relative vs absolute path choice Co-authored-by: BYVoid <245270+BYVoid@users.noreply.github.com> Agent-Logs-Url: https://github.com/BYVoid/OpenCC/sessions/a2b64015-d200-4d3d-b473-55a9be50c4b6 --- CMakeLists.txt | 22 +++++++++------------- opencc.pc.in | 6 +++--- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2e9dc70d..083c74121 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,16 +79,16 @@ endif() ######## Directory -set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "") -if(CMAKE_INSTALL_LIBDIR MATCHES "lib64$") - set(LIB_SUFFIX 64) -endif() - set (DIR_PREFIX ${CMAKE_INSTALL_PREFIX}) -set (DIR_INCLUDE ${DIR_PREFIX}/include) -set (DIR_SHARE ${DIR_PREFIX}/share) -set (DIR_ETC ${DIR_PREFIX}/etc) -set (DIR_LIBRARY ${DIR_PREFIX}/lib${LIB_SUFFIX}) +# Use relative GNUInstallDirs paths for install() destinations and cmake package +# config (relative paths enable relocatable packages). +set (DIR_INCLUDE ${CMAKE_INSTALL_INCLUDEDIR}) +set (DIR_ETC ${CMAKE_INSTALL_SYSCONFDIR}) +set (DIR_LIBRARY ${CMAKE_INSTALL_LIBDIR}) +# Use the full absolute path for the data directory because it is embedded as a +# compile-time PKGDATADIR/LOCALEDIR definition that the binary uses at runtime +# to locate its data files. +set (DIR_SHARE ${CMAKE_INSTALL_FULL_DATAROOTDIR}) if (DEFINED SHARE_INSTALL_PREFIX) set (DIR_SHARE ${SHARE_INSTALL_PREFIX}) @@ -102,10 +102,6 @@ if (DEFINED SYSCONF_INSTALL_DIR) set (DIR_ETC ${SYSCONF_INSTALL_DIR}) endif (DEFINED SYSCONF_INSTALL_DIR) -if (DEFINED LIB_INSTALL_DIR) - set (DIR_LIBRARY ${LIB_INSTALL_DIR}) -endif (DEFINED LIB_INSTALL_DIR) - set (DIR_SHARE_OPENCC ${DIR_SHARE}/opencc) set (DIR_SHARE_LOCALE ${DIR_SHARE}/locale) diff --git a/opencc.pc.in b/opencc.pc.in index 93ff260b1..2bd4d294e 100644 --- a/opencc.pc.in +++ b/opencc.pc.in @@ -1,7 +1,7 @@ -prefix=@DIR_PREFIX@ +prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} -libdir=@DIR_LIBRARY@ -includedir=@DIR_INCLUDE@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ Name: opencc Description: Open Chinese Convert From 863d33c2c48a57a155e3df1e3fa4064f22b41766 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 04:26:26 +0000 Subject: [PATCH 3/8] Add GNUInstallDirs docs link and parity comments to CMakeLists.txt Each new variable (CMAKE_INSTALL_INCLUDEDIR, CMAKE_INSTALL_SYSCONFDIR, CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_FULL_DATAROOTDIR) now has inline documentation showing: - Link to https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html - Default relative/absolute values for common prefixes (/usr/local, /usr) - The old hardcoded path each variable replaces - SYSCONFDIR special case: /usr prefix gives /etc (not /usr/etc) Co-authored-by: BYVoid <245270+BYVoid@users.noreply.github.com> Agent-Logs-Url: https://github.com/BYVoid/OpenCC/sessions/4d6d1872-e7f6-4eb6-bf48-930c0d22928b --- CMakeLists.txt | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 083c74121..3f61749d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,16 +78,35 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") endif() ######## Directory +# Installation directories follow GNU Coding Standards via CMake's GNUInstallDirs module: +# https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html +# +# Default values and parity with previously hardcoded paths +# (shown for CMAKE_INSTALL_PREFIX=/usr/local and /usr): +# +# CMAKE_INSTALL_INCLUDEDIR "include" -> /usr/local/include or /usr/include +# (replaces: ${CMAKE_INSTALL_PREFIX}/include) +# +# CMAKE_INSTALL_SYSCONFDIR "etc" -> /usr/local/etc or /etc +# (replaces: ${CMAKE_INSTALL_PREFIX}/etc) +# NOTE: when prefix is /usr the full path is /etc per GNU Coding Standards, +# whereas the old code would have produced /usr/etc. +# +# CMAKE_INSTALL_LIBDIR "lib" -> /usr/local/lib or /usr/lib +# (also resolves to lib64 or lib/ on applicable platforms) +# (replaces: ${CMAKE_INSTALL_PREFIX}/lib[64]) +# +# CMAKE_INSTALL_FULL_DATAROOTDIR (absolute) -> /usr/local/share or /usr/share +# (replaces: ${CMAKE_INSTALL_PREFIX}/share) +# Full/absolute form is required here because the value is baked into the +# binary as PKGDATADIR/LOCALEDIR at compile time for runtime data lookup. set (DIR_PREFIX ${CMAKE_INSTALL_PREFIX}) -# Use relative GNUInstallDirs paths for install() destinations and cmake package -# config (relative paths enable relocatable packages). +# Relative paths are used for install() destinations and CMake package config +# so that packages remain relocatable. set (DIR_INCLUDE ${CMAKE_INSTALL_INCLUDEDIR}) set (DIR_ETC ${CMAKE_INSTALL_SYSCONFDIR}) set (DIR_LIBRARY ${CMAKE_INSTALL_LIBDIR}) -# Use the full absolute path for the data directory because it is embedded as a -# compile-time PKGDATADIR/LOCALEDIR definition that the binary uses at runtime -# to locate its data files. set (DIR_SHARE ${CMAKE_INSTALL_FULL_DATAROOTDIR}) if (DEFINED SHARE_INSTALL_PREFIX) From 31771ffd817ddbee1b06eddf82bb2e3325d4bb23 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 04:52:16 +0000 Subject: [PATCH 4/8] Address all reviewer concerns: consistent relative DIR_*, restore LIB_INSTALL_DIR, fix pc.in - Make DIR_SHARE relative (CMAKE_INSTALL_DATAROOTDIR) like all other DIR_* variables - Compute DIR_*_FULL absolute variants (via IS_ABSOLUTE check) for uses that require absolute paths: add_definitions(PKGDATADIR/LOCALEDIR) and the pc file - Restore LIB_INSTALL_DIR override block (removed in previous commit) so all four legacy overrides are now treated consistently - Remove dead DIR_PREFIX variable - Fix opencc.pc.in: use @DIR_LIBRARY_FULL@ / @DIR_INCLUDE_FULL@ so legacy override variables (LIB_INSTALL_DIR, INCLUDE_INSTALL_DIR) are correctly reflected in the generated pkg-config file - Update parity comment: s/CMAKE_INSTALL_FULL_DATAROOTDIR/CMAKE_INSTALL_DATAROOTDIR/ Co-authored-by: BYVoid <245270+BYVoid@users.noreply.github.com> Agent-Logs-Url: https://github.com/BYVoid/OpenCC/sessions/4215d006-8491-4f30-a125-94c14523e0e3 --- CMakeLists.txt | 30 +++++++++++++++++++++--------- opencc.pc.in | 4 ++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f61749d1..05a7c263e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,18 +96,15 @@ endif() # (also resolves to lib64 or lib/ on applicable platforms) # (replaces: ${CMAKE_INSTALL_PREFIX}/lib[64]) # -# CMAKE_INSTALL_FULL_DATAROOTDIR (absolute) -> /usr/local/share or /usr/share +# CMAKE_INSTALL_DATAROOTDIR "share" -> /usr/local/share or /usr/share # (replaces: ${CMAKE_INSTALL_PREFIX}/share) -# Full/absolute form is required here because the value is baked into the -# binary as PKGDATADIR/LOCALEDIR at compile time for runtime data lookup. -set (DIR_PREFIX ${CMAKE_INSTALL_PREFIX}) -# Relative paths are used for install() destinations and CMake package config -# so that packages remain relocatable. +# All DIR_* variables use relative paths so that install() destinations and +# CMake package config files remain relocatable. set (DIR_INCLUDE ${CMAKE_INSTALL_INCLUDEDIR}) set (DIR_ETC ${CMAKE_INSTALL_SYSCONFDIR}) set (DIR_LIBRARY ${CMAKE_INSTALL_LIBDIR}) -set (DIR_SHARE ${CMAKE_INSTALL_FULL_DATAROOTDIR}) +set (DIR_SHARE ${CMAKE_INSTALL_DATAROOTDIR}) if (DEFINED SHARE_INSTALL_PREFIX) set (DIR_SHARE ${SHARE_INSTALL_PREFIX}) @@ -121,9 +118,24 @@ if (DEFINED SYSCONF_INSTALL_DIR) set (DIR_ETC ${SYSCONF_INSTALL_DIR}) endif (DEFINED SYSCONF_INSTALL_DIR) +if (DEFINED LIB_INSTALL_DIR) + set (DIR_LIBRARY ${LIB_INSTALL_DIR}) +endif (DEFINED LIB_INSTALL_DIR) + set (DIR_SHARE_OPENCC ${DIR_SHARE}/opencc) set (DIR_SHARE_LOCALE ${DIR_SHARE}/locale) +# Compute absolute paths needed for compile-time macros (PKGDATADIR/LOCALEDIR) +# and for the pkg-config file. We must handle both the GNUInstallDirs relative +# defaults and user-supplied absolute override paths (SHARE_INSTALL_PREFIX etc.). +foreach (_gnu_dir SHARE INCLUDE LIBRARY) + if (IS_ABSOLUTE "${DIR_${_gnu_dir}}") + set (DIR_${_gnu_dir}_FULL "${DIR_${_gnu_dir}}") + else () + set (DIR_${_gnu_dir}_FULL "${CMAKE_INSTALL_PREFIX}/${DIR_${_gnu_dir}}") + endif () +endforeach () + ######## Configuration include(CMakePackageConfigHelpers) @@ -167,8 +179,8 @@ install( ######## Compiler flags add_definitions( - -DPKGDATADIR="${DIR_SHARE_OPENCC}" - -DLOCALEDIR="${DIR_SHARE_LOCALE}" + -DPKGDATADIR="${DIR_SHARE_FULL}/opencc" + -DLOCALEDIR="${DIR_SHARE_FULL}/locale" -DVERSION="${OPENCC_VERSION}" -DPACKAGE_NAME="${PACKAGE_NAME}" ) diff --git a/opencc.pc.in b/opencc.pc.in index 2bd4d294e..7079b775e 100644 --- a/opencc.pc.in +++ b/opencc.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} -libdir=@CMAKE_INSTALL_FULL_LIBDIR@ -includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ +libdir=@DIR_LIBRARY_FULL@ +includedir=@DIR_INCLUDE_FULL@ Name: opencc Description: Open Chinese Convert From a382ca8ffa4bb67e8c81067f0f00d8f96eb015e2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 05:23:23 +0000 Subject: [PATCH 5/8] Derive DIR_SHARE_OPENCC_FULL/LOCALE_FULL from existing derived vars; avoid suffix duplication Introduce DIR_SHARE_OPENCC_FULL and DIR_SHARE_LOCALE_FULL by appending the /opencc and /locale suffixes to DIR_SHARE_FULL once, keeping the suffix in a single location. Use these in add_definitions() instead of inline expansion. Co-authored-by: BYVoid <245270+BYVoid@users.noreply.github.com> Agent-Logs-Url: https://github.com/BYVoid/OpenCC/sessions/81a83abd-8b46-4cdb-9768-6ccaeeb287e9 --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05a7c263e..b93383484 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,9 @@ foreach (_gnu_dir SHARE INCLUDE LIBRARY) endif () endforeach () +set (DIR_SHARE_OPENCC_FULL ${DIR_SHARE_FULL}/opencc) +set (DIR_SHARE_LOCALE_FULL ${DIR_SHARE_FULL}/locale) + ######## Configuration include(CMakePackageConfigHelpers) @@ -179,8 +182,8 @@ install( ######## Compiler flags add_definitions( - -DPKGDATADIR="${DIR_SHARE_FULL}/opencc" - -DLOCALEDIR="${DIR_SHARE_FULL}/locale" + -DPKGDATADIR="${DIR_SHARE_OPENCC_FULL}" + -DLOCALEDIR="${DIR_SHARE_LOCALE_FULL}" -DVERSION="${OPENCC_VERSION}" -DPACKAGE_NAME="${PACKAGE_NAME}" ) From 876c0249946ec312f16d96dae6607f555f1fa01f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 05:28:39 +0000 Subject: [PATCH 6/8] Remove unused DIR_SHARE_LOCALE and DIR_SHARE_LOCALE_FULL variables DIR_SHARE_LOCALE (relative) was only defined but never consumed. DIR_SHARE_LOCALE_FULL was only used in add_definitions(), where the suffix /locale can be inlined directly against DIR_SHARE_FULL. Keep DIR_SHARE_OPENCC (used by install() in data/ and doc/) and DIR_SHARE_OPENCC_FULL (used in add_definitions()) as both are needed. Co-authored-by: BYVoid <245270+BYVoid@users.noreply.github.com> Agent-Logs-Url: https://github.com/BYVoid/OpenCC/sessions/8bb2a2da-c659-4eaf-bec0-07ee0a2d3eb0 --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b93383484..df930bdaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,6 @@ if (DEFINED LIB_INSTALL_DIR) endif (DEFINED LIB_INSTALL_DIR) set (DIR_SHARE_OPENCC ${DIR_SHARE}/opencc) -set (DIR_SHARE_LOCALE ${DIR_SHARE}/locale) # Compute absolute paths needed for compile-time macros (PKGDATADIR/LOCALEDIR) # and for the pkg-config file. We must handle both the GNUInstallDirs relative @@ -137,7 +136,6 @@ foreach (_gnu_dir SHARE INCLUDE LIBRARY) endforeach () set (DIR_SHARE_OPENCC_FULL ${DIR_SHARE_FULL}/opencc) -set (DIR_SHARE_LOCALE_FULL ${DIR_SHARE_FULL}/locale) ######## Configuration @@ -183,7 +181,7 @@ install( add_definitions( -DPKGDATADIR="${DIR_SHARE_OPENCC_FULL}" - -DLOCALEDIR="${DIR_SHARE_LOCALE_FULL}" + -DLOCALEDIR="${DIR_SHARE_FULL}/locale" -DVERSION="${OPENCC_VERSION}" -DPACKAGE_NAME="${PACKAGE_NAME}" ) From 4e129b1a69505324275313fcd1e582d81ac37053 Mon Sep 17 00:00:00 2001 From: Carbo Kuo Date: Tue, 24 Mar 2026 22:52:26 -0700 Subject: [PATCH 7/8] Use DIR_SHARE_LOCALE_FULL variable for LOCALEDIR consistency Restore DIR_SHARE_LOCALE and add DIR_SHARE_LOCALE_FULL so both compile-time macros (PKGDATADIR, LOCALEDIR) use dedicated _FULL variables instead of mixing variable and inline suffix styles. --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df930bdaf..b93383484 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,7 @@ if (DEFINED LIB_INSTALL_DIR) endif (DEFINED LIB_INSTALL_DIR) set (DIR_SHARE_OPENCC ${DIR_SHARE}/opencc) +set (DIR_SHARE_LOCALE ${DIR_SHARE}/locale) # Compute absolute paths needed for compile-time macros (PKGDATADIR/LOCALEDIR) # and for the pkg-config file. We must handle both the GNUInstallDirs relative @@ -136,6 +137,7 @@ foreach (_gnu_dir SHARE INCLUDE LIBRARY) endforeach () set (DIR_SHARE_OPENCC_FULL ${DIR_SHARE_FULL}/opencc) +set (DIR_SHARE_LOCALE_FULL ${DIR_SHARE_FULL}/locale) ######## Configuration @@ -181,7 +183,7 @@ install( add_definitions( -DPKGDATADIR="${DIR_SHARE_OPENCC_FULL}" - -DLOCALEDIR="${DIR_SHARE_FULL}/locale" + -DLOCALEDIR="${DIR_SHARE_LOCALE_FULL}" -DVERSION="${OPENCC_VERSION}" -DPACKAGE_NAME="${PACKAGE_NAME}" ) From 9fbb3fb862e00e364811f9824cb3a73af023fbe9 Mon Sep 17 00:00:00 2001 From: Carbo Kuo Date: Tue, 24 Mar 2026 23:08:20 -0700 Subject: [PATCH 8/8] Remove unused DIR_SHARE_LOCALE variable --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b93383484..90e343f31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,6 @@ if (DEFINED LIB_INSTALL_DIR) endif (DEFINED LIB_INSTALL_DIR) set (DIR_SHARE_OPENCC ${DIR_SHARE}/opencc) -set (DIR_SHARE_LOCALE ${DIR_SHARE}/locale) # Compute absolute paths needed for compile-time macros (PKGDATADIR/LOCALEDIR) # and for the pkg-config file. We must handle both the GNUInstallDirs relative