Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install CMake files to arch-indep directories when ARCH_INDEPENDENT is set #108

Closed
hosiet opened this issue Sep 27, 2023 · 3 comments
Closed

Comments

@hosiet
Copy link

hosiet commented Sep 27, 2023

Current CMakeLists.txt supports ARCH_INDEPENDENT in write_basic_package_version_file, which is great. However, the default configuration would install CMake files under CMAKE_INSTALL_LIBDIR/cmake/utfcpp/ (i.e.. /usr/lib/*/cmake/utfcpp/, which may be an architecture-dependent location as stated on https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html . This breaks the nice ARCH_INDEPENDENT feature.

I am proposing a patch to install CMake files to CMAKE_INSTALL_DATADIR/cmake/utfcpp/ (i.e. /usr/share/cmake/utfcpp/) when ARCH_INDEPENDENT feature is detected and enabled. This is also supported as described in https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure . Please find the patch below:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7c13109..3105dc3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,17 +20,22 @@ add_library(utf8::cpp ALIAS utf8cpp)
 
 if(UTF8_INSTALL)
     include(CMakePackageConfigHelpers)
+
+    if(${CMAKE_VERSION} VERSION_GREATER "3.14")
+        set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT")
+    endif()
+
     if(MSVC)
         set(DEF_INSTALL_CMAKE_DIR CMake)
     else()
         include(GNUInstallDirs) # define CMAKE_INSTALL_*
-        set(DEF_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/utf8cpp)
+        if(${OPTIONAL_ARCH_INDEPENDENT} STREQUAL "ARCH_INDEPENDENT")
+            set(DEF_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_DATADIR}/cmake/utf8cpp)
+        else()
+            set(DEF_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/utf8cpp)
+        endif()
     endif()
 
-    if(${CMAKE_VERSION} VERSION_GREATER "3.14")
-        set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT")
-    endif()
-    
     write_basic_package_version_file(
         ${CMAKE_CURRENT_BINARY_DIR}/utf8cppConfigVersion.cmake
         VERSION ${PROJECT_VERSION}
@nemtrif
Copy link
Owner

nemtrif commented Sep 30, 2023

Will this change break a build for anyone?

@hosiet
Copy link
Author

hosiet commented Sep 30, 2023

I do not anticipate any breakage. If anything does break, please let me know.

@nemtrif
Copy link
Owner

nemtrif commented Oct 14, 2023

I don't intend to do any CMake related work before version 4.0 is released.

@nemtrif nemtrif closed this as completed Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants