Skip to content

Commit ea62d10

Browse files
authored
Merge pull request #250 from FeignClaims/fix/foreach_genex
2 parents da5f308 + 9db1d52 commit ea62d10

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

src/PackageProject.cmake

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include_guard()
22

3+
include("${CMAKE_CURRENT_LIST_DIR}/Utilities.cmake")
4+
35
# Uses ycm (permissive BSD-3-Clause license) and ForwardArguments (permissive MIT license)
46

57
function(get_property_of_targets)
@@ -15,7 +17,8 @@ function(get_property_of_targets)
1517
list(APPEND _Value ${_Current_property})
1618
endif()
1719
endforeach()
18-
list(REMOVE_DUPLICATES _Current_property)
20+
convert_genex_semicolons("${_Value}" _Value)
21+
list(REMOVE_DUPLICATES _Value)
1922
set(${args_OUTPUT} ${_Value} PARENT_SCOPE)
2023
endfunction()
2124

src/SystemLink.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include_guard()
22

3+
include("${CMAKE_CURRENT_LIST_DIR}/Utilities.cmake")
4+
35
#[[.rst:
46
57
``target_include_system_directories``
@@ -18,6 +20,7 @@ function(target_include_system_directories target)
1820
cmake_parse_arguments(ARG "" "" "${multiValueArgs}" ${ARGN})
1921

2022
foreach(scope IN ITEMS INTERFACE PUBLIC PRIVATE)
23+
convert_genex_semicolons("${ARG_${scope}}" "ARG_${scope}")
2124
foreach(lib_include_dirs IN LISTS ARG_${scope})
2225
if(NOT MSVC OR (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0"
2326
AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "19.29.30036.3")
@@ -83,6 +86,7 @@ function(target_link_system_libraries target)
8386
cmake_parse_arguments(ARG "" "" "${multiValueArgs}" ${ARGN})
8487

8588
foreach(scope IN ITEMS INTERFACE PUBLIC PRIVATE)
89+
convert_genex_semicolons("${ARG_${scope}}" "ARG_${scope}")
8690
foreach(lib IN LISTS ARG_${scope})
8791
target_link_system_library(${target} ${scope} ${lib})
8892
endforeach()

src/Utilities.cmake

+49
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,52 @@ function(detect_architecture arch)
124124
set(${arch} x64 PARENT_SCOPE)
125125
endif()
126126
endfunction()
127+
128+
# convert semicolons in generator expression to $<SEMICOLON>
129+
function(convert_genex_semicolons genex output)
130+
set(result)
131+
132+
set(depth 0)
133+
set(index 0)
134+
set(prefixed_with_dollar FALSE)
135+
string(LENGTH "${genex}" length)
136+
137+
while(index LESS length)
138+
string(SUBSTRING "${genex}" ${index} 1 ch)
139+
140+
if(ch STREQUAL "$")
141+
set(prefixed_with_dollar TRUE)
142+
string(APPEND result "${ch}")
143+
elseif(ch STREQUAL "<")
144+
if(prefixed_with_dollar)
145+
set(prefixed_with_dollar FALSE)
146+
math(EXPR depth "${depth}+1")
147+
endif()
148+
149+
string(APPEND result "${ch}")
150+
elseif(ch STREQUAL ">")
151+
set(prefixed_with_dollar FALSE)
152+
153+
if(depth GREATER 0)
154+
math(EXPR depth "${depth}-1")
155+
endif()
156+
157+
string(APPEND result "${ch}")
158+
elseif(ch STREQUAL ";")
159+
set(prefixed_with_dollar FALSE)
160+
161+
if(depth GREATER 0)
162+
string(APPEND result "$<SEMICOLON>")
163+
else()
164+
string(APPEND result "${ch}")
165+
endif()
166+
else()
167+
set(prefixed_with_dollar FALSE)
168+
string(APPEND result "${ch}")
169+
endif()
170+
171+
math(EXPR index "${index}+1")
172+
endwhile()
173+
174+
set("${output}" "${result}" PARENT_SCOPE)
175+
endfunction()

tests/myproj/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ add_test(NAME main COMMAND main)
102102
# Header-only library
103103
add_library(lib INTERFACE)
104104
set(lib_INCLUDE_DIR "include")
105-
target_include_directories(
106-
lib INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${lib_INCLUDE_DIR}>"
107-
"$<INSTALL_INTERFACE:./${CMAKE_INSTALL_INCLUDEDIR}>"
105+
target_include_system_directories( # Test the fix of semicolon in genex issue
106+
lib INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/${lib_INCLUDE_DIR}>"
107+
"$<INSTALL_INTERFACE:./${CMAKE_INSTALL_INCLUDEDIR}>"
108108
) # TODO(refactor)
109109
target_link_libraries(lib INTERFACE myproj_project_options myproj_project_warnings)
110110
target_link_system_libraries(lib INTERFACE fmt::fmt Eigen3::Eigen)

0 commit comments

Comments
 (0)