Skip to content

Commit

Permalink
Improvements in the package installation feature.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Juan Hernando Vieites committed Aug 3, 2016
1 parent babb2c4 commit 191c99e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
4 changes: 4 additions & 0 deletions CommonFindPackage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
31 changes: 26 additions & 5 deletions SubProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 191c99e

Please sign in to comment.