Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

Commit

Permalink
Fix for bug in add_gtests CMake script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser Hutchison committed Mar 14, 2015
1 parent 56e07ce commit 3d21070
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions cmake_modules/add_gtests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,21 @@ function(get_gtest_typedef_types FileContents)
message(AUTHOR_WARNING "Unexpected parsing failure of gtest aliases.")
return()
endif()
# We don't need to know the actual types, we ultimately only need a count. Remove all commas except
# those separating the list of types (there could be some inside a type's template args, e.g.
# std::pair<int, int> should count as one variable, not two.) Also remove whitespace.
string(REGEX REPLACE "<[^>]*>|[ \t\n]" "" Types "${Types}")
# Turn the comma-separated list into a CMake list
string(REGEX REPLACE "," ";" Types "${Types}")
set(${AliasName}Var ${Types} PARENT_SCOPE)
# We don't need to know the actual types, we ultimately only need a count. Iterate through the
# string counting commas which are outside angle brackets.
set(AngleBracketDepth 0)
set(TypePlaceholders T)
string(REGEX REPLACE "(.)" "\\1;" Types "${Types}")
foreach(Char ${Types})
if(Char STREQUAL "," AND AngleBracketDepth EQUAL 0)
list(APPEND TypePlaceholders T)
elseif(Char STREQUAL "<")
math(EXPR AngleBracketDepth ${AngleBracketDepth}+1)
elseif(Char STREQUAL ">")
math(EXPR AngleBracketDepth ${AngleBracketDepth}-1)
endif()
endforeach()
set(${AliasName}Var ${TypePlaceholders} PARENT_SCOPE)
endforeach()
endfunction()

Expand Down

0 comments on commit 3d21070

Please sign in to comment.