Caret7:Development/CMake

From Van Essen Lab

Jump to: navigation, search

Contents

Using CMake

Project Directories

|--<some-directory-that-you-create>
       |--caret7_source
       |-- src
       |      |-- CMakeLists.txt
       |      |-- common/
       |              |-- *.h
       |              |-- *.cxx
       |              |-- CMakeLists.txt
       |      |-- xml/
       |              |-- *.h
       |              |-- *.cxx
       |              |-- CMakeLists.txt
       |      |-- <other-source-directories...>
|- <build-directory-that-you-create>

The contents under the src directory will only contain the header (.h), implementation (.cxx), and CMakeLists.txt files. NEVER add anything else.

CMakeLists.txt

  • This file read by the cmake executable and produces a build file (Makefile, XCode Project, etc.) for building the source code.
  • All headers (.h) and implementation files (.cxx) must be listed in the CMakeLists.txt file. While CMake does not require listing header files in CMakeLists.txt, they will not show up in XCode unless they are listed in the CMakeLists.txt.
  • Those headers that subclass a QT class and contain the "Q_OBJECT" macro must be in a special section of the CMakeLists.txt file so the the "moc*.cxx" files are generated.

Configuring with CMake

Always build the software outside of the caret7_source directory.

  • Create a "build" directory that is in the same directory as caret7_source. There is no required name for the build directory and there may be multiple build directories (release, debugging, etc.).
  • cd <build-directory-that-you-create>

CMakeCache contains the build settings used to generate the project. CMake will create CMakeCache.txt the first time it is run. To adjust the CMakeCache.txt parameters, one can edit CMakeCache.txt in a text editor, use the CMake GUI (cmake -gui), or run CMake interactively (cmake -i). One can also specify parameters to cmake (cmake ../caret7_source/src -DCMAKE_CXX_COMPILER=llvm-g++).

If one tries to reconfigure a project using a different build type, it may be necessary to delete the CMakeCache.txt file.

Creating and Building a Makefile Project

To get the proper version of QT software, qmake must be in the PATH environment variable. The QT library used is the QT library from which qmake is found.

Depending upon the platform, cmake may generate Makefiles by default and the '-G "Unix Makefiles"' parameter may be unnecessary.

  • cmake ../caret7_source/src -G "Unix Makefiles"
  • make

Create and Building XCode Project Files on Mac OSX

  • cmake ../caret7_source/src -G Xcode
  • cmakexbuild

Editing CMakeCache.txt

Build Type

  • CMAKE_BUILD_TYPE:STRING
    • Debug
    • Release
    • RelWithDebInfo

C++ Compilers

  • CMAKE_CXX_COMPILER
    • g++
    • llvm-g++
  • CMAKE_CXX_FLAGS
  • CMAKE_CXX_FLAGS_DEBUG
    • -g
  • CMAKE_CXX_FLAGS_RELEASE
    • -O3 -DNDEBUG
  • CMAKE_CXX_FLAGS_RELWITHDEBINFO
    • -O2 -g

C Compilers

  • CMAKE_C_COMPILER
    • gcc
    • llvm-gcc
  • CMAKE_C_FLAGS
  • CMAKE_C_FLAGS_DEBUG
    • -g
  • CMAKE_C_FLAGS_RELEASE
    • -O3 -DNDEBUG
  • CMAKE_C_FLAGS_RELWITHDEBINFO
    • -O2 -g

Linking

  • CMAKE_EXE_LINKER_FLAGS
  • CMAKE_EXE_LINKER_FLAGS_DEBUG
  • CMAKE_EXE_LINKER_FLAGS_RELEASE
  • CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
  • CMAKE_LINKER
    • ld

Mac OSX

  • CMAKE_OSX_ARCHITECTURES:STRING=
  • CMAKE_OSX_DEPLOYMENT_TARGET:STRING=
  • CMAKE_OSX_SYSROOT:PATH=/Developer/SDKs/MacOSX10.6.sdk

Show More Info

  • CMAKE_VERBOSE_MAKEFILE
    • TRUE
    • FALSE

Setting Variables When Running CMake

  • cmake -D=<value>

CMake Modules

To get a list of modules run:

  • cmake --help-module-list

To get help for a particular module:

  • cmake --help-module <module-name>
  • cmake --help-module FindZLIB

To include the module in CMakeLists.txt

FIND_PACKAGE(ZLIB)     # Leave the "Find" part off
IF (ZLIB_FOUND) 
ENDIF()

CTest

In CMakeLists.txt

  • add_test(testName exeName arg[s])
  • exeName should return zero on success


References

Personal tools
Sums Database