Skip to content

Commit

Permalink
Update gitexternals and fix more cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jafet Villafranca committed Apr 10, 2014
1 parent 76a36c3 commit c07ceb6
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 99 deletions.
5 changes: 1 addition & 4 deletions .gitexternals
@@ -1,5 +1,2 @@
# -*- mode: cmake -*-
include(GitExternal)
git_external_manage(${CMAKE_CURRENT_LIST_FILE})
#-> CMake/common https://github.com/Eyescale/CMake.git a26c94b

# CMake/common https://github.com/Eyescale/CMake.git 9388c77
186 changes: 102 additions & 84 deletions CMake/GitExternal.cmake
@@ -1,21 +1,14 @@
# configures an external git repository
# Usage:
# git_external(<directory> <giturl> <gittag> [RESET <files>])
# * Automatically reads, parses and updates a .gitexternals file if it only
# contains lines in the form "# <directory> <giturl> <gittag>".
# This function parses the file for this pattern and then calls
# git_external on each found entry. Additionally it provides an
# update target to bump the tag to the master revision by
# recreating .gitexternals.
# * Provides function
# git_external(<directory> <giturl> <gittag> [RESET <files>])
# git_external_manage(<file>)
# is used for a managed .gitexternal file which is parsed and
# updated by this function, which calls git_external and provides
# an update target to bump the tag to the master revision by
# recreating the given file. The file has to contain:
# include(GitExternal)
# git_external_manage(${CMAKE_CURRENT_LIST_FILE})
# #-> CMake/common https://github.com/Eyescale/CMake.git 8324611
# Where the last line can appear multiple times, once for each
# external repo It has to start with '#->'. This function parses
# the file for this pattern and then calls git_external on each
# found entry. The entries are encoded into a target which will
# recreate the file on invocation. Since only the '#-> ' lines are
# parsed, everything else is ignored. Since the file is under git
# control, there should be no risk of data loss.

find_package(Git)
if(NOT GIT_EXECUTABLE)
Expand All @@ -24,74 +17,6 @@ endif()

include(CMakeParseArguments)

function(GIT_EXTERNAL_MANAGE FILE)
if(NOT EXISTS ${FILE})
message(FATAL_ERROR "Can't open ${FILE}")
endif()

file(READ ${FILE} GIT_EXTERNAL_FILE)
string(REGEX REPLACE "\n" ";" GIT_EXTERNAL_FILE "${GIT_EXTERNAL_FILE}")
foreach(LINE ${GIT_EXTERNAL_FILE})
string(REGEX REPLACE "^#->[ ]*(.+[ ]+.+[ ]+.+)$" "\\1" DATA ${LINE})
if(NOT LINE STREQUAL DATA)
string(REGEX REPLACE "[ ]+" ";" DATA "${DATA}")
list(LENGTH DATA DATA_LENGTH)
if(DATA_LENGTH EQUAL 3)
list(GET DATA 0 DIR)
list(GET DATA 1 REPO)
list(GET DATA 2 TAG)

# pull in identified external
git_external(${DIR} ${REPO} ${TAG})

# Create update script and target to bump external spec
if(NOT TARGET update)
add_custom_target(update)
endif()
if(NOT TARGET update_git_external)
add_custom_target(update_git_external)
add_dependencies(update update_git_external)
endif()
if(NOT TARGET update_git_external_header)
set(GIT_EXTERNAL_SCRIPT
"${CMAKE_CURRENT_BINARY_DIR}/gitupdateexternal.cmake")
file(WRITE "${GIT_EXTERNAL_SCRIPT}"
"file(WRITE ${FILE} \"# -*- mode: cmake -*-
include(GitExternal)
git_external_manage(\\\${CMAKE_CURRENT_LIST_FILE})
\")")
add_custom_target(update_git_external_header
COMMAND ${CMAKE_COMMAND} -P ${GIT_EXTERNAL_SCRIPT}
COMMENT "Recreate ${FILE}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endif()

string(REPLACE "/" "_" GIT_EXTERNAL_NAME ${DIR}) # unique, flat name
set(GIT_EXTERNAL_SCRIPT
"${CMAKE_CURRENT_BINARY_DIR}/gitupdate${GIT_EXTERNAL_NAME}.cmake")
file(WRITE "${GIT_EXTERNAL_SCRIPT}" "
execute_process(COMMAND ${GIT_EXECUTABLE} fetch --all -q
WORKING_DIRECTORY ${DIR})
execute_process(
COMMAND ${GIT_EXECUTABLE} show-ref --hash=7 refs/remotes/origin/master
OUTPUT_VARIABLE newref WORKING_DIRECTORY ${DIR})
if(newref)
file(APPEND ${FILE} \"#-> ${DIR} ${REPO} \${newref}\n\")
else()
file(APPEND ${FILE} \"#-> ${DIR} ${REPO} ${TAG}\n\")
endif()")
add_custom_target(update_git_external_${GIT_EXTERNAL_NAME}
COMMAND ${CMAKE_COMMAND} -P ${GIT_EXTERNAL_SCRIPT}
COMMENT "Update ${REPO} in ${FILE}"
DEPENDS update_git_external_header
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_dependencies(update_git_external
update_git_external_${GIT_EXTERNAL_NAME})
endif()
endif()
endforeach()
endfunction()

function(GIT_EXTERNAL DIR REPO TAG)
cmake_parse_arguments(GIT_EXTERNAL "" "" "RESET" ${ARGN})
get_filename_component(DIR "${DIR}" ABSOLUTE)
Expand All @@ -109,6 +34,14 @@ function(GIT_EXTERNAL DIR REPO TAG)
endif()

if(IS_DIRECTORY "${DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
OUTPUT_VARIABLE currentref OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${DIR})
if(currentref STREQUAL TAG) # nothing to do
return()
endif()

# reset generated files
foreach(GIT_EXTERNAL_RESET_FILE ${GIT_EXTERNAL_RESET})
execute_process(
COMMAND "${GIT_EXECUTABLE}" reset -q "${GIT_EXTERNAL_RESET_FILE}"
Expand All @@ -120,20 +53,105 @@ function(GIT_EXTERNAL DIR REPO TAG)
WORKING_DIRECTORY "${DIR}")
endforeach()

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

# checkout requested tag
execute_process(
COMMAND "${GIT_EXECUTABLE}" checkout -q "${TAG}"
RESULT_VARIABLE nok ERROR_VARIABLE error
WORKING_DIRECTORY "${DIR}"
)
if(nok)
message(FATAL_ERROR "${DIR} git checkout ${TAG} failed: ${error}\n")
message(STATUS "${DIR} git checkout ${TAG} failed: ${error}\n")
endif()
else()
message(STATUS "Can't update git external ${DIR}: Not a git repository")
endif()
endfunction()

set(GIT_EXTERNALS ${GIT_EXTERNALS_FILE})
if(NOT GIT_EXTERNALS)
set(GIT_EXTERNALS "${CMAKE_CURRENT_SOURCE_DIR}/.gitexternals")
endif()

if(EXISTS ${GIT_EXTERNALS})
file(READ ${GIT_EXTERNALS} GIT_EXTERNAL_FILE)
string(REGEX REPLACE "\n" ";" GIT_EXTERNAL_FILE "${GIT_EXTERNAL_FILE}")
foreach(LINE ${GIT_EXTERNAL_FILE})
if(NOT LINE MATCHES "^#.*$")
message(FATAL_ERROR "${GIT_EXTERNALS} contains non-comment line: ${LINE}")
endif()
string(REGEX REPLACE "^#[ ]*(.+[ ]+.+[ ]+.+)$" "\\1" DATA ${LINE})
if(NOT LINE STREQUAL DATA)
string(REGEX REPLACE "[ ]+" ";" DATA "${DATA}")
list(LENGTH DATA DATA_LENGTH)
if(DATA_LENGTH EQUAL 3)
list(GET DATA 0 DIR)
list(GET DATA 1 REPO)
list(GET DATA 2 TAG)

# Create a unique, flat name
string(REPLACE "/" "_" GIT_EXTERNAL_NAME ${DIR})

if(NOT TARGET update_git_external_${GIT_EXTERNAL_NAME}) # not done
# pull in identified external
git_external(${DIR} ${REPO} ${TAG})

# Create update script and target to bump external spec
if(NOT TARGET update)
add_custom_target(update)
endif()
if(NOT TARGET update_git_external)
add_custom_target(update_git_external)
add_dependencies(update update_git_external)
endif()

# Create a unique, flat name
file(RELATIVE_PATH GIT_EXTERNALS_BASE ${CMAKE_SOURCE_DIR}
${GIT_EXTERNALS})
string(REPLACE "/" "_" GIT_EXTERNAL_TARGET ${GIT_EXTERNALS_BASE})

set(GIT_EXTERNAL_TARGET update_git_external_${GIT_EXTERNAL_TARGET})
if(NOT TARGET ${GIT_EXTERNAL_TARGET})
set(GIT_EXTERNAL_SCRIPT
"${CMAKE_CURRENT_BINARY_DIR}/${GIT_EXTERNAL_TARGET}.cmake")
file(WRITE "${GIT_EXTERNAL_SCRIPT}"
"file(WRITE ${GIT_EXTERNALS} \"# -*- mode: cmake -*-\n\")\n")
add_custom_target(${GIT_EXTERNAL_TARGET}
COMMAND ${CMAKE_COMMAND} -P ${GIT_EXTERNAL_SCRIPT}
COMMENT "Recreate ${GIT_EXTERNALS_BASE}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endif()

set(GIT_EXTERNAL_SCRIPT
"${CMAKE_CURRENT_BINARY_DIR}/gitupdate${GIT_EXTERNAL_NAME}.cmake")
file(WRITE "${GIT_EXTERNAL_SCRIPT}" "
execute_process(COMMAND ${GIT_EXECUTABLE} fetch --all -q
WORKING_DIRECTORY ${DIR})
execute_process(
COMMAND ${GIT_EXECUTABLE} show-ref --hash=7 refs/remotes/origin/master
OUTPUT_VARIABLE newref WORKING_DIRECTORY ${DIR})
if(newref)
file(APPEND ${GIT_EXTERNALS} \"# ${DIR} ${REPO} \${newref}\")
else()
file(APPEND ${GIT_EXTERNALS} \"# ${DIR} ${REPO} ${TAG}\n\")
endif()")
add_custom_target(update_git_external_${GIT_EXTERNAL_NAME}
COMMAND ${CMAKE_COMMAND} -P ${GIT_EXTERNAL_SCRIPT}
COMMENT "Update ${REPO} in ${GIT_EXTERNALS_BASE}"
DEPENDS ${GIT_EXTERNAL_TARGET}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_dependencies(update_git_external
update_git_external_${GIT_EXTERNAL_NAME})
endif()
endif()
endif()
endforeach()
include(${GIT_EXTERNALS})
endif()
15 changes: 10 additions & 5 deletions CMakeLists.txt
Expand Up @@ -5,9 +5,11 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(Equalizer)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake
${CMAKE_SOURCE_DIR}/CMake/common)
include(.gitexternals)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake
${CMAKE_CURRENT_SOURCE_DIR}/CMake/common)

include(GitExternal)
include(Common)

include(Buildyard)
if(BUILDYARD_STOP)
Expand All @@ -22,14 +24,18 @@ option(EQUALIZER_BUILD_2_0_API

mark_as_advanced(EQUALIZER_INSTALL_SERVER_HEADERS)

include(Revision)
include(GitInfo)

set(RELEASE_VERSION OFF) # OFF or 'Mm0' ABI version
set(LAST_RELEASE 1.6.0)
set(VERSION_MAJOR "1")
set(VERSION_MINOR "7")
set(VERSION_PATCH "2")

set(COMMON_PROJECT_DOMAIN ch.eyescale)
set(EQUALIZER_DESCRIPTION "Parallel rendering framework for the creation of
parallel and scalable OpenGL and GPGPU applications.")

if(RELEASE_VERSION)
set(EQ_DEFINITIONS -DEQ_RELEASE)
set(VERSION_ABI ${RELEASE_VERSION})
Expand All @@ -44,7 +50,6 @@ else()
list(APPEND FIND_PACKAGES_DEFINES EQ_1_0_API)
endif()

include(Common)
include(GitTargets)
include(configure)
include(UpdateFile)
Expand Down
2 changes: 1 addition & 1 deletion eq/client/CMakeLists.txt
Expand Up @@ -16,7 +16,7 @@ include(files.cmake)
include(../util/files.cmake)
include(compressor/files.cmake)

update_file(${CMAKE_CURRENT_SOURCE_DIR}/version.in.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.in.h
${OUTPUT_INCLUDE_DIR}/eq/client/version.h)

add_definitions(-DEQ_PLUGIN_BUILD -DBOOST_PROGRAM_OPTIONS_DYN_LINK)
Expand Down
4 changes: 2 additions & 2 deletions eq/client/roiFinder.cpp
Expand Up @@ -469,7 +469,7 @@ uint8_t ROIFinder::_splitArea( Area& a )

void ROIFinder::_findAreas( PixelViewports& resultPVPs )
{
LBASSERT( _areasToCheck.size() == 0 );
LBASSERT( _areasToCheck.empty() );

Area area( PixelViewport( 0, 0, _w, _h ));
area.pvp = _getObjectPVP( area.pvp, &_mask[0] );
Expand All @@ -485,7 +485,7 @@ void ROIFinder::_findAreas( PixelViewports& resultPVPs )
_areasToCheck.push_back( area );

// try to split areas
while( _areasToCheck.size() > 0 )
while( !_areasToCheck.empty() )
{
Area curArea = _areasToCheck.back();
_areasToCheck.pop_back();
Expand Down
4 changes: 3 additions & 1 deletion eq/client/roiFinder.h
Expand Up @@ -107,7 +107,9 @@ class ROIFinder : public boost::noncopyable
/** Describes region that is used to search holes withing */
struct Area
{
Area(){};
Area()
: valid( false )
{};
Area( PixelViewport pvp_ )
: emptySize( 0 ), pvp ( pvp_ ), valid( false )
{}
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Expand Up @@ -5,7 +5,7 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

if(Equalizer_BINARY_DIR) # in-repository build
update_file(CMakeLists.txt ${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt)
configure_file(CMakeLists.txt ${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt)

set(EQUALIZER_LIBRARIES Equalizer)
set(EQUALIZER_ADMIN_LIBRARY EqualizerAdmin)
Expand Down
2 changes: 1 addition & 1 deletion examples/triply/vertexBufferRoot.h
Expand Up @@ -50,7 +50,7 @@ class VertexBufferRoot : public VertexBufferNode
PLYLIB_API void setupTree( VertexData& data );
PLYLIB_API bool writeToFile( const std::string& filename );
PLYLIB_API bool readFromFile( const std::string& filename );
bool hasColors() const { return _data.colors.size() > 0; }
bool hasColors() const { return !_data.colors.empty(); }

void useInvertedFaces() { _invertFaces = true; }

Expand Down

0 comments on commit c07ceb6

Please sign in to comment.