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

[All] Improve extlibs integration #1137

Merged
merged 99 commits into from
Sep 26, 2019

Conversation

guparan
Copy link
Contributor

@guparan guparan commented Sep 5, 2019

This is a (big) attempt to clean the dependencies management in SOFA.

Better understand SOFA dependencies

Here is a summary: https://docs.google.com/spreadsheets/d/1dxP7Rsyl1oCr0lfTwQESeeZQTt315CIFih5QpJp5OZY/edit?usp=sharing

Clean dependency management in CMakeLists

  • SofaFramework
    • Moved to SofaHelper: Boost, OpenGL, GLEW, GTest, Eigen, JSON, FFMPEG_exec
    • Removed (not needed by any SofaFramework module): TinyXML, ZLIB
  • SofaMisc
    • Added to SofaMiscTopology: ZLIB
    • Added to SofaMiscFem: Newmat
  • SofaGeneral
    • Added to SofaDenseSolver: Newmat
    • Added to SofaGeneralLoader: ZLIB
  • SofaGui
    • Moved to SofaGuiQt: Qt + lots of options about QtViewer, QGLViewer, VSync, ...
  • Modularized modules (oh yeah)
    • SofaPreconditioner: removed Newmat, added SofaSparseSolver
    • SofaExporter: added ZLIB
  • Plugins
    • SofaMiscCollision: added SofaDistanceGrid
    • SofaImplicitField: added SofaPython
    • Registration: removed SofaOpenglVisual
    • image: added ZLIB
    • Flexible: added SofaPython

Rework all YYY_HAVE_XXX variables to reduce their scope

This is important for future global modularization of SOFA.

  • Variables are now named upon their module.

  • Whenever you need to use the YYY_HAVE_XXX of another module, you surely should declare your own MYMODULE_HAVE_XXX instead.

  • All those new YYY_HAVE_XXX variables are booleans, so they can be used in CMake with if(YYY_HAVE_XXX) and in C++ (if correcly propagated via a config.h.in file) with #if YYY_HAVE_XX or if(YYY_HAVE_XXX).

  • Add sofa_find_package and sofa_set_bool macros to auto create YYY_HAVE_XXX variables.

  • Edit sofa_install_targets to call configure_file() on any *.h.in found in target sources (the sources that are given to add_library()).

⚠️ Here is a quick tuto about how to correctly add and propagate a dependency.

Rework #1121 to avoid nested projects

  • Use SOFA_NO_OPENGL to build an OpenGL-free version of SofaGuiQt

This PR:

  • builds with SUCCESS for all platforms on the CI.
  • does not generate new warnings.
  • does not generate new unit test failures.
  • does not generate new scene test failures.
  • does not break API compatibility.
  • is more than 1 week old (or has fast-merge label).

Reviewers will merge only if all these checks are true.

namespace alias "po" makes difficult to find where program_options is used
SofaTest_test contains only:
- scenes/damping.py
- python_tests/python_test_test.py

If this scripts are needed, they should be in SofaPython_test.
sofa_set_int: define a variable to 0 or 1 to be usable by both config.h.and or XXXConfig.cmake.in

sofa_extlib_find_package: call find_package + call sofa_set_int to create a XXX_HAVE_YYY variable
"name" has nothing to do as add_subdirectory 2nd argument
Useful to debug.
Prints all properties of a target.
SofaHighOrderTopology is needed by Flexible
Because some variables defined above may be needed in the configured files
- Add forward declaration to TinyXML classes
- Add find_package
- Link TinyXML privately
Setting variables as boolean permits to use them with #if or directly with if() without implicit conversion warning.
Always using the same name from CMake option definition to C++ #ifdef blocks
The addition of TimeoutWatchdog is already controlled by Boost_THREAD_FOUND in CMakeLists.txt
find_package(QGLViewer QUIET REQUIRED)
endif()
if(SOFAGUIQT_HAVE_QWT)
find_package(QGLViewer QUIET REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo ? find_package(qwt QUIET REQUIRED) instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! 👍

@guparan
Copy link
Contributor Author

guparan commented Sep 9, 2019

[ci-build][with-all-tests]

…libs_integration

# Conflicts:
#	applications/sofa/gui/qt/CMakeLists.txt
#	applications/sofa/gui/qt/gl/CMakeLists.txt
#	applications/sofa/gui/qt/viewer/GLBackend.cpp
#	extlibs/CMakeLists.txt
@guparan guparan added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Sep 17, 2019
even if variable goes from TRUE to UNDEFINED (old way let the #define with no value, leading to errors)
Better consistency with #cmakedefine01
@guparan guparan added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Sep 17, 2019
@@ -60,11 +60,12 @@ void initExternalModule()
if (first)
{
first = false;
if(SOFAEXPORTER_HAVE_SOFAPYTHON)
#if SOFAEXPORTER_HAVE_SOFAPYTHON
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this was indeed broken.

option(SOFAEXPORTER_BUILD_TESTS "Compile the automatic tests" ON)
else()
set(SOFAEXPORTER_BUILD_TESTS FALSE)
endif()
Copy link
Contributor Author

@guparan guparan Sep 24, 2019

Choose a reason for hiding this comment

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

I don't agree with this approach.
SOFA_BUILD_TEST is for SOFA tests. SofaExporter is now modularized so it should be considered as out-of-SOFA.

My view is:

  • SOFA old modules (that are not real modules) do not integrate their tests themselves because of SofaTest dependencies (see the order of add_subdirectory calls in main CMakeLists)
  • new modules ("modularized") and plugins and projects must be buildable out of SOFA so they integrate their tests themselves and do not depend on a SOFA internal variable. Those tests, though, can have a SofaTest dependency (SofaExporter_test does) and thus may fail to generate if SofaTest is not found.

In this case for example, I prefer an explicit SOFAEXPORTER_BUILD_TESTS that may lead to a failure because SofaExporter_test couldn't find SofaTest than a magic check above SofaExporter_test setting the variable OFF beforehand.

What could be changed though is the way SofaExporter_test finds SofaTest

find_package(SofaTest QUIET)
if(NOT SofaTest_FOUND)
    message(SEND_ERROR "Couldn't find SofaTest. If building SOFA, you need to activate SOFA_BUILD_TESTS")
endif()

Copy link
Contributor

@epernod epernod Sep 24, 2019

Choose a reason for hiding this comment

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

ok I understand that tests from module should be independant but they need SofaTest lib.
In my case I don't compile SofaTest (bad I know). But unchecking SofaTest failed at cmake configuration because SOFAEXPORTER_BUILD_TESTS need SofaTest. So it means I would need to uncheck each TEST in the cmake configuration...

Maybe the good approach is (not sure it works):

if (SOFA_BUILD_TESTS)
    option(SOFAEXPORTER_BUILD_TESTS "Compile the automatic tests" ON)
else()
    option(SOFAEXPORTER_BUILD_TESTS "Compile the automatic tests" OFF)
endif()

and in the SOFAExporter_test cmake:

find_package(SofaTest REQUIRED)
if(NOT SofaTest_FOUND)
    message(SEND_ERROR "Couldn't find SofaTest. If building SOFA, you need to activate SOFA_BUILD_TESTS")
endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the problem behind is that SOFA_BUILD_TESTS should not be used to check SofaTest_FOUND.
SOFA_BUILD_TESTS should be only used to ON/OFF the old module tests (all at once).

Being able to ON/OFF specific tests is a good thing in my opinion.
Here is a compromise, in SofaExporter_test CMakeLists:

find_package(SofaTest QUIET)
if(NOT SofaTest_FOUND)
    message(STATUS "Couldn't find SofaTest. ${PROJECT_NAME} will not be built.")
    return()
endif()

This is more or less the same idea but keeping the check inside of SofaExporter_test.

Copy link
Contributor

@epernod epernod left a comment

Choose a reason for hiding this comment

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

Not sure it works fully as expected but for me cmake generation works as well as compilation and make install.
I was also able to create a project using SOFA as lib. It is not totally easy going but it works.

@guparan guparan added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Sep 25, 2019
@guparan guparan merged commit 5654a0e into sofa-framework:master Sep 26, 2019
@guparan guparan added this to the v19.12 milestone Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement About a possible enhancement pr: breaking Change possibly inducing a compilation error pr: clean Cleaning the code pr: status ready Approved a pull-request, ready to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants