Perform the following steps to get the [http://www.cmake.org CMake Make System] working for you. The example shows how to set things up such that the binary startCompletionServer is built by a call to "make" and that the distribution autocomplete-0.1.tar.gz is built by a call to "make package_source".
Basic workcycle
Let us assume that all your soruce files (.h and .cpp files) are located in one top level directory. In this directory, create a file called CMakeLists.txt with the following content:
# BUILDING PROJECT(autocompletion) SET(BASEFILES Globals.cpp Globals.h HYBCompleter.cpp HYBCompleter.h IndexBase.cpp IndexBase.h History.cpp History.h codes.cpp codes.h nrutil.c nrutil.h QueryParameters.cpp QueryParameters.h HYBIndex.cpp HYBIndex.h WordsFile.cpp WordsFile.h ConcurrentLog.cpp ConcurrentLog.h DocsDB.cpp DocsDB.h Document.cpp Document.h ExcerptsGenerator.cpp ExcerptsGenerator.h CompletionServer.cpp CompletionServer.h CompleterBase.cpp CompleterBase.h ) ADD_EXECUTABLE(startCompletionServer StartCompletionServer.cpp ${BASEFILES}) # TODO: the following ist not portable! # we could use IF(UNIX) or IF($ENV{OSTYPE} EQUAL linux-gnu) ADD_DEFINITIONS(-fexceptions -static -O6 -Wall -DVERSION=\"'`date +\"Version %d%b%y %H:%M\"`'\" -DNDEBUG -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT ) TARGET_LINK_LIBRARIES(startCompletionServer pthread z)
# INSTALLING INSTALL(TARGETS startCompletionServer RUNTIME DESTINATION bin)
Use the command line definition CMAKE_INSTALL_PREFIX:
$ cmake .. -DCMAKE_INSTALL_PREFIX=.
Testing
ADD_EXECUTABLE(test-adler32 test-adler32.cpp ${BASEFILES}) TARGET_LINK_LIBRARIES(test-adler32 pthread z) ADD_TEST(adler32 test-adler32 4711)
Using subdirectories
# Recurse into subdirs ADD_SUBDIRECTORY( src )
Generating config.h
INCLUDE (CheckIncludeFiles) # usage: CHECK_INCLUDE_FILES (<header> <RESULT_VARIABLE> ) CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H) # If another header is required to use the header you are looking for, # you have to list the header files separated by semicolons CHECK_INCLUDE_FILES ("sys/param.h;sys/mount.h" HAVE_SYS_MOUNT_H) INCLUDE (CheckFunctionExists) CHECK_FUNCTION_EXISTS(memcpy HAVE_MEMCPY) CHECK_FUNCTION_EXISTS(floedeldoe HAVE_FLODELDOE) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
Useful options
CMAKE_MINIMUM_REQUIRED(VERSION 2.4) ENABLE_TESTING() # the following line works in 2.4, but not in 2.0 :-) # CMAKE_MINIMUM_REQUIRED(VERSION 2.4 FATAL_ERROR) # workaround for stopping cmake IF(CMAKE_SYSTEM_VERSION LESS 2.4) MESSAGE(FATAL_ERROR "STOPPED! You need at least CMake version 2.4 for this.") ENDIF(CMAKE_SYSTEM_VERSION LESS 2.4) # option to produce more 'verbose' compiling #SET(CMAKE_VERBOSE_MAKEFILE ON)