Skip to content

Set tinyxml2_LIBRARIES after find_package()#3918

Merged
danmar merged 1 commit into
cppcheck-opensource:mainfrom
c72578:2022-03-20_Set_tinyxml2_LIBRARIES_after_find_package
Mar 22, 2022
Merged

Set tinyxml2_LIBRARIES after find_package()#3918
danmar merged 1 commit into
cppcheck-opensource:mainfrom
c72578:2022-03-20_Set_tinyxml2_LIBRARIES_after_find_package

Conversation

@c72578

@c72578 c72578 commented Mar 20, 2022

Copy link
Copy Markdown
Contributor

If tinyxml2 is found by find_package(), then tinyxml2_LIBRARIES
is empty. Set tinyxml2_LIBRARIES to "tinyxml2::tinyxml2" in this case.

  • Fixes "undefined reference to tinyxml2::`"
  • printInfo.cmake: Fix indentation of tinyxml2_LIBRARIES

@c72578 c72578 force-pushed the 2022-03-20_Set_tinyxml2_LIBRARIES_after_find_package branch from 92c1772 to 10f1595 Compare March 20, 2022 06:10
@c72578

c72578 commented Mar 20, 2022

Copy link
Copy Markdown
Contributor Author
-- ------------------ General configuration for Cppcheck 2.7.3 -----------------
...
-- USE_BUNDLED_TINYXML2 =  OFF
-- tinyxml2_LIBRARIES =    tinyxml2

@c72578

c72578 commented Mar 20, 2022

Copy link
Copy Markdown
Contributor Author

This is a followup to #3897
@firewave, @gdsotirov could you please have a look.

@c72578 c72578 marked this pull request as ready for review March 20, 2022 06:28
@gdsotirov

Copy link
Copy Markdown
Contributor

@c72578 I had the same problem, because tinyxml2 installs an incomplete CMake module/package, which does not set any of the expected <package>_LIB* or <package>_INC* variables (see issue 904). So I removed it from tinyxml2 package, because I can imagine problems with other dependents. Otherwise, if tinyxml2_LIBRARIES is not set after find_package (to account for the insufficiency) perhpas it is better to call find_library, i.e. simply:

diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake
index d1cf61848..a91b89053 100644
--- a/cmake/findDependencies.cmake
+++ b/cmake/findDependencies.cmake
@@ -47,7 +47,7 @@ endif()

 if (NOT USE_BUNDLED_TINYXML2)
     find_package(tinyxml2 QUIET)
-    if (NOT tinyxml2_FOUND)
+    if (NOT tinyxml2_FOUND OR NOT tinyxml2_LIBRARIES)
         find_library(tinyxml2_LIBRARIES tinyxml2)
         if (NOT tinyxml2_LIBRARIES)
             message(FATAL_ERROR "tinyxml2 has not been found")

I did not tough of this before, but it seems more rational now.

@c72578

c72578 commented Mar 20, 2022

Copy link
Copy Markdown
Contributor Author

@gdsotirov Thanks for the feedback and the link to the upstream tinyxml2 issue leethomason/tinyxml2#904.

These variables are currently available after find_package(tinyxml2 QUIET) (output according to [1]):

  • tinyxml2 7.0.1:
-- tinyxml2_CONFIG=/usr/lib64/cmake/tinyxml2/tinyxml2Config.cmake
-- tinyxml2_CONSIDERED_CONFIGS=/usr/lib64/cmake/tinyxml2/tinyxml2Config.cmake
-- tinyxml2_CONSIDERED_VERSIONS=unknown
-- tinyxml2_DIR=/usr/lib64/cmake/tinyxml2
-- tinyxml2_FOUND=1
-- tinyxml2_VERSION_COUNT=0
-- tinyxml2_VERSION_MAJOR=0
-- tinyxml2_VERSION_MINOR=0
-- tinyxml2_VERSION_PATCH=0
-- tinyxml2_VERSION_TWEAK=0
  • tinyxml2 9.0.0:
-- tinyxml2_CONFIG=/usr/lib64/cmake/tinyxml2/tinyxml2-config.cmake
-- tinyxml2_CONSIDERED_CONFIGS=/usr/lib64/cmake/tinyxml2/tinyxml2-config.cmake
-- tinyxml2_CONSIDERED_VERSIONS=9.0.0
-- tinyxml2_DIR=/usr/lib64/cmake/tinyxml2
-- tinyxml2_FOUND=1
-- tinyxml2_VERSION=9.0.0
-- tinyxml2_VERSION_COUNT=3
-- tinyxml2_VERSION_MAJOR=9
-- tinyxml2_VERSION_MINOR=0
-- tinyxml2_VERSION_PATCH=0
-- tinyxml2_VERSION_TWEAK=0
-- tinyxml2_comp_shared=NO
-- tinyxml2_comp_static=NO
-- tinyxml2_known_comps=static;shared
-- tinyxml2_shared_targets=/usr/lib64/cmake/tinyxml2/tinyxml2-shared-targets.cmake
-- tinyxml2_static_targets=/usr/lib64/cmake/tinyxml2/tinyxml2-static-targets.cmake

So yes, currently there is no <package>_LIB* set.

[1] https://stackoverflow.com/a/9328525/5067752

@gdsotirov

gdsotirov commented Mar 20, 2022

Copy link
Copy Markdown
Contributor

Indeed, no <package>_LIB* variables set, but since cppcheck only needs tinyxml2_LIBRARIES it could be fixed with either what you or I suggest. I removed tinyxml2's CMake files, because I'm not sure whether it would not break other packages that depend on tinyxml2. Have you noticed such problems @c72578 ? I had no builds of tinyxml2 since 4.0.1 and the CMake files seem to be installed with the latest versions, so I hit the problem with 9.x, but apparently it should have existed with 7.x as well.

Comment thread cmake/findDependencies.cmake Outdated
@c72578 c72578 marked this pull request as draft March 20, 2022 13:33
If tinyxml2 is found by find_package(), then tinyxml2_LIBRARIES
is empty. Set tinyxml2_LIBRARIES to "tinyxml2::tinyxml2" in this case.

- Fixes "undefined reference to `tinyxml2::"
- printInfo.cmake: Fix indentation of tinyxml2_LIBRARIES
@c72578 c72578 force-pushed the 2022-03-20_Set_tinyxml2_LIBRARIES_after_find_package branch from 10f1595 to 72ff5fd Compare March 20, 2022 13:58
@c72578

c72578 commented Mar 20, 2022

Copy link
Copy Markdown
Contributor Author

Here's a sketch that would be better.

find_package(tinyxml2 QUIET)
if (TARGET tinyxml2::tinyxml2)
  set(tinyxml2_LIBRARIES "tinyxml2::tinyxml2")
else ()
  # as before ...
endif ()

@alexreinking Thanks for taking the time to have a look at this PR and the feedback.
I have updated the PR according to your suggestion.

@c72578

c72578 commented Mar 20, 2022

Copy link
Copy Markdown
Contributor Author
  • New output from printInfo.cmake:
-- ------------------ General configuration for Cppcheck 2.7.3 -----------------
...
-- USE_BUNDLED_TINYXML2 =  OFF
-- tinyxml2_LIBRARIES =    tinyxml2::tinyxml2

@c72578 c72578 marked this pull request as ready for review March 20, 2022 14:08
Comment thread cmake/findDependencies.cmake
@danmar

danmar commented Mar 21, 2022

Copy link
Copy Markdown
Collaborator

I have no idea about this.. when everbody is happy I feel I can merge this..

@gdsotirov

Copy link
Copy Markdown
Contributor

It works for me.

gdsotirov added a commit to gdsotirov/tinyxml2.SlackBuild that referenced this pull request Mar 22, 2022
It should not be necessary after PR 3918 is merged.

See cppcheck-opensource/cppcheck#3918
@danmar danmar merged commit 3cefba0 into cppcheck-opensource:main Mar 22, 2022
@danmar

danmar commented Mar 22, 2022

Copy link
Copy Markdown
Collaborator

Well.. if you feel that a new 2.7.x tag is wanted that has these changes then ping me.

@firewave

Copy link
Copy Markdown
Collaborator

Well.. if you feel that a new 2.7.x tag is wanted that has these changes then ping me.

Yeah, we need that so it works without additional patches.

@c72578

c72578 commented Mar 23, 2022

Copy link
Copy Markdown
Contributor Author

I will prepare a PR for the 2.7.x branch ...

@c72578

c72578 commented Mar 25, 2022

Copy link
Copy Markdown
Contributor Author

A PR for the 2.7.x branch has been prepared: #3932

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants