Skip to content

Commit

Permalink
(#13027) jsoncpp: also provide JsonCpp::JsonCpp target
Browse files Browse the repository at this point in the history
target added in upstream config file in 1.9.5 (open-source-parsers/jsoncpp#1271)
  • Loading branch information
SpaceIm authored Sep 21, 2022
1 parent 79e088a commit e2c75e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
12 changes: 9 additions & 3 deletions recipes/jsoncpp/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

# TODO: to remove in conan v2 once legacy generators removed
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{
"JsonCpp::JsonCpp": "jsoncpp::jsoncpp", # alias target since 1.9.5
"jsoncpp_lib": "jsoncpp::jsoncpp", # imported target for shared lib, but also static between 1.9.0 & 1.9.3
"jsoncpp_static": "jsoncpp::jsoncpp", # imported target for static lib if >= 1.9.4
"jsoncpp_lib_static": "jsoncpp::jsoncpp", # imported target for static lib if < 1.9.0
Expand All @@ -110,13 +113,16 @@ def _module_file_rel_path(self):

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "jsoncpp")
self.cpp_info.set_property("cmake_target_name", "jsoncpp_lib")
if not self.options.shared:
self.cpp_info.set_property("cmake_target_aliases", ["jsoncpp_static", "jsoncpp_lib_static"])
self.cpp_info.set_property("cmake_target_name", "JsonCpp::JsonCpp")
self.cpp_info.set_property(
"cmake_target_aliases",
["jsoncpp_lib"] if self.options.shared else ["jsoncpp_lib", "jsoncpp_static", "jsoncpp_lib_static"],
)
self.cpp_info.set_property("pkg_config_name", "jsoncpp")
self.cpp_info.libs = ["jsoncpp"]
if self.settings.os == "Windows" and self.options.shared:
self.cpp_info.defines.append("JSON_DLL")

# TODO: to remove in conan v2 once legacy generators removed
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
6 changes: 1 addition & 5 deletions recipes/jsoncpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ project(test_package LANGUAGES CXX)
find_package(jsoncpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
if(JSONCPP_SHARED)
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_lib)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_static)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE JsonCpp::JsonCpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
10 changes: 3 additions & 7 deletions recipes/jsoncpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["JSONCPP_SHARED"] = self.dependencies["jsoncpp"].options.shared
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
Expand Down
6 changes: 1 addition & 5 deletions recipes/jsoncpp/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,5 @@ conan_basic_setup(TARGETS)
find_package(jsoncpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
if(JSONCPP_SHARED)
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_lib)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_static)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE JsonCpp::JsonCpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
1 change: 0 additions & 1 deletion recipes/jsoncpp/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class TestPackageConan(ConanFile):

def build(self):
cmake = CMake(self)
cmake.definitions["JSONCPP_SHARED"] = self.options["jsoncpp"].shared
cmake.configure()
cmake.build()

Expand Down

0 comments on commit e2c75e7

Please sign in to comment.