Skip to content

Improve CMake Support

Jeff requested to merge flying-tiger/cppduals:master into master

Hello! Really nice library. I needed to verify some analytic Jacobians, and this library was perfect. My only complaint was getting it integrated into my CMake setup. While the ExternalProject approach worked, I've been using FetchContent/add_subdirectory for my dependencies, and cppduals did not support that out-of-the-box. Most notably, there was no exported target for the library and the docs build was using CMAKE_*_DIR variables instead of PROJECT_*_DIR variables, which breaks when cppduals is included as a sub-project.

This pull request does a modest overhaul to the top level CMakeLists.txt based on recommended practice from Professional CMake. We now export a cppduals::duals target for users to link against, generate a cppduals-config.cmake file for find_package, and use PROJECT_*_DIR variables as appropriate to allow inclusion via add_subdirectory. Install location is controlled by CMAKE_INSTALL_PREFIX and docs are installed along side the headers if built.

There are still a few other things that could be improved (notably: prefixing cppduals_ to the other targets to avoid name collisions when using add_subdirectory), but I suspect that would have disrupted your current workflows, so I wanted to get this in first and gauge your interest in further updates. Please review and let me know your thoughts.

Cheers!

Merge request reports