Allow cmake users to use FetchContent_Declare
Description
It would be nice for cmake users to be able to use something like the following to include Stan math in their projects
include(FetchContent)
FetchContent_Declare(
stanmath
GIT_REPOSITORY https://github.com/stan-dev/math
GIT_TAG v4.7.0
)
FetchContent_MakeAvailable(stanmath)
I have part of this written here where I have stan math compiling with cmake. I'd be happy to expand this into a CMakeLists.txt file in the stan math repo, which would then allow cmake users to do something like the above to include stan math in their projects.
Do any folks have objections to this? I'd say the cmake file I have there is like 60% complete. It does all the correct includes, but does not handle some of the specific flags we use. It also does not support MPI, but that should be easy to setup.
If I set this up we could also setup our test suite to integrate with ctest
Expected Output
Please provide the expected output.
If this is a bug report, show what you expected to happen. Please also show what currently happens.
If this is a feature request, show what you expect to happen if the feature exists.
Current Version:
v4.7.0
No objections!
I have my own version of this (modified from Steve’s) here: https://github.com/WardBrian/math/tree/experiment/cmake
It has a bit more flag configuration and some logic to support a “install” target for Math, which would let other tools use a find_library call
Having a canonical version that's tested would be wonderful.
I'm interested in moving to cmake because there's a new Python build system scikit-build that would allow pystan/httpstan to create a source distribution. It would work even if the user doesn't have cmake installed. It works on many more platforms than we currently support.
I'm afraid I haven't found time to really learn cmake, otherwise I'd be more than happy to help out with this.