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

Draft: 1005 cmake reruns on code changes #1144

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
64 changes: 42 additions & 22 deletions cmake-modules/GetGitRevisionDescription.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,62 @@ set(__get_git_revision_description YES)
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)

function(git_hash_info _headfile _git_dir _ref _hash)
set(HEAD_HASH)

file(READ "${_headfile}" HEAD_CONTENTS LIMIT 1024)

string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "${_git_dir}/${HEAD_REF}")
file(READ "${_git_dir}/${HEAD_REF}" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
else()
file(READ "${_git_data}/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif()
endif()

set(${_ref} "${HEAD_REF}" PARENT_SCOPE)
set(${_hash} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()


function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
if (NOT GIT_DIR)
set(_git_dir "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${_git_dir}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(_git_dir "${GIT_PARENT_DIR}/.git")
endwhile()
set(GIT_DIR "${_git_dir}" CACHE PATH "Path to the Git directory")
endif()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()

if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
set(HEAD_FILE "${GIT_DIR}/HEAD")

configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")
git_hash_info("${HEAD_FILE}" "${GIT_DIR}" HEAD_REF HEAD_HASH)

set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
Expand Down
41 changes: 0 additions & 41 deletions cmake-modules/GetGitRevisionDescription.cmake.in

This file was deleted.

2 changes: 0 additions & 2 deletions cmake/build_git_info.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

include(GetGitRevisionDescription)

get_git_head_revision(GIT_REFSPEC GIT_SHA1)

# set some variables related to GIT state information
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
git_describe(GIT_EXACT_TAG --tags --abbrev=0 --all)
Expand Down
10 changes: 6 additions & 4 deletions cmake/local_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ macro(find_package_local pkg_name pkg_directory pkg_other_name)

#message(STATUS "skipping find_package for ${pkg_name}")
else()
message(
STATUS "find_package_local: pkg name=\"${pkg_name}\", "
"directory=\"${pkg_directory}\""
)
if (NOT ${pkg_name})
message(
STATUS "find_package_local: pkg name=\"${pkg_name}\", "
"directory=\"${pkg_directory}\""
)
endif()

# Rest of the arguments are potential relative search paths wrt the
# ${pkg_directory}
Expand Down
17 changes: 8 additions & 9 deletions cmake/turn_on_warnings.cmake
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
include(CheckCXXCompilerFlag)

function(enable_cxx_compiler_flag_if_supported flag)
function(enable_cxx_compiler_flag_if_supported flag var)
string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set)
if(flag_already_set EQUAL -1)
check_cxx_compiler_flag("${flag}" flag_supported)
check_cxx_compiler_flag("${flag}" ${var})
if(flag_supported)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
endif()
unset(flag_supported CACHE)
endif()
endfunction()

get_directory_property(hasParent PARENT_DIRECTORY)
if(NOT hasParent)
enable_cxx_compiler_flag_if_supported("-Wall")
enable_cxx_compiler_flag_if_supported("-pedantic")
enable_cxx_compiler_flag_if_supported("-Wshadow")
enable_cxx_compiler_flag_if_supported("-Wno-unknown-pragmas")
enable_cxx_compiler_flag_if_supported("-Wsign-compare")
enable_cxx_compiler_flag_if_supported("-Wall" VT_WALL_FLAG_SUPPORTED)
enable_cxx_compiler_flag_if_supported("-pedantic" VT_PEDANTIC_FLAG_SUPPORTED)
enable_cxx_compiler_flag_if_supported("-Wshadow" VT_WSHADOW_FLAG_SUPPORTED)
enable_cxx_compiler_flag_if_supported("-Wno-unknown-pragmas" VT_WNO_UNKNOWN_PRAGMAS_FLAG_SUPPORTED)
enable_cxx_compiler_flag_if_supported("-Wsign-compare" VT_WSIGN_COMPARE_SUPPORTED)
# Not really a warning, is still diagnostic related..
enable_cxx_compiler_flag_if_supported("-ftemplate-backtrace-limit=100")
enable_cxx_compiler_flag_if_supported("-ftemplate-backtrace-limit=100" VT_FTEMPLATE_BACKTRACE_LIMIT_SUPPORTED)
endif()