Skip to content

Commit 39e9283

Browse files
xiazuoling.xzlzeroxia
xiazuoling.xzl
authored andcommitted
cmake export configuration: allow repeating find_package(jsoncpp) calls
In jsoncpp-namspaced-targets.cmake, it creates JsonCpp::JsonCpp imported library without first checking whether it was already created by former call to find_package(JsonCpp). As CMake allows repeated call to find_package(), the error of "another target with the same name already exists" should be fixed.
1 parent 69098a1 commit 39e9283

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

jsoncpp-namespaced-targets.cmake

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
if (TARGET jsoncpp_static)
2-
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
3-
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_static")
4-
elseif (TARGET jsoncpp_lib)
5-
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
6-
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib")
7-
endif ()
1+
if (NOT TARGET JsonCpp::JsonCpp)
2+
if (TARGET jsoncpp_static)
3+
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
4+
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_static")
5+
elseif (TARGET jsoncpp_lib)
6+
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
7+
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib")
8+
endif ()
9+
endif ()

0 commit comments

Comments
 (0)