Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize CMake #1524

Merged
merged 28 commits into from
Dec 28, 2020
Merged

Modernize CMake #1524

merged 28 commits into from
Dec 28, 2020

Conversation

phcerdan
Copy link
Member

@phcerdan phcerdan commented Oct 15, 2020

  • Avoid global include_directories, link_libraries etc. Use
    instead the target_ commands.
  • Create DGtal library in the top directory, allowing to be targeted in
    the other CMake files.
  • Use lower case for CMake commands, i.e. SET to set etc.
  • Remove naming the condition in else, endif, and endforeach: if(x), else(x), endif(x)
  • Add function DGtal_add_test(test_file) to avoid repetition when
    configuring tests. It accepts a dummy optional parameter, for example
    ONLY_ADD_EXECUTABLE that will create the executable, link to DGtal,
    but avoid the add_test command. Used mainly when benchmarking is ON.

Checklist

  • Unit-test of your feature with Catch.
  • Doxygen documentation of the code completed (classes, methods, types, members...)
  • Documentation module page added or updated.
  • New entry in the ChangeLog.md added.
  • No warning raised in Debug cmake mode (otherwise, Travis C.I. will fail).
  • All continuous integration tests pass (Travis & appveyor)

@phcerdan phcerdan force-pushed the modernize_cmake branch 7 times, most recently from ae581dd to 757a5b9 Compare October 19, 2020 10:32
@dcoeurjo
Copy link
Member

dcoeurjo commented Nov 9, 2020

I am now a great fan of "Fact_content" (or any higher level facade like https://github.com/TheLartians/CPM.cmake).
What do think to have the following deps "fetched" at cmake by default:

  • Eigen
  • GMP/GMPXX
  • CGAL

(with flag to allow to use the installed deps)

@JacquesOlivierLachaud ? @rolanddenis

@rolanddenis
Copy link
Member

Since CGAL is now header only, it is a good idea to simplify DGtal installation! If we replace boost/program_options by CL11 in DGtal, I suppose Boost should also be header only?

@JacquesOlivierLachaud
Copy link
Member

I am not a great expert on configuration tools. Everything that makes the life of future developers/users easier is good for me.
If we have to fetch by default some packages, the three you list is a good option (Eigen very useful but pulls a lot of other packages, gmp/gmpxx is a small dependency, CGAL is sometimes useful and header only).

@dcoeurjo
Copy link
Member

dcoeurjo commented Nov 9, 2020

In DGtal, boost is already header only (only libs have been considered in DGtalTools but not true anymore I guess). It could also be "fetched" at cmake step but my only concern would be the size of the working copy (minor issue, though...).

Maybe the "make install" step is also something that could introduce bugs..

@phcerdan
Copy link
Member Author

phcerdan commented Nov 9, 2020

FetchContent uses add_subdirectory, so you end owning the third-party library in your project, i.e gmp.so would be at the same level than DGtal.so. If the CMake files of the third-party are not pretty modern, you might face global changes on CMAKE_CXX_FLAGS, or if missing alias targets, you might find incompatibilities of library names between find_package and add_subdirectory.

An alternative that from my experience works great is to have a dependencies subproject inside DGtal (but completely independent), that uses FetchContent to feed all the dependencies (with options). It will be built in its own folder, for example build-dgtal-dependencies.

With this approach, DGtal won't be changed, it will still expect Eigen_DIR, CGAL_DIR and use find_package. Then, a wrapper can be created, such as: DEPENDENCIES_DIR=/path/build-dgtal-dependencies to where the dependencies subproject was built, that provide all the dependencies _DIR with just one option.

The dependencies approach is like the super-build approach, but you don't have to config all the dependencies every time.

@phcerdan
Copy link
Member Author

phcerdan commented Nov 9, 2020

Since CGAL is now header only, it is a good idea to simplify DGtal installation! If we replace boost/program_options by CL11 in DGtal, I suppose Boost should also be header only?

I think boost-graph can enjoy being linked (reduces compile time).

@phcerdan
Copy link
Member Author

phcerdan commented Nov 9, 2020

In any case, this modernization is about removing global commands for target specific commands. Remove upper case, and modernize DGtalConfig.cmake file accordingly.

@dcoeurjo
Copy link
Member

Additional things that should be in the Fetch_content stuff:

  • Catch2 (for the tests)
  • CLI11 (maybe DGtalTools only)
  • LibBoard? (though the main project seems to be dead)

@dcoeurjo
Copy link
Member

dcoeurjo commented Dec 1, 2020

I've just tried a first Fetch_content with Catch2...

phcerdan and others added 13 commits December 8, 2020 11:59
- Avoid global `include_directories`, `link_libraries` etc. Use
instead the `target_` commands.
- Create DGtal library in the top directory, allowing to be targeted in
the other CMake files.
- Use lower case for CMake commands, i.e. `SET` to `set` etc.
- Remove naming the condition in `else`, `endif`, and `endforeach`: `if(x), else(x), endif(x)`
- Add function `DGtal_add_test(test_file)` to avoid repetition when
configuring tests. It accepts a dummy optional parameter, for example
`ONLY_ADD_EXECUTABLE` that will create the executable, link to DGtal,
but avoid the `add_test` command. Used mainly when benchmarking is ON.
No need to prepend CMAKE_INSTALL_PREFIX
Instead of `INSTALL_X_DIR`.  Where X is one of LIB, BIN, INCLUDE, DATA.
`INSTALL_X_DIR` will be set based on the RELATIVE ones.

This allow to have access to the relative paths to make DGtal re-allocatable.

Also allow to change the docs with INSTALL_DOC_DIR_RELATIVE
This also solves the existing problem where the docs installation folder
does not change when changing `CMAKE_INSTALL_PREFIX` after the first
configuration (because it was a CACHE variable)
Use find_dependency (find_package) for all enabled dependencies.
This forces consumers of DGtal to provide `FOO_DIR` where FOO is a DGtal
dependency.
To ease this transition the option HINTS is provided with the current
value of `FOO_DIR` computed when building DGtal. This will ease the
transition in development environments, for example along DGtalTools.

If DGtal is deployed, i.e. re-allocated, the HINTS are meaningless, but
hopefully harmless, they just won't help in this case.
Use target_compile_definitions instead.
Provide HINTS to DGtalConfig.cmake. This allow
third-parties (i.e DGtalTools) to not having to provide
FOO_DIR, where FOO is a DGtal dependency, to their project, but to reuse
the FOO_DIR provided in DGtal.
This option should be disabled for deployment or any other re-allocation
situation.
…s.cmake

To avoid using add_definitions, we need DGtal target to exists.
So these options are moved to a CMake file included after DGtal target
is created.
Also fix OPENMP to OpenMP
In the build tree into: `PROJECT_BINARY_DIR/Modules`
In install tree into `DGTAL_CMAKE_DIR_INSTALL/Modules`

Also change find_dependency to find_package for the FindFoo.cmake packages.
It seems that find_dependency prioritizes Config files and ignore
Find modules.
@phcerdan
Copy link
Member Author

phcerdan commented Dec 8, 2020

@dcoeurjo I will rebase on top of master instead of: Merge branch master into this branch.

git checkout master; git pull;
git checkout modernize_cmake;
git rebase master

Are you working on something on this branch? The head of this branch will be invalidated

@dcoeurjo
Copy link
Member

dcoeurjo commented Dec 8, 2020

please go ahead, I'll resest my working copy if I need.

No need to have two `add_library` commands based on `BUILD_SHARED_LIBS`.
`SHARED` will be added automatically if `BUILD_SHARED_LIBS` is `ON`
and `STATIC` if `OFF`.
@dcoeurjo
Copy link
Member

Can this branch be merged ? @phcerdan anything that is still WIP here?
We may consider other FecthContent in the future but maybe in a separate PR..

@phcerdan
Copy link
Member Author

Can this branch be merged ?

I think yes.

We may consider other FecthContent in the future but maybe in a separate PR..

Sounds good!

@phcerdan phcerdan mentioned this pull request Dec 27, 2020
27 tasks
Copy link
Member

@dcoeurjo dcoeurjo left a comment

Choose a reason for hiding this comment

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

Excellent, I just have a minor question.

cmake/DGtalConfigGenerator.cmake Show resolved Hide resolved
cmake/FindCOIN3D.cmake Show resolved Hide resolved
@dcoeurjo
Copy link
Member

Ok SoQT and COin3D can be removed.. I'll do it

Copy link
Member

@dcoeurjo dcoeurjo left a comment

Choose a reason for hiding this comment

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

  • Changelog entry?

Copy link
Member

@dcoeurjo dcoeurjo left a comment

Choose a reason for hiding this comment

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

All good... thx

@dcoeurjo dcoeurjo merged commit f36dbce into DGtal-team:master Dec 28, 2020
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.

None yet

4 participants