|
| 1 | +# CMakeLists.txt has to be located in the project folder and cmake has to be |
| 2 | +# executed from 'project/build' with 'cmake ../'. |
| 3 | + |
| 4 | +# ${PROJECT_SOURCE_DIR} refers to the folder of the CMakeLists.txt (project) |
| 5 | +# ${PROJECT_BINARY_DIR} refers to the folder from which cmake was executed (project/build). |
| 6 | + |
| 7 | + |
| 8 | +# If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition |
| 9 | +# and dump it in the cache along with proper documentation, otherwise set CMAKE_BUILD_TYPE |
| 10 | +# to Debug prior to calling PROJECT() |
| 11 | +IF(DEFINED CMAKE_BUILD_TYPE) |
| 12 | + SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of |
| 13 | +build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug |
| 14 | +Release RelWithDebInfo MinSizeRel.") |
| 15 | +ELSE() |
| 16 | + ##### Build types ################################################# |
| 17 | + # single-configuration generator like Makefile generator creates following variables per default |
| 18 | + # |
| 19 | + # None (CMAKE_C_FLAGS or CMAKE_CXX_FLAGS used) |
| 20 | + # Debug (CMAKE_C_FLAGS_DEBUG or CMAKE_CXX_FLAGS_DEBUG) |
| 21 | + # Release (CMAKE_C_FLAGS_RELEASE or CMAKE_CXX_FLAGS_RELEASE) |
| 22 | + # RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO |
| 23 | + # MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL) |
| 24 | + #################################################################### |
| 25 | + SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, |
| 26 | +options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release |
| 27 | +RelWithDebInfo MinSizeRel.") |
| 28 | +ENDIF() |
| 29 | + |
| 30 | +message("Build type set to: " ${CMAKE_BUILD_TYPE}) |
| 31 | + |
| 32 | +cmake_minimum_required(VERSION 2.6) |
| 33 | + |
| 34 | +##### Set Project name and version ##################################### |
| 35 | +project(dummyproject) |
| 36 | +SET(PROJECT_VERSION 1.0) |
| 37 | +SET(PROJECT_DESCRIPTION "Template project for C++ development" |
| 38 | +##### End Set Project name and version ################################# |
| 39 | + |
| 40 | +##### Specification of build directory ################################# |
| 41 | +# Specifies a common place where CMake should put all the executables. |
| 42 | +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) |
| 43 | +# Specifies a common place where CMake should put all the libraries |
| 44 | +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) |
| 45 | +# Include headers within source |
| 46 | +# If you create subdirectories within source include headers with subdirectory, i.e. |
| 47 | +# #include "subdirectory/myheader.h" |
| 48 | +include_directories(${PROJECT_SOURCE_DIR}/src) |
| 49 | +##### End specification of build directory ############################## |
| 50 | + |
| 51 | +# Process CMakeLists.txt in the following subdirectory |
| 52 | +add_subdirectory(src) |
| 53 | + |
| 54 | +# command line output on, you can also use make VERBOSE=1 |
| 55 | +# SET(CMAKE_VERBOSE_MAKEFILE on) |
| 56 | + |
| 57 | + |
| 58 | +##### Select required libraries and desired versions###################### |
| 59 | +set(PROJECT_USES_QT FALSE) |
| 60 | +set(DESIRED_QT_VERSION 4.5) |
| 61 | +set(PROJECT_USES_BOOST FALSE) |
| 62 | +# Required boost components will be set in the Boost section below |
| 63 | +# Set your boost version here, otherwise the installed version might not be found |
| 64 | +set( Boost_ADDITIONAL_VERSIONS "1.40 1.41") |
| 65 | +##### End Select required libaries ####################################### |
| 66 | + |
| 67 | +##### Add Qt support ##################################################### |
| 68 | +if(PROJECT_USES_QT) |
| 69 | + # FINDING QT |
| 70 | + # Note: entries are case sensitive, i.e. use 'Qt4' and not 'QT4' |
| 71 | + # If you have a local installation of a qt version, add it to the search path |
| 72 | + SET(QT_SEARCH_PATH /opt) |
| 73 | + message(Desired Qt version is: ${DESIRED_QT_VERSION}) |
| 74 | + # Try to find Qt4 libraries and set all required variables |
| 75 | + find_package(Qt4 REQUIRED) |
| 76 | + |
| 77 | + if(QT_FOUND) |
| 78 | + message("Prerequisite ok: QT installation found") |
| 79 | + # Activate the required Qt-libraries here |
| 80 | + SET (QT_USE_QTTEST TRUE) |
| 81 | + SET (QT_USE_QTTHREAD TRUE) |
| 82 | + SET(QT_USE_QTXML TRUE) |
| 83 | + SET(QT_USE_QTNETWORK TRUE) |
| 84 | + SET(QT_USE_QTGUI TRUE) |
| 85 | + # QtCore and QtGui libraries are loaded by default |
| 86 | + # SET(QT_DONT_USE_QTCORE TRUE) |
| 87 | + # SET(QT_DONT_USE_QTGUI TRUE) |
| 88 | + |
| 89 | + # Definitions to use when compiling code that uses Qt |
| 90 | + add_definitions(${QT_DEFINITIONS}) |
| 91 | + |
| 92 | + # Set your desired Qt-Version here |
| 93 | + include_directories(${QT_INCLUDE_DIR}) |
| 94 | + # Path to a Cmake file that can be included to compile Qt4 applications and libraries |
| 95 | + include(${QT_USE_FILE}) |
| 96 | + else(QT_FOUND) |
| 97 | + message("QT required to build this project, but installation cannot be found!") |
| 98 | + endif(QT_FOUND) |
| 99 | +endif(PROJECT_USES_QT) |
| 100 | +##### End Qt support ####################################################### |
| 101 | + |
| 102 | +##### Add boost support #################################################### |
| 103 | +if(PROJECT_USES_BOOST) |
| 104 | + # Select boost components from (there might be more): filesystem iostreams signals serialization thread system program_options |
| 105 | + find_package(Boost COMPONENTS filesystem program_options) |
| 106 | + |
| 107 | + if(Boost_FOUND) |
| 108 | + message("Prerequisite ok: Boost installation found") |
| 109 | + else(Boost_FOUND) |
| 110 | + message("Boost required to build this project, but installation cannot be found!") |
| 111 | + endif(Boost_FOUND) |
| 112 | + |
| 113 | + include_directories( ${Boost_INCLUDE_DIRS}) |
| 114 | + link_directories( ${Boost_LIBRARY_DIRS}) |
| 115 | +endif(PROJECT_USES_BOOST) |
| 116 | +##### End boost support ##################################################### |
| 117 | + |
| 118 | +##### Update external libaries variable #################################### |
| 119 | +SET(EXTERNAL_LIBS ${Boost_LIBRARIES} ${QT_LIBRARIES}) |
| 120 | +##### End Update external libraries ####################################### |
| 121 | + |
| 122 | +##### User defined area #################################################### |
| 123 | + |
| 124 | +# EXAMPLE: |
| 125 | +# SET(PC104_ROOT_DIR /opt/PC104/) |
| 126 | +# SET(PC104_LIBRARIES module monsterframes communication) |
| 127 | +# include_directories(${PC104_ROOT_DIR}) |
| 128 | +# link_directories(${PC104_ROOT_DIR} |
| 129 | +# /usr/lib |
| 130 | +# ) |
| 131 | + |
| 132 | +# Other required libraries |
| 133 | +# SET(OTHER_LIBS log4cxx sqlite3 uuid) |
| 134 | +# add_definitions(-DLOGGER_EXTERNAL_) |
| 135 | + |
| 136 | +# SET(USER_DEFINED_LIBS ${OTHER_LIBS} ${PC104_LIBRARIES}) |
| 137 | + |
| 138 | +###### End User define area ################################################# |
| 139 | + |
| 140 | +###### COPY Configuration files into build directory ######################## |
| 141 | +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory |
| 142 | + ${PROJECT_SOURCE_DIR}/configuration ${PROJECT_BINARY_DIR}/configuration) |
| 143 | + |
| 144 | +##### INSTALL Process ####################################################### |
| 145 | +# ACTUALLY only *.h files should be used |
| 146 | +install(DIRECTORY ${PROJECT_SOURCE_DIR}/src DESTINATION include/${PROJECT_NAME} |
| 147 | + FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") |
| 148 | + |
| 149 | +# Dont' forget to add an install for your target, when you create your executable or library |
| 150 | +# install(TARGETS ${PROJECT_NAME} |
| 151 | +# RUNTIME DESTINATION bin |
| 152 | +# LIBRARY DESTINATION lib |
| 153 | +# ) |
| 154 | + |
| 155 | + |
| 156 | +##### End INSTALL Process ################################################### |
| 157 | + |
| 158 | +##### Add doxygen support ################################################### |
| 159 | +include(FindDoxygen) #sets DOXYGEN_EXECUTABLE |
| 160 | +if(DOXYGEN_EXECUTABLE) |
| 161 | + # uses |
| 162 | + # PROJECT_NAME = @PROJECT_NAME@ |
| 163 | + # PROJECT_NUMBER = @PROJECT_VERSION@ |
| 164 | + # OUTPUT_DIRECTORY = @PROJECT_BINARY_DIR@/doc |
| 165 | + # INPUT = @PROJECT_SOURCE_DIR@/src |
| 166 | + # input output @ONLY: replace @VAR@ in the input file with the cmake variables |
| 167 | + CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/doc/Doxyfile.in ${PROJECT_SOURCE_DIR}/doc/Doxyfile @ONLY) |
| 168 | + # documentation can be generated with 'make doc' |
| 169 | + ADD_CUSTOM_TARGET(doc ${DOXYGEN_EXECUTABLE} ${PROJECT_SOURCE_DIR}/doc/Doxyfile) |
| 170 | + # generates documentation with cmake |
| 171 | + # QUIET mode is enabled in the configuration file (QUIET = YES) |
| 172 | + EXECUTE_PROCESS(COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_SOURCE_DIR}/doc/Doxyfile ) |
| 173 | +endif(DOXYGEN_EXECUTABLE) |
| 174 | +##### End doxygen support ################################################### |
0 commit comments