cmake: building as part of a system and standalone

Normally I have a mixture of libraries and GUI applications making up a larger system.

I tend to use Qt/QML for the GUI components only. For everything else I use standard libraries, boost and what ever is most appropriate for the application/system I am building.

Using Qt for everything precludes me from changing the GUI to something else such as Fox, Gtk or MFC.

This means that I use cmake for building my applications and systems.

So while qtcreator now supports cmake quite well it does not appear to work well with some of the large cmake based builds that I have (30 or more build targets).

There for when I need to work with qtcreator I ensure that my CMakeLists.txt can be part of the main build and also be loaded independently by qtcreator.

I am this using the following pattern:
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
  # Part of main build
else()
  # Building on its own
  cmake_minimum_required(VERSION 3.5)
  project(my_project_name LANGUAGES CXX)
...pull in any cmake files needed...
endif()
...
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
  # Part of main build
  ... setup as though building as part of main build system
else()
  # building on its 
  ... setup as though building stand-alone ... find all packages build and dependencies etc...
endif()

Technically this makes maintenance a lot more difficult but it does appear shorten the development cycle significantly primarily as I don't end up rebuilding all the other 30 targets everytime I touch the local cmake files.



Comments