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

Improvements in the package installation feature. #504

Merged
merged 1 commit into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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)
52 changes: 45 additions & 7 deletions SubProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
# - DISABLE_SUBPROJECTS: when set, does not load sub projects. Useful for
# example for continuous integration builds
# - SUBPROJECT_${name}: If set to OFF, the subproject is not added.
# - INSTALL_PACKAGES: command line cache variable which will "apt-get" or
# "port install" the known system packages. Will be unset after installation.
# - INSTALL_PACKAGES: command line cache variable which will "apt-get", "yum" or
# "port install" the known system packages. This variable is unset after this
# script is parsed by top level projects.
# The packages to install are taken from ${PROJECT_NAME}_${type}_DEPENDS
# where type is DEB, RPM or PORT depending on the system.
# - COMMON_SOURCE_DIR: When set, the source code of subprojects will be
# downloaded in this path instead of CMAKE_SOURCE_DIR.
# A sample project can be found at https://github.com/Eyescale/Collage.git
Expand Down Expand Up @@ -80,12 +83,40 @@ 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)
else()
find_program(__pkg_mng yum)
if(__pkg_mng)
set(__pkg_type RPM)
endif()
endif()
elseif(APPLE)
find_program(__pkg_mng port)
endif()

if(NOT __pkg_mng)
message(WARNING "Could not find the package manager tool for installing dependencies in this system")
# Removing INSTALL_PACKAGES so the warning is not printed repeatedly.
unset(INSTALL_PACKAGES CACHE)
return()
else()
# We don't want __pkg_mng to appear in ccmake.
set(__pkg_mng ${__pkg_mng} CACHE INTERNAL "")
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux" 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()

if(${NAME}_PORT_DEPENDS AND APPLE)
list(SORT ${NAME}_PORT_DEPENDS)
list(REMOVE_DUPLICATES ${NAME}_PORT_DEPENDS)
Expand Down Expand Up @@ -241,4 +272,11 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitsubprojects")
endif()
add_dependencies(update ${PROJECT_NAME}-update-git-subprojects)
endif()

if(NOT ${PROJECT_NAME}_IS_SUBPROJECT)
# 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)
endif()

endif()