CMake

From Wikipedia, the free encyclopedia
  (Redirected from Cmake)
Jump to: navigation, search
CMake
Cmake.svg
Developer(s) Andy Cedilnik, Bill Hoffman, Brad King, Ken Martin, Alexander Neundorf
Stable release 3.0 / June 11, 2014 (2014-06-11)
Written in C++[1]
Operating system Cross-platform
Type Software development tools
License New BSD License
Website www.cmake.org

CMake is cross-platform free and open-source software for managing the build process of software using a compiler-independent method. It is designed to support directory hierarchies and applications that depend on multiple libraries. It is used in conjunction with native build environments such as make, Apple's Xcode, and Microsoft Visual Studio. It has minimal dependencies, requiring only a C++ compiler on its own build system.

History[edit]

CMake development began in the year 1999 in response to the need for a cross-platform build environment for the Insight Segmentation and Registration Toolkit (ITK).[2] The project is funded by the United States National Library of Medicine as part of the Visible Human Project. It was partially inspired by pcmaker, which was made by Ken Martin and other developers to support the Visualization Toolkit (VTK). At Kitware, Bill Hoffman blended components of pcmaker with his own ideas, striving to mimic the functionality of Unix configure scripts. CMake was first implemented in 2000 and further developed in 2001. Continued development and improvements were fueled by the incorporation of CMake into developers’ own systems, including:

  • The VXL Project
  • The CABLE; features added by Brad King
  • GE Corporate R&D for support of DART

Additional features were created when VTK transitioned to CMake for its build environment and for supporting ParaView.

Features[edit]

CMake can handle in-place and out-of-place builds, enabling several builds from the same source tree, and cross-compilation. The ability to build a directory tree outside the source tree is a key feature, ensuring that if a build directory is removed, the source file remains unaffected.

Another feature of CMake is the ability to generate a cache to be used with a graphical editor, which, when CMake is run, can locate executables, files and libraries. This information goes into the cache, which can then be tailored before generating the native build files.

Complicated directory hierarchies and applications that rely on several libraries are well supported by CMake. For instance, CMake is able to accommodate a project that has multiple toolkits, or libraries that each have multiple directories. In addition, CMake can work with projects that require executables to be created before generating code to be compiled for the final application. Its open-source, extensible design allows CMake to be adapted as necessary for specific projects.[3]

CMake can generate makefiles for many platforms and IDEs including Unix, Windows, Mac OS X, OS/2, MSVC, Cygwin, MinGW and Xcode.

Microsoft Visual Studio[edit]

CMake scripts can produce Microsoft Visual Studio project and solution files. However, CMake syntax is more oriented towards Unix/Linux makefiles which is rather unfriendly for Visual Studio development which relies primarily on project->properties GUI.[4]

Build process[edit]

The build process with CMake takes place in two stages. First, standard build files are created from configuration files. Then the platform's native build tools are used for the actual building.[3]

Each build project contains a CMakeLists.txt file in every directory that controls the build process. The CMakeLists.txt file has one or more commands in the form COMMAND (args...), with COMMAND representing the name of each command and args the list of arguments, each separated by white space. While there are many built-in rules for compiling the software libraries (static and dynamic) and executables, there are also provisions for custom build rules. Some build dependencies can be determined automatically. Advanced users can also create and incorporate additional makefile generators to support their specific compiler and OS needs.

Example CMake file[edit]

if (${UNIX})
  set (DESKTOP $ENV{HOME})
else()
  set (DESKTOP $ENV{USERPROFILE}/Desktop)
endif()
 
set  (PRJ      ${DESKTOP}/common/svn )
set  (FILELIST ${PRJ}/src/source.txt )
 
message(STATUS "CMAKE_GENERATOR : ${CMAKE_GENERATOR}")
message(STATUS "DESKTOP         : ${DESKTOP}")
message(STATUS "PRJ             : ${PRJ}")
message(STATUS "FILELIST        : ${FILELIST}")
message(STATUS "SYSTEM_NAME     : ${CMAKE_SYSTEM_NAME}")
 
project(project_name)
 
include_directories(
  ${PRJ}/src
  ${PRJ}/includes
)
 
# Load SRC Variable from file
file(READ ${FILELIST} SRC)
string(REGEX REPLACE  "#.*$"  ""  SRC  ${SRC})
string(REPLACE        "\n"    ";" SRC  ${SRC})
 
add_executable(${PROJECT_NAME} ${SRC} )
 
foreach (f ${SRC})
  set_source_files_properties(${f} PROPERTIES LANGUAGE       CXX)
endforeach(f)
 
if (${WIN32})
  link_directories(
  )
 
  add_definitions(
    -DDEFINE1
  )
 
  target_link_libraries(
    ${PROJECT_NAME} 
    wsock32.lib 
  )
endif()

Notable applications that use CMake[edit]

See also[edit]

References[edit]

  1. ^ "Ohloh Analysis Summary - CMake". Ohloh. Retrieved 2009-12-25. 
  2. ^ "FLOSS Weekly 111: CMake". podcast. TWiT Network. Retrieved 27 February 2011. 
  3. ^ a b c d Neundorf, Alexander (2006-06-21). "Why the KDE project switched to CMake—and how". LWN.net. 
  4. ^ "CMake and Visual Studio". 
  5. ^ Conky README.cmake file
  6. ^ "Compiling YARP and iCub". iCub user manual. 
  7. ^ a b c d Hoffman, Bill. "CMake / CTest / CPack: Open source tools to build, test, and install software" (PDF). BoostCon 2009. 
  8. ^ "Qt Doc / CMake Manual". Digia. 

External links[edit]