Skip to content

Commit

Permalink
(conan-io#15704) argtable3: fix target name regression in CMakeDeps
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored and sabelka committed Feb 12, 2023
1 parent 99de1cf commit be9e5eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 7 additions & 10 deletions recipes/argtable3/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,19 @@ def build(self):
cmake.configure()
cmake.build()

@property
def _module_subfolder(self):
return os.path.join("lib", "cmake")

@property
def _module_file_rel_path(self):
return os.path.join(self._module_subfolder,
"conan-official-{}-targets.cmake".format(self.name))
return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake")

def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
content += textwrap.dedent(f"""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
""")
save(self, module_file, content)

def package(self):
Expand All @@ -84,7 +79,7 @@ def package(self):
rmdir(self, os.path.join(self.package_folder, "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

# These targets were for versions <= 3.2.0 (newer create argtable3::argtable3)
# These targets were for versions < 3.2.1 (newer create argtable3::argtable3)
target_name = "argtable3" if self.options.shared else "argtable3_static"
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
Expand All @@ -102,7 +97,9 @@ def package_info(self):
self.cpp_info.system_libs.append("m")

self.cpp_info.set_property("cmake_file_name", "Argtable3")
self.cpp_info.set_property("cmake_target_name", "argtable3")
self.cpp_info.set_property("cmake_target_name", "argtable3::argtable3")
# These targets were for versions < 3.2.1 (newer create argtable3::argtable3)
self.cpp_info.set_property("cmake_target_aliases", ["argtable3" if self.options.shared else "argtable3_static"])

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "Argtable3"
Expand Down
4 changes: 3 additions & 1 deletion recipes/argtable3/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ project(test_package LANGUAGES C)
find_package(Argtable3 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
if(TARGET argtable3)
if(Argtable3_VERSION VERSION_GREATER_EQUAL "3.2.1")
target_link_libraries(${PROJECT_NAME} PRIVATE argtable3::argtable3)
elseif(TARGET argtable3)
target_link_libraries(${PROJECT_NAME} PRIVATE argtable3)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE argtable3_static)
Expand Down

0 comments on commit be9e5eb

Please sign in to comment.