Home › Forum › Announcements / Infos › New build system
Tagged: cmake
- This topic has 0 replies, 1 voice, and was last updated 9 years, 6 months ago by Marc.
-
AuthorPosts
-
24 June 2015 at 13:03 #3385MarcBlocked
As you may know, there have been a rewrite of the CMake scripts going on for quite some time; this thread attempts to explain and document the basics of the new build system.
This post will be updated over time. It is kind of a draft, so please do ask any questions you have and point out missing information.
Intro
Goals:
- use a vanilla, modern cmake style, more maintainable than the current system;
- allow installation (“make install”) — and later, packaging;
- make each project independent (you install the sofa libraries, and then build only your own plugins).
This happens on the build-system branch:
git checkout build-system
Building things
Build Sofa:
mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=/path/to/install/directory /path/to/sofa/source/tree make make install
Build a plugin
You can still build the public plugins at the same time as Sofa (via
the cmake options), yet they are independent projects. If you are
a developer of a given plugin, you are better off building it
independently.mkdir build cd build CMAKE_PREFIX_PATH=/path/to/sofa cmake /path/to/the/plugin/source/tree make
Writing a CMakeLists.txt
Minimal example
This build system provides cmake package configuration files, which
simply means you can use the find_package() cmake command to find Sofa
headers and libraries.cmake_minimum_required(VERSION 2.8) project(MyPlugin) find_package(SofaFramework REQUIRED) add_library(${PROJECT_NAME} SHARED \<my source files\>) target_link_libraries(${PROJECT_NAME} SofaCore)
More generally, the content of the repository has been split in the following packages:
- SofaFramework (helper, defaulttype, core)
- SofaSimulation (simulation*)
- SofaBase, SofaCommon, SofaGeneral, SofaAdvanced, SofaMisc (modules)
You can use them in CMake with:
find_package(<sofa-package>)
and them use a library with:
target_link_libraries(<mylib> <sofa-library>)
This will both
- add the include directories of
<sofa-library>
- link
<mylib>
against<sofa-library>
Using a plugin as a library
If a plugin can be used as a library, it provides cmake config files, e.g.
the ‘image’ plugin is used as a library by ‘Flexible’:find_package(image QUIET) if(image_FOUND) list(APPEND HEADER_FILES "quadrature/ImageGaussPointSampler.h") [...] endif() [...] if(image_FOUND) target_link_libraries(${PROJECT_NAME} image) set(FLEXIBLE_COMPILER_FLAGS "${FLEXIBLE_COMPILER_FLAGS} -DSOFA_HAVE_IMAGE") endif()
-
AuthorPosts
- You must be logged in to reply to this topic.