Commit a22d5c4b authored by Lynn Garren's avatar Lynn Garren

fix CLHEP-137

parent f8ad330a
2017-03-21 Lynn Garren <garren@fnal.gov>
* cmake/Modules/ClhepOutOfSourceBuild.cmake: fix CLHEP-137
* cmake/Modules/ClhepRegexEscape.cmake: regex escape function
* Vector/src/RotationA.cc:
fix for CLHEP-141 supplied by Evgueni Tcherniaev
* Vector/test/testRotationAxis.cc:
......
......@@ -2,10 +2,17 @@
# clhep_ensure_out_of_source_build()
#
# we need the full path here because we check for an out of source build before anything else
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/ClhepRegexEscape.cmake)
macro (clhep_ensure_out_of_source_build)
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" in_source)
string( REGEX MATCH "${CMAKE_SOURCE_DIR}/" in_source_subdir "${CMAKE_BINARY_DIR}")
clhep_regex_escape( "${CMAKE_SOURCE_DIR}" escaped_path)
set(my_source_dir "^${escaped_path}$")
clhep_regex_escape( "${CMAKE_BINARY_DIR}" escaped_path)
set(my_binary_dir "^${escaped_path}$")
string( REGEX MATCH "${my_source_dir}/" in_source_subdir "${my_binary_dir}")
if (in_source OR in_source_subdir)
message(FATAL_ERROR "
ERROR: In source builds of this project are not allowed.
......
########################################################################
# clhep_regex_escape(<val> <var> [<num>])
#
# Escape the provided string to prevent interpretation by the CMake
# regex engine.
#
# The result of escaping characters which would be interpreted by
# CMake's regex engine is passed through clhep_armor_string if <num> is
# specified and non-zero.
#
########################################################################
# clhep_armor_string(<val> <var> <num>)
#
# Armor the instances of "\" in the string aginst being passed to a
# macro (and therefore being interpolated).
#
# The <num> argument indicates the expected interpolation level for the
# resulting string (0 is a NOP). Every time the string is expected to be
# passed to a macro, increase <num> to ensure that "\" are correctly
# handled. This is not necessary for a function.
#
########################################################################
# Author: Chris Green
# See ClhepOutOfSourceBuild for usage
########################################################################
function(clhep_regex_escape val var)
string(REGEX REPLACE "(\\.|\\||\\^|\\$|\\*|\\(|\\)|\\[|\\]|\\+)" "\\\\\\1" val "${val}")
string(REGEX REPLACE "/+" "/" val "${val}")
if (ARGN)
list(GET ARGN 0 count)
endif()
if (count)
clhep_armor_string("${val}" val ${count})
endif()
set(${var} "${val}" PARENT_SCOPE)
endfunction()
function(clhep_armor_string val var count)
while (count GREATER 0) # Extra escapes for passing to macros.
string(REPLACE "\\" "\\\\" val "${val}")
math(EXPR count "${count} - 1")
endwhile()
set(${var} "${val}" PARENT_SCOPE)
endfunction()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment