Add CMake build files

#13 Declined
Repository
roboticslibrary
Branch
patch-cmake
Repository
odedevs
Branch
default
Author
  1. Markus Rickert
Reviewers
Description

This patch adds CMake as a build system option, tested with Visual Studio, Ubuntu, Fedora, and Mac OS.

It features the same options as the configure/premake scripts, e.g., BUILD_SHARED_LIBS=ON/OFF for shared/static libraries, ODE_WITH_OPCODE/ODE_WITH_GIMPACT for switching between the trimesh options, ODE_WITH_LIBCCD together with ODE_WITH_LIBCCD_BOX_CYL etc. for selecting libccd. ODE_DOUBLE_PRECISION=ON/OFF can be used to select between double and single precision. ODE_WITH_DEMOS and ODE_WITH_TESTS can be used for enabling demos and tests. The latter are also connected to CTest.

It generates an ode-config.cmake file with an ODE::ODE target for inclusion in other CMake projects.

CPack can be used to generate DEB and RPM packages with separate files for runtime and development as well as an NSIS installer for Windows.

Comments (6)

  1. Oleh Derevenko

    Markus, would you please change the makefiles to create all the project files and all the build directories in a subfolder, like the premake does?
    You can create a new folder named "build-cmake" (or you may add to the existing "build" folder) and generate files there (or in its subfolders). You may keep the three added files in the root.

  2. Markus Rickert author

    CMake supports and encourages out-of-source builds, i.e., you call cmake <path-to-source> from the directory where you would like to generate the build files (e.g., cmake ../ode-src). For instance, QtCreator uses ../build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name} for this by default and Visual Studio 2017 uses %HOMEDRIVE%%HOMEPATH%\CMakeBuilds\<id>.

    You can also create build files within the source directory, e.g. by changing to the folder build or build-cmake and executing cmake ... The build folder is up to the user and even the root directory of the source can be used as you have probably noticed via cmake ..

    In order to prevent the latter, the two undocumented options CMAKE_DISABLE_SOURCE_CHANGES and CMAKE_DISABLE_IN_SOURCE_BUILD can be enabled, but these could be removed in future versions and are not recommended. Another option is to calculate the real path to CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR, compare them, and output an error message. In both of these cases, the generation of the file CMakeCache.txt and the directory CMakeFiles cannot be prevented.

    I would suggest to add files generated by CMake in the source directory to the file .hgignore and add documentation to INSTALL.txt on how to create a build directory outside of the source directory or how to generate these files inside the existing build folder with cd build ; cmake ... Please let me know what you prefer.

  3. Oleh Derevenko

    Thank you for the explanation.
    There are too many files generated by CMake — it is not reasonable to add them all to .hgignore. Just add a section to INSTALL.txt with instructions on suggested method of building with CMake.

  4. Markus Rickert author

    I've added an additional section to INSTALL.txt explaining how to use CMake for generating project files. I've also referred to it in the other sections.