From 191c99ee986c97a9697a8ec15a427bfd05a5a787 Mon Sep 17 00:00:00 2001 From: Juan Hernando Vieites Date: Wed, 3 Aug 2016 10:48:57 +0200 Subject: [PATCH] Improvements in the package installation feature. Support for yum and avoid caching of INSTALL_PACKAGES in CMakeCache.txt. This changes are motivated by some issues reported by a user trying to compile Equalizer in RHEL. --- CHANGES.md | 7 +++++++ CommonFindPackage.cmake | 4 ++++ README.md | 5 ++++- SubProject.cmake | 31 ++++++++++++++++++++++++++----- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 177417e..3b8d917 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +# git master + +* [504](https://github.com/Eyescale/CMake/pull/504): + * Add support for yum to subproject_install_packages + * Make sure that package installation is only attempted if INSTALL_PACKAGES + is in the command line (i.e. do not cache the variable). + # 2016.06 (30-Jun-2016) * [503](https://github.com/Eyescale/CMake/pull/503): diff --git a/CommonFindPackage.cmake b/CommonFindPackage.cmake index 265fb02..51e2efe 100644 --- a/CommonFindPackage.cmake +++ b/CommonFindPackage.cmake @@ -269,4 +269,8 @@ macro(common_find_package_post) endif() common_graph(${PROJECT_NAME}) message(STATUS ${__configure_msg}) + + # If this variable was given in the command line, ensure that the package + # installation is only run in this cmake invocation. + unset(INSTALL_PACKAGES CACHE) endmacro() diff --git a/README.md b/README.md index 3f4792f..d6cc90e 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,9 @@ The following CMake modules can be included in your project: Additional features: * Users can use "cmake -DINSTALL_PACKAGES=1" during the initial configuration to - install known system packages (Ubuntu and OS X only). + install known system packages. + This is only implemented for Linux distributions using apt-get and yum + package managers and MacPorts in OS X. The actual support depends on the + project declaring its dependencies for each particular case. [Detailed Change Log](CHANGES.md) diff --git a/SubProject.cmake b/SubProject.cmake index a393de9..ce3f18c 100644 --- a/SubProject.cmake +++ b/SubProject.cmake @@ -80,12 +80,33 @@ function(subproject_install_packages name) clang-format-3.5) # optional deb packages, not added to build spec list(APPEND ${NAME}_PORT_DEPENDS cppcheck) - if(${NAME}_DEB_DEPENDS AND CMAKE_SYSTEM_NAME MATCHES "Linux" ) - list(SORT ${NAME}_DEB_DEPENDS) - list(REMOVE_DUPLICATES ${NAME}_DEB_DEPENDS) - message("Running 'sudo apt-get install ${${NAME}_DEB_DEPENDS}'") - execute_process(COMMAND sudo apt-get install ${${NAME}_DEB_DEPENDS}) + if(CMAKE_SYSTEM_NAME MATCHES "Linux" ) + # Detecting the package manager to use + find_program(__pkg_mng apt-get) + if(__pkg_mng) + set(__pkg_type DEB) + elseif(__pkg_mng) + find_program(__pkg_mng yum) + if(__pkg_mng) + set(__pkg_type RPM) + endif() + endif() + if(NOT __pkg_mng) + message(WARNING "Could not determine the package manager for installing dependencies") + # Removing INSTALL_PACKAGES so the warning is not printed repeatedly. + unset(INSTALL_PACKAGES CACHE) + endif() + + if(__pkg_mng AND ${NAME}_${__pkg_type}_DEPENDS) + list(SORT ${NAME}_${__pkg_type}_DEPENDS) + list(REMOVE_DUPLICATES ${NAME}_${__pkg_type}_DEPENDS) + message( + "Running 'sudo ${__pkg_mng} install ${${NAME}_${__pkg_type}_DEPENDS}'") + execute_process( + COMMAND sudo ${__pkg_mng} install ${${NAME}_${__pkg_type}_DEPENDS}) + endif() endif() + if(${NAME}_PORT_DEPENDS AND APPLE) list(SORT ${NAME}_PORT_DEPENDS) list(REMOVE_DUPLICATES ${NAME}_PORT_DEPENDS)