Skip to content

Commit

Permalink
Single CMake/common superproject
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Eilemann authored and Stefan Eilemann committed Apr 14, 2015
1 parent ef72a95 commit 9c29fd4
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .gitexternals
@@ -1,2 +1,2 @@
# -*- mode: cmake -*-
# CMake/common https://github.com/Eyescale/CMake.git 2bc6da6
# CMake/common https://github.com/Eyescale/CMake.git bc88771
12 changes: 6 additions & 6 deletions .gitsubprojects
@@ -1,8 +1,8 @@
# -*- mode: cmake -*-
git_subproject(vmmlib https://github.com/Eyescale/vmmlib.git eb372a2)
git_subproject(Lunchbox https://github.com/Eyescale/Lunchbox.git b0e3e0a)
git_subproject(Pression https://github.com/Eyescale/Pression.git 5657b69)
git_subproject(hwsd https://github.com/Eyescale/hwsd.git 09b72d4)
git_subproject(Collage https://github.com/Eyescale/Collage.git bddbf4d)
git_subproject(GLStats https://github.com/Eyescale/GLStats.git ee6d8d5)
git_subproject(Deflect https://github.com/BlueBrain/Deflect.git deb49b5)
git_subproject(Lunchbox https://github.com/Eyescale/Lunchbox.git 2bf4453)
git_subproject(Pression https://github.com/Eyescale/Pression.git 3c0ca5e)
git_subproject(hwsd https://github.com/Eyescale/hwsd.git 3258283)
git_subproject(Collage https://github.com/Eyescale/Collage.git 0d169b9)
git_subproject(GLStats https://github.com/Eyescale/GLStats.git 96d90e1)
git_subproject(Deflect https://github.com/BlueBrain/Deflect.git e070e07)
151 changes: 86 additions & 65 deletions CMake/GitExternal.cmake
Expand Up @@ -8,18 +8,20 @@
# update target to bump the tag to the master revision by
# recreating .gitexternals.
# * Provides function
# git_external(<directory> <giturl> <gittag> [NO_UPDATE, VERBOSE]
# [RESET <files>])
# git_external_manage(<file>)
# git_external(<directory> <giturl> <gittag> [NO_UPDATE, VERBOSE]
# [RESET <files>])
# which will check out directory in CMAKE_SOURCE_DIR (if relative)
# or in the given absolute path using the given repository and tag
# (commit-ish).
#
# [optional] Flags which control behaviour
# NO_UPDATE
# Options which control behaviour:
# GIT_EXTERNAL_DISABLE_UPDATE
# When set, GitExternal will not change a repo that has already
# been checked out. The purpose of this is to allow one to set a
# default branch to be checked out, but stop GitExternal from
# changing back to that branch if the user has checked out and is
# working on another.
# VERBOSE
# GIT_EXTERNAL_VERBOSE
# When set, displays information about git commands that are executed
#
# CMake variables
Expand All @@ -33,6 +35,8 @@ if(NOT GIT_EXECUTABLE)
endif()

include(CMakeParseArguments)
option(GIT_EXTERNAL_DISABLE_UPDATE "Disable update of cloned repositories" ON)
option(GIT_EXTERNAL_VERBOSE "Print git commands as they are executed" OFF)

set(GIT_EXTERNAL_USER $ENV{GIT_EXTERNAL_USER})
if(NOT GIT_EXTERNAL_USER)
Expand All @@ -46,14 +50,29 @@ set(GIT_EXTERNAL_USER_FORK ${GIT_EXTERNAL_USER} CACHE STRING
"Github user name used to setup remote for user forks")

macro(GIT_EXTERNAL_MESSAGE msg)
if(${GIT_EXTERNAL_VERBOSE})
if(GIT_EXTERNAL_VERBOSE)
message(STATUS "${NAME} : ${msg}")
endif()
endmacro(GIT_EXTERNAL_MESSAGE)
endmacro()

function(GIT_EXTERNAL DIR REPO TAG)
cmake_parse_arguments(GIT_EXTERNAL "NO_UPDATE;VERBOSE" "" "RESET" ${ARGN})
get_filename_component(DIR "${DIR}" ABSOLUTE)
cmake_parse_arguments(GIT_EXTERNAL "" "" "RESET" ${ARGN})

# check if we had a previous external of the same name
string(REGEX REPLACE "[:/]" "_" TARGET "${DIR}")
get_property(OLD_TAG GLOBAL PROPERTY ${TARGET}_GITEXTERNAL_TAG)
if(OLD_TAG)
if(NOT OLD_TAG STREQUAL TAG)
message(STATUS "${DIR}: already configured with ${OLD_TAG}, ignoring requested ${TAG}")
set(TAG ${OLD_TAG})
endif()
else()
set_property(GLOBAL PROPERTY ${TARGET}_GITEXTERNAL_TAG ${TAG})
endif()

if(NOT IS_ABSOLUTE "${DIR}")
set(DIR "${CMAKE_SOURCE_DIR}/${DIR}")
endif()
get_filename_component(NAME "${DIR}" NAME)
get_filename_component(GIT_EXTERNAL_DIR "${DIR}/.." ABSOLUTE)

Expand All @@ -78,64 +97,66 @@ function(GIT_EXTERNAL DIR REPO TAG)
WORKING_DIRECTORY "${DIR}")
endif()

if(IS_DIRECTORY "${DIR}/.git")
if(${GIT_EXTERNAL_NO_UPDATE})
GIT_EXTERNAL_MESSAGE("git update disabled by user")
else()
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_VARIABLE currentref OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${DIR})
GIT_EXTERNAL_MESSAGE(
"current ref is \"${currentref}\" and tag is \"${TAG}\"")
if(currentref STREQUAL TAG) # nothing to do
return()
endif()
if(NOT IS_DIRECTORY "${DIR}/.git")
message(STATUS "Can't update git external ${DIR}: Not a git repository")
return()
endif()

# reset generated files
foreach(GIT_EXTERNAL_RESET_FILE ${GIT_EXTERNAL_RESET})
GIT_EXTERNAL_MESSAGE("git reset -q ${GIT_EXTERNAL_RESET_FILE}")
execute_process(
COMMAND "${GIT_EXECUTABLE}" reset -q "${GIT_EXTERNAL_RESET_FILE}"
RESULT_VARIABLE nok ERROR_VARIABLE error
WORKING_DIRECTORY "${DIR}")
GIT_EXTERNAL_MESSAGE("git checkout -q -- ${GIT_EXTERNAL_RESET_FILE}")
execute_process(
COMMAND "${GIT_EXECUTABLE}" checkout -q -- "${GIT_EXTERNAL_RESET_FILE}"
RESULT_VARIABLE nok ERROR_VARIABLE error
WORKING_DIRECTORY "${DIR}")
endforeach()

# fetch latest update
execute_process(COMMAND "${GIT_EXECUTABLE}" fetch origin -q
RESULT_VARIABLE nok ERROR_VARIABLE error
WORKING_DIRECTORY "${DIR}")
if(nok)
message(STATUS "Update of ${DIR} failed:\n ${error}")
endif()
if(GIT_EXTERNAL_DISABLE_UPDATE)
git_external_message("git update disabled by user")
return()
endif()

# update tag
GIT_EXTERNAL_MESSAGE("git rebase FETCH_HEAD")
execute_process(COMMAND ${GIT_EXECUTABLE} rebase FETCH_HEAD
RESULT_VARIABLE RESULT OUTPUT_VARIABLE OUTPUT ERROR_VARIABLE OUTPUT
WORKING_DIRECTORY "${DIR}")
if(RESULT)
message(STATUS "git rebase failed, aborting ${DIR} merge")
execute_process(COMMAND ${GIT_EXECUTABLE} rebase --abort
WORKING_DIRECTORY "${DIR}")
endif()
# update to given tag
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_VARIABLE currentref OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${DIR})
git_external_message(
"current ref is \"${currentref}\" and tag is \"${TAG}\"")
if(currentref STREQUAL TAG) # nothing to do
return()
endif()

# checkout requested tag
execute_process(
COMMAND "${GIT_EXECUTABLE}" checkout -q "${TAG}"
RESULT_VARIABLE nok ERROR_VARIABLE error
WORKING_DIRECTORY "${DIR}"
)
if(nok)
message(STATUS "git checkout ${TAG} in ${DIR} failed: ${error}\n")
endif()
else()
message(STATUS "Can't update git external ${DIR}: Not a git repository")
endif()
# reset generated files
foreach(GIT_EXTERNAL_RESET_FILE ${GIT_EXTERNAL_RESET})
git_external_message("git reset -q ${GIT_EXTERNAL_RESET_FILE}")
execute_process(
COMMAND "${GIT_EXECUTABLE}" reset -q "${GIT_EXTERNAL_RESET_FILE}"
RESULT_VARIABLE nok ERROR_VARIABLE error
WORKING_DIRECTORY "${DIR}")
git_external_message("git checkout -q -- ${GIT_EXTERNAL_RESET_FILE}")
execute_process(
COMMAND "${GIT_EXECUTABLE}" checkout -q -- "${GIT_EXTERNAL_RESET_FILE}"
RESULT_VARIABLE nok ERROR_VARIABLE error
WORKING_DIRECTORY "${DIR}")
endforeach()

# fetch latest update
execute_process(COMMAND "${GIT_EXECUTABLE}" fetch origin -q
RESULT_VARIABLE nok ERROR_VARIABLE error
WORKING_DIRECTORY "${DIR}")
if(nok)
message(STATUS "Update of ${DIR} failed:\n ${error}")
endif()

# update tag
git_external_message("git rebase FETCH_HEAD")
execute_process(COMMAND ${GIT_EXECUTABLE} rebase FETCH_HEAD
RESULT_VARIABLE RESULT OUTPUT_VARIABLE OUTPUT ERROR_VARIABLE OUTPUT
WORKING_DIRECTORY "${DIR}")
if(RESULT)
message(STATUS "git rebase failed, aborting ${DIR} merge")
execute_process(COMMAND ${GIT_EXECUTABLE} rebase --abort
WORKING_DIRECTORY "${DIR}")
endif()

# checkout requested tag
execute_process(
COMMAND "${GIT_EXECUTABLE}" checkout -q "${TAG}"
RESULT_VARIABLE nok ERROR_VARIABLE error
WORKING_DIRECTORY "${DIR}")
if(nok)
message(STATUS "git checkout ${TAG} in ${DIR} failed: ${error}\n")
endif()
endfunction()

Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(Equalizer)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake
${PROJECT_SOURCE_DIR}/CMake/common)
${CMAKE_SOURCE_DIR}/CMake/common)

include(GitExternal)
include(SubProject)
Expand Down Expand Up @@ -109,7 +109,8 @@ if(GLEW_MX_FOUND)
endif()

common_install(RELATIVE
FILES CMake/common/FindGLEW_MX.cmake CMake/EqGLLibraries.cmake
FILES ${CMAKE_SOURCE_DIR}/CMake/common/FindGLEW_MX.cmake
CMake/EqGLLibraries.cmake
DESTINATION ${CMAKE_MODULE_INSTALL_PATH}
COMPONENT dev)
install(FILES ${DEFINES_FILE} DESTINATION include/eq COMPONENT dev)
Expand Down
6 changes: 3 additions & 3 deletions examples/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (c) 2010 Daniel Pfeifer <daniel@pfeifer-mail.de>
# 2010-2014 Stefan Eilemann <eile@eyescale.ch>
# 2010-2015 Stefan Eilemann <eile@eyescale.ch>
# 2011 Maxim Makhinya <maxmah@gmail.com>

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
Expand Down Expand Up @@ -83,8 +83,8 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt
DESTINATION share/Equalizer/examples COMPONENT examples)
install(DIRECTORY include DESTINATION share/Equalizer/examples
COMPONENT examples)
install(FILES ${PROJECT_SOURCE_DIR}/CMake/common/StringifyShaders.cmake
${PROJECT_SOURCE_DIR}/CMake/common/FindGLEW_MX.cmake
install(FILES ${CMAKE_SOURCE_DIR}/CMake/common/StringifyShaders.cmake
${CMAKE_SOURCE_DIR}/CMake/common/FindGLEW_MX.cmake
${PROJECT_SOURCE_DIR}/CMake/FindPackages.cmake
${PROJECT_SOURCE_DIR}/CMake/configure.cmake
DESTINATION share/Equalizer/examples/CMake COMPONENT examples)
Expand Down

0 comments on commit 9c29fd4

Please sign in to comment.