devernay / cminpack

A C/C++ rewrite of the MINPACK software (originally in FORTRAN) for solving nonlinear equations and nonlinear least squares problems
http://devernay.free.fr/hacks/cminpack/
145 stars 63 forks source link

Make CMinpack more conform with modern cmake #38

Closed CaeruleusAqua closed 4 years ago

CaeruleusAqua commented 4 years ago

The test run failed on my system (Win10 VS2019) because the test executable was not found, the macro now uses a generator expression to get the test executable (should work on all systems).

Since cmake provides an automated way to generate a CMinpackConfig.cmake that should work across platforms, I included this. Mainly to integrate CMinpack into vcpkg.

The main advantage of this is that you can import targets instead of variables. In addition this should be much more portable.

With the new CMinpackConfig.cmake, you must use it as follows:

find_package(CMinpack 1.3.6) 
# You may want to use REQUIRED here!
# When the [version] argument is given Config mode will only find a version of the package that claims compatibility with the requested version (format is major[.minor[.patch[.tweak]]]).
# If the EXACT option is given only a version of the package claiming an #exact match of the requested version may be found. 

target_link_libraries(yourTargetName PRIVATE
    cminpack::cminpack)

Done! The include directory is imported automatically, also debug, release builds are processed automatically! The inlcude headers are prepended in cminpack-1/ because I don't like to pollute the global header namespace. You can change this behavior by changing the following lines:

target_include_directories(cminpack INTERFACE
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
        $<INSTALL_INTERFACE:include>
       )

to:

target_include_directories(cminpack INTERFACE
        $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
        $<INSTALL_INTERFACE:${CMINPACK_INCLUDE_INSTALL_DIR}/>
       )
coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 94.105% when pulling 2c664bcc2812730ff8844a31349e08d9331b3ef2 on CaeruleusAqua:master into fd2eafc929b3abc85ef262c94f00769b91ae64c2 on devernay:master.

devernay commented 4 years ago

Nice! Thank you very much!

However, I don't think that installing two headers which have the same name as the package is pollution. And this may break many packages that depend on cminpack. Can you please remove installation of includes in a subdir, or do you expect me to do it (in which case it will take time).

CaeruleusAqua commented 4 years ago

Done!

I also switched off the caching of the version string. Because if it is on, the version will not be reset on multiple cmake runs, causing the version Regex to run multiple times and fail.

StefanBruens commented 1 year ago

Done!

I also switched off the caching of the version string. Because if it is on, the version will not be reset on multiple cmake runs, causing the version Regex to run multiple times and fail.

As the syntax for CACHED and non-CACHED variables is different, the set command now fills the CMINPACK_VERSION variable with a string list.

This breaks pkgconfig file generation, see #55