CMake package config?
Would it be possible to add auto-generation of CMake config files (i.e., with configure_package_config_file()/write_basic_package_version_file()/etc.) to avoid the need for CMake's built-in FindJasper.cmake? It would be helpful for Jasper to provide info itself to downstream CMake projects so that exact build options, dependencnesi, etc. can be determined without having to separately use pkgconfig-- I suppose one alternative could be to add pkgconfig invocations to FindJasper.cmake, but using CMake-based configuration is probably lower maintenance long term, and would put control of it directly under jasper.
The motivating issue here is that FindJasper.cmake fails when jasper is built with JAS_ENABLE_LIBJPEG=OFF: https://gitlab.kitware.com/cmake/cmake/-/issues/26915 I'll keep looking into a workaround on the CMake end, but it would be great to avoid the need for FindJasper.cmake altogether. If it would be helpful, I'm happy to point to examples of CMake-generated CMake config files, probably 90%+ of the scripting could be copied and pasted.
(for my own reference, my test setup here is on gaea at ~/stack-stack-jasper-398/)
@AlexanderRichert-NOAA : As of JasPer 4.2.6 (which I have just released), I have added experimental support for generating CMake package configuration files. This support is enabled/disabled by the JAS_ENABLE_CMAKE_PACKAGE_CONFIG CMake option, and is disabled by default. Could you please let me know if this work correctly for you and does what you want. If it works for you and is also what you wanted, I can consider enabling this option by default in a future release.
@AlexanderRichert-NOAA: I just wanted to ping you again to see if the option that I added for CMake (mentioned above) meets your needs. Please advise.
Thanks, I apologize this fell off my radar.
I tested this out with 4.2.6 just now. I would suggest modifying the CMake config to automatically load dependencies with find_dependency(). As it is, if I call target_link_libraries(my_target PRIVATE JasPer::libjasper), it will fail with
30 The link interface of target "JasPer::libjasper" contains:
31
32 JPEG::JPEG
33
34 but the target was not found. Possible reasons include:
because it's correctly adding the JPEG::JPEG target to JasPerTargets.cmake when JAS_ENABLE_LIBJPEG=ON, but the JPEG package itself was never loaded. Having the CMake config automatically load dependencies is especially useful for optional dependencies, so that downstream packages don't have to guess/infer the configuration and decide whether to load, in this case, libjpeg on their own prior to calling find_package(JasPer). Here's an example where we set dependencies for a package dynamically based on its build options: https://github.com/NOAA-EMC/NCEPLIBS-ip/blob/develop/cmake/PackageConfig.cmake.in
For the code I tested with (g2c), after I manually added the find_dependency call for JPEG and included the JasPer::libjasper target with a few other small tweaks, the code compiles and all but one of the unit tests passes (I suspect but haven't confirmed that the failing unit test is something on our end related to Jasper versions). So this is a really great start, thank you, I'd definitely love to see this finalized and included by default in a future release. I'm fairly busy over the next few weeks but I'm happy to try to make some time to test out changes.
@AlexanderRichert-NOAA I am not sure if I fully understand all the nuances of CMake package config file support. In any case, I tried to further improve JasPer's CMake package config file support in the direction that you suggested. I made some further changes to the support by using find_dependency in the package config template. The resulting support seems to work correctly on my system both with and without the JPEG library being installed. So, I think that this should fix the problem that you were describing if I understood it correctly. Can you please let me know if this support now works for you for your use cases? Thanks. (Note: The support is still disabled by default. So, you have to enable it in order to use it, as before.)
Incidentally, I added a new CMake project under test/src for testing the installed package config files.