Skip to content

Conversation

@traversaro
Copy link
Contributor

@traversaro traversaro commented Oct 14, 2020

Use standard CMake functions to generate the CMake config files.

In particular, this PR fixes the following issues:
Fix #1517
Fix #3260
Fix #3365

In particular, it reduces the difference between the normal CMake build and the CMake build with Hunter enabled (option ASSIMP_HUNTER_ENABLED enabled). Unfortunately the Hunter build at the moment generates imported targets that are named Assimp::assimp while the regular build have generated imported targets named assimp::assimp for a long time, so it is still necessary to account for that for backcompatibility.

traversaro added a commit to traversaro/assimp-feedstock that referenced this pull request Oct 14, 2020
traversaro added a commit to traversaro/assimp-feedstock that referenced this pull request Oct 14, 2020
traversaro added a commit to traversaro/assimp-feedstock that referenced this pull request Oct 14, 2020
@rbsheth
Copy link
Contributor

rbsheth commented Oct 14, 2020

@traversaro we can alias assimp::assimp targets to Assimp::assimp in the config file, if that allows you to consolidate more. See https://github.com/cpp-pm/zlib/blob/hunter-1.2.11/cmake/Config.cmake.in#L6 for an example.

@@ -0,0 +1,9 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also put conditionals into the config file, so you can consolidate the Hunter and non-Hunter config files. See https://github.com/cpp-pm/meshoptimizer/blob/hunter-0.14-a507623/config.cmake.in#L3 for an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is more readable with the conditional ? I personally find that two separate files will help in avoid confusion, also because I imagine that the assimp-plain-config.cmake variant will get more logic with time. For example, in a coming PR I want to also switch ZLIB to use the imported targets provided by the official CMake FindZLIB, and I don't think that mixing find_package(ZLIB CONFIG REQUIRED) and find_package(ZLIB MODULE REQUIRED) in the same file would be helpful for readability and maintainability, but this is just my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, only CMake reads these config files. In addition, the @ASSIMP_HUNTER_ENABLED@ will be set to ON or OFF in the generated config file, in case a human wants to read it. I think it is worth consolidating everything and simplifying the config file generation into a single one.

Copy link
Contributor Author

@traversaro traversaro Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, only CMake reads these config files. In addition, the @ASSIMP_HUNTER_ENABLED@ will be set to ON or OFF in the generated config file, in case a human wants to read it. I think it is worth consolidating everything and simplifying the config file generation into a single one.

Sorry, regarding the readability comment I was referring to the .cmake.in file that will be read by any contributor that needs to modify it for the future. I find that having the two separate files is more mantainable, but it is just a personal opinion, anything that is ok for the Assimp mantainers is ok for me.

@traversaro
Copy link
Contributor Author

@traversaro we can alias assimp::assimp targets to Assimp::assimp in the config file, if that allows you to consolidate more. See https://github.com/cpp-pm/zlib/blob/hunter-1.2.11/cmake/Config.cmake.in#L6 for an example.

I don't know, assimp is used in several place as well in the assimp generate files (the config file is name assimp-config.cmake, the target file is assimpTarget.cmake), so I am not sure what is the preferred way to go.

@traversaro
Copy link
Contributor Author

@traversaro we can alias assimp::assimp targets to Assimp::assimp in the config file, if that allows you to consolidate more. See https://github.com/cpp-pm/zlib/blob/hunter-1.2.11/cmake/Config.cmake.in#L6 for an example.

I don't know, assimp is used in several place as well in the assimp generate files (the config file is name assimp-config.cmake, the target file is assimpTarget.cmake), so I am not sure what is the preferred way to go.

However, I think it could make sense to define Assimp::assimp as an alias target of assimp::assimp, but only if CMake >= 3.11 is used (for CMake <=3.10, it is not possible to define an ALIAS of an imported target: https://cmake.org/cmake/help/v3.10/command/add_library.html#alias-libraries )

@traversaro
Copy link
Contributor Author

More in general, it seems that the assimp::assimp variant and related convention (i.e. find_package(assimp) ) seems the one preferred in downstream projects (but I may be biased, as I have used it for some time) and have been added first to the project (#2161) while the Hunter variant of Assimp::assimp seems to have been added later (#2488), so it could make sense to converge eventually to assimp::assimp.

However I don't want to start bikeshadding about the CMake namespace, so any solution that is fine to the mantainer is fine for me.

Use standard CMake function to generate the CMake config files.
@rahulshethsc
Copy link
Contributor

We can keep the assimp::assimp target and export an ALIAS target for Hunter builds only. That solves all the problems, no?

@traversaro
Copy link
Contributor Author

We can keep the assimp::assimp target and export an ALIAS target for Hunter builds only. That solves all the problems, no?

I think that make sense, especially if Hunter is ensured to always be used with CMake >= 3.11 .

@traversaro
Copy link
Contributor Author

However, I think that reducing the amount of code duplication between Hunter and non-Hunter can also done in future PRs, as the PR is already quite complex as it is. Perhaps we can open a dedicated issue for that?

@kimkulling kimkulling merged commit de610b8 into assimp:master Oct 29, 2020
@kimkulling
Copy link
Member

Merged, thanks a lot for your contribution.

@traversaro
Copy link
Contributor Author

Merged, thanks a lot for your contribution.

Thanks a lot @kimkulling !

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.

Please use CMakePackageConfigHelpers make CMake config file relocatable Generated CMake config script contains hard-coded values

4 participants