Skip to content

Commit

Permalink
cmake export configuration: allow repeating find_package(jsoncpp) calls
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xiazuoling.xzl committed Jun 9, 2023
1 parent 3d9bf8e commit 944b296
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions jsoncpp-namespaced-targets.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
if (TARGET jsoncpp_static)
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_static")
elseif (TARGET jsoncpp_lib)
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib")
endif ()
if (NOT TARGET JsonCpp::JsonCpp)
if (TARGET jsoncpp_static)
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_static")
elseif (TARGET jsoncpp_lib)
add_library(JsonCpp::JsonCpp INTERFACE IMPORTED)
set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib")
endif ()
endif ()

0 comments on commit 944b296

Please sign in to comment.