Open Graph Drawing Framework
current version:
v.2015.05 (Baobab)
     

Discussion: Configuring OGDF using CMake

Preamble

Currently, OGDF uses its own Python scripts for creating Makefiles (on Linux/MacOS) or project files (on Windows). Many people have asked to provide configuration using CMake and preliminary support for Cmake has been added to the current developer version. Here, we want to describe the current status and discuss problems and possible solutions.

Why CMake?

The current make*.py meta build system is cumbersome to modify (duplicated work), imperative Python code has to be edited (verbose syntax) and you need to have an understanding of the target build systems (Visual Studio and Makefiles). With every new version of Visual Studio files have to be adapted (duplicated work). To add even more to the list of IDEs is rather limited and packaging isn't supported. Thats not the way things should be. You want to start working on your problem and hit a build button, instead of fiddling with the build system(s).

There were a couple of options to replace the current system:

  • SCons and WAF
    • it mixes declarative and imperative syntax
    • Pro: its written in Python
    • Pro: packaging support
    • Cons: Visual Studio integration is meh (not a meta build system)
    • Cons: its slow (!)
  • GYP
    • it has declarative syntax
    • Pro: its written in Python
    • Pro: its a meta build system
    • Cons: its very much tailored to the Chrome project
    • Cons: Docs
    • Cons: GYPisms (!)
    • Cons: no packaging support
    • it mixes declarative and imperative syntax
    • Pro: its a meta build system
    • Pro: huge community (LLVM, KDE, OGRE and many others use it)
    • Pro: integration with Visual Studio and XCode is “okay”
    • Pro: packaging support
    • Cons: has tricky concepts (e.g. lists ↔ string duality)
    • Cons: error reporting quality varies

I've used all of these tools for at least one project in the past 10 years and all have their pros and cons. Judging from that I think CMake is best, at least most of the time.

Current Status of Configuration with CMake

How it is Implemented

As OGDF's directory is a bit special we're not using sub-projects for targets. The root file CMakeLists.txt is used to set a couple of settings along with macros and target includes. The macro and target files config/*.cmake set up things the usual CMake-way.

Options are put into the corresponding target's file. Configuration headers are put into config/*stuff/*.h. Currently there is one custom macro called source_dirs that should be used for collecting sources. It puts sources into source-groups for Visual Studio, XCode using the directory structure; use it as follows:

source_dirs(SOURCES
    "dir1"
    "dir2")

How to Use It

You need to have a C++ compiler and CMake 2.8.9+ (Documentation) installed. CMake is a meta-build system, e.g. it creates Makefiles or Visual Studio files using Generators. There are many ways to use CMake; those are mainly cmake-gui (Qt User Interface), ccmake (Curses Interface) and cmake (Commandline Interface). Some cheat sheets for the most common use cases, to spare you from reading the documentation:

Qt Creator: open CMakeLists.txt as new project, follow the instructions, hit build and you're done.

Visual Studio Express (free): open cmake-gui, choose OGDF as source path, OGDF\build as build path, press generate, open OGDF\build\OGDF.sln and hit build OR use cmake -G "Visual Studio 11 Win64" .. from the command line after loading Visual C++ environment variables using "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86_amd64.

Makefiles: open up a terminal and navigate to OGDF, run mkdir build-make && cd build-make && cmake -G "Unix Makefiles" .. and start building using JOBS=MAX make.

Ninja: mkdir build && cd build && cmake -G "Ninja" .. && ninja.

CMake supports a bunch of other Generators such as XCode and Eclipse (see cmake --help). Setting options from the command line is done using -D <Variable>=<Value>. A list of options can be fetched from the interfaces or CMakeCache.txt. Setting the build mode for generators that can not handle more than one is done using CMAKE_BUILD_TYPE (defaults to Release).

Note that Clang currently doesn't support OpenMP. When building with Clang one should disable OpenMP support.

Current Problems

  • config_autogen.h not created automatically but required for compiling OGDF [CG] Fixed. [CS]
  • Is the /MP flag set automatically for Visual Studio projects? [CG] Yes. [CS]
    • Should be possible with: set (CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} /MP”)
  • Usage not documented in README.txt [SB]
    • How can we specify the platform toolset for Visual Studio 2012? [CG] CMAKE_VS_PLATFORM_TOOLSET (CMake.config) [CS]
    • How can we specify the minimum required Windows version? [CG] * Whats the reason for this? [CS] It specifies which Windows APIfunctions are available. E.g., Win 7 has a much richer API than Win XP. OGDF makes use of these functions (if available) depending on the value of the _WIN32_WINNT define. [CG] Done. [CS]
    • How can we specify an alternative LP solver (e.g., CPLEX) and make sure that user code automatically gets the correct defines? [CG] * This seems to be the most complicated part of the configuration. Either use defines from CMake or ship a generated header file configuration_file() [CS] Done. [CS]
  • Enumeration of Options [CS]
    • grep option config/*.cmake (CLI) not very convenient GUI needs screenshots? [CS] Use ccmake or cmake-gui. [CS]
    • Config file missing (combination of include() and set() could be used) [CS] Done. [CS]
  • Packaging [CS]
    • What packages are desired (Debian, Installer, …?) [CS]

After testing on June 17 [CG]

The following problems refer to the latest incarnation of Cmake support (June 17):

  • After configuring for VS 11 on Win8 64, there is no x64 platform (just a Win32), but additional cryptic targets (MinsizeRel, RelWithDebInfo). I would expect Debug/Release targets and Win32/x64 platforms.
    • As far as i know I have to decide for which platform I want to make project files (and two in a project are not supported);
      the magic line is cmake -G “Visual Studio 11 Win64” .. (I could live with this, CG).
      No magic when using cmake-gui :) [CS]
  • OGDF_DEBUG not defined for Debug build
  • There are lots of defines or the ogdf project that may not be there:
    • many COIN build defines [CG] Yes, they're defined make*.py, too. Plus they differ between VC(X) and Makefiles. See below [CS]
    • _CRT_SECURE_NO_WARNINGS, _SCL_SECURE_NO_WARNINGS [CG]. Those do no harm. [CS]
    • configuration options that must be put in config_autogen.h (see below) Done for OGDF [CS].
  • Though config_autogen.h is created, it seems it just copies a prepared standard file. See config_autogen.h.in [CS]
    • Important: Defines from configuration options must go there, otherwise user code will not set the corresponding flags, which will result in crashes.
    • The purpose of the config_autogen.h file is to release a user from the burden to add all the correct compiler defines (we had such a mechanism before, and it was cumbersome and error-prone).
    • So the config_autogen.h should be created according to the given options in .config, I don't know if this is possible with Cmake (needs to access somehow the configuration settings and write to a new file)… [CG]. Possible/done [CS].

After changes on June 28

  • Use CMakeCache.txt instead of CMake.config (removed)
  • Using enums for some options/properties now (see screenshot below) [CS]
  • Configuration of COIN is rather confusing and inconsistent between VC(X) and Makefiles. HAVE_CONFIG_H doesn't compile with WIN32. How to deal with this? [CS]
  • Support for external solvers is missing, as I can't test this. Any volunteers? [CS]

 
discuss/cmake-config.txt · Last modified: 2016/01/23 12:16 by karsten
This page is driven by DokuWiki