|
| 1 | +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) |
| 2 | + |
| 3 | +set(IGN_PROJECT_NAME "gui") |
| 4 | + |
| 5 | +project (ignition-${IGN_PROJECT_NAME}) |
| 6 | +string (TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) |
| 7 | +string (TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) |
| 8 | + |
| 9 | +set (PROJECT_MAJOR_VERSION 0) |
| 10 | +set (PROJECT_MINOR_VERSION 1) |
| 11 | +set (PROJECT_PATCH_VERSION 0) |
| 12 | + |
| 13 | +set (PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}) |
| 14 | +set (PROJECT_VERSION_FULL ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}) |
| 15 | + |
| 16 | +message (STATUS "${PROJECT_NAME} version ${PROJECT_VERSION_FULL}") |
| 17 | + |
| 18 | +set (project_cmake_dir ${PROJECT_SOURCE_DIR}/cmake |
| 19 | + CACHE PATH "Location of CMake scripts") |
| 20 | + |
| 21 | +include (${project_cmake_dir}/Utils.cmake) |
| 22 | + |
| 23 | +######################################## |
| 24 | +# Package Creation: |
| 25 | +include (${project_cmake_dir}/cpack.cmake) |
| 26 | +set (CPACK_PACKAGE_VERSION "${PROJECT_VERSION_FULL}") |
| 27 | +set (CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_MAJOR_VERSION}") |
| 28 | +set (CPACK_PACKAGE_VERSION_MINOR "${PROJECT_MINOR_VERSION}") |
| 29 | +set (CPACK_PACKAGE_VERSION_PATCH "${PROJECT_PATCH_VERSION}") |
| 30 | + |
| 31 | +if (CPACK_GENERATOR) |
| 32 | + message(STATUS "Found CPack generators: ${CPACK_GENERATOR}") |
| 33 | + |
| 34 | + configure_file("${project_cmake_dir}/cpack_options.cmake.in" |
| 35 | + ${PROJECT_CPACK_CFG_FILE} @ONLY) |
| 36 | + |
| 37 | + set(CPACK_PROJECT_CONFIG_FILE ${PROJECT_CPACK_CFG_FILE}) |
| 38 | + include (CPack) |
| 39 | +endif() |
| 40 | + |
| 41 | +# If we're configuring only to package source, stop here |
| 42 | +if (PACKAGE_SOURCE_ONLY) |
| 43 | + message(WARNING "Configuration was done in PACKAGE_SOURCE_ONLY mode." |
| 44 | + "You can build a tarball (make package_source), but nothing else.") |
| 45 | + return() |
| 46 | +endif() |
| 47 | + |
| 48 | +################################################# |
| 49 | +# Documentation: |
| 50 | +add_subdirectory(doc) |
| 51 | + |
| 52 | +# Configure documentation uploader |
| 53 | +configure_file("${project_cmake_dir}/upload_doc.sh.in" |
| 54 | + ${CMAKE_BINARY_DIR}/upload_doc.sh @ONLY) |
| 55 | + |
| 56 | +# If we're configuring only to build docs, stop here |
| 57 | +if (DOC_ONLY) |
| 58 | + message(WARNING "Configuration was done in DOC_ONLY mode." |
| 59 | + " You can build documentation (make doc), but nothing else.") |
| 60 | + return() |
| 61 | +endif() |
| 62 | + |
| 63 | +enable_testing() |
| 64 | + |
| 65 | +# Use GNUInstallDirst to get canonical paths |
| 66 | +include(GNUInstallDirs) |
| 67 | + |
| 68 | +# with -fPIC |
| 69 | +if(UNIX AND NOT WIN32) |
| 70 | + set (CMAKE_INSTALL_PREFIX "/usr" CACHE STRING "Install Prefix") |
| 71 | + find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin ) |
| 72 | + if(CMAKE_UNAME) |
| 73 | + exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR) |
| 74 | + set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR} CACHE INTERNAL |
| 75 | + "processor type (i386 and x86_64)") |
| 76 | + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") |
| 77 | + ADD_DEFINITIONS(-fPIC) |
| 78 | + endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") |
| 79 | + endif(CMAKE_UNAME) |
| 80 | +endif() |
| 81 | + |
| 82 | +set (CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) |
| 83 | + |
| 84 | +# developer's option to cache PKG_CONFIG_PATH and |
| 85 | +# LD_LIBRARY_PATH for local installs |
| 86 | +if(PKG_CONFIG_PATH) |
| 87 | + set (ENV{PKG_CONFIG_PATH} ${PKG_CONFIG_PATH}:$ENV{PKG_CONFIG_PATH}) |
| 88 | +endif() |
| 89 | +if(LD_LIBRARY_PATH) |
| 90 | + set (ENV{LD_LIBRARY_PATH} ${LD_LIBRARY_PATH}:$ENV{LD_LIBRARY_PATH}) |
| 91 | +endif() |
| 92 | + |
| 93 | + |
| 94 | +set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/ignition") |
| 95 | +set (LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) |
| 96 | +set (LIB_INSTALL_DIR_ARCH_INDEPENDENT "lib/") |
| 97 | +set (BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}) |
| 98 | + |
| 99 | +set (USE_FULL_RPATH OFF CACHE BOOL "Set to true to enable full rpath") |
| 100 | + |
| 101 | +if (USE_FULL_RPATH) |
| 102 | + # use, i.e. don't skip the full RPATH for the build tree |
| 103 | + set(CMAKE_SKIP_BUILD_RPATH FALSE) |
| 104 | + |
| 105 | + # when building, don't use the install RPATH already |
| 106 | + # (but later on when installing) |
| 107 | + set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) |
| 108 | + |
| 109 | + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}") |
| 110 | + |
| 111 | + # add the automatically determined parts of the RPATH |
| 112 | + # which point to directories outside the build tree to the install RPATH |
| 113 | + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
| 114 | + |
| 115 | + # the RPATH to be used when installing, but only if its not a system directory |
| 116 | + list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" isSystemDir) |
| 117 | + if("${isSystemDir}" STREQUAL "-1") |
| 118 | + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}") |
| 119 | + endif("${isSystemDir}" STREQUAL "-1") |
| 120 | +endif() |
| 121 | + |
| 122 | +set (BUILD_IGNITION ON CACHE INTERNAL |
| 123 | + "Build Ignition ${IGN_PROJECT_NAME}" FORCE) |
| 124 | +set (build_errors "" CACHE INTERNAL "build errors" FORCE) |
| 125 | +set (build_warnings "" CACHE INTERNAL "build warnings" FORCE) |
| 126 | + |
| 127 | +include (${project_cmake_dir}/DissectVersion.cmake) |
| 128 | + |
| 129 | +message (STATUS "\n\n====== Finding 3rd Party Packages ======") |
| 130 | +include (${project_cmake_dir}/SearchForStuff.cmake) |
| 131 | +message (STATUS "----------------------------------------\n") |
| 132 | + |
| 133 | +##################################### |
| 134 | +MESSAGE(STATUS "Checking ignition build type") |
| 135 | +# Set the default build type |
| 136 | +if (NOT CMAKE_BUILD_TYPE) |
| 137 | + set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING |
| 138 | + "Choose the type of build, options are: Debug Release RelWithDebInfo Profile Check" FORCE) |
| 139 | +endif (NOT CMAKE_BUILD_TYPE) |
| 140 | +# TODO: still convert to uppercase to keep backwards compatibility with |
| 141 | +# uppercase old supported and deprecated modes |
| 142 | +string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE) |
| 143 | + |
| 144 | +set (BUILD_TYPE_PROFILE FALSE) |
| 145 | +set (BUILD_TYPE_RELEASE FALSE) |
| 146 | +set (BUILD_TYPE_RELWITHDEBINFO FALSE) |
| 147 | +set (BUILD_TYPE_DEBUG FALSE) |
| 148 | + |
| 149 | +if ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "PROFILE") |
| 150 | + set (BUILD_TYPE_PROFILE TRUE) |
| 151 | +elseif ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELEASE") |
| 152 | + set (BUILD_TYPE_RELEASE TRUE) |
| 153 | +elseif ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELWITHDEBINFO") |
| 154 | + set (BUILD_TYPE_RELWITHDEBINFO TRUE) |
| 155 | +elseif ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "DEBUG") |
| 156 | + set (BUILD_TYPE_DEBUG TRUE) |
| 157 | +elseif ("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "COVERAGE") |
| 158 | + include (${project_cmake_dir}/CodeCoverage.cmake) |
| 159 | + set (BUILD_TYPE_DEBUG TRUE) |
| 160 | + SETUP_TARGET_FOR_COVERAGE(coverage ctest coverage) |
| 161 | +else() |
| 162 | + build_error("CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} unknown. Valid options are: Debug Release RelWithDebInfo Profile Check Coverage") |
| 163 | +endif() |
| 164 | + |
| 165 | +##################################### |
| 166 | +# Handle CFlags |
| 167 | +unset (CMAKE_C_FLAGS_ALL CACHE) |
| 168 | +unset (CMAKE_CXX_FLAGS CACHE) |
| 169 | + |
| 170 | +# USE_HOST_CFLAGS (default TRUE) |
| 171 | +# Will check building host machine for proper cflags |
| 172 | +if(NOT DEFINED USE_HOST_CFLAGS OR USE_HOST_CFLAGS) |
| 173 | + message(STATUS "Enable host CFlags") |
| 174 | + include (${project_cmake_dir}/HostCFlags.cmake) |
| 175 | +endif() |
| 176 | + |
| 177 | +# USE_UPSTREAM_CFLAGS (default TRUE) |
| 178 | +# Will use predefined ignition developers cflags |
| 179 | +if(NOT DEFINED USE_UPSTREAM_CFLAGS OR USE_UPSTREAM_CFLAGS) |
| 180 | + message(STATUS "Enable upstream CFlags") |
| 181 | + include(${project_cmake_dir}/DefaultCFlags.cmake) |
| 182 | +endif() |
| 183 | + |
| 184 | +# Check if warning options are avaliable for the compiler and return WARNING_CXX_FLAGS variable |
| 185 | +filter_valid_compiler_warnings(-Wall -Wextra -Wno-long-long |
| 186 | + -Wno-unused-value -Wno-unused-value -Wno-unused-value -Wno-unused-value |
| 187 | + -Wfloat-equal -Wshadow -Winit-self -Wswitch-default |
| 188 | + -Wmissing-include-dirs -pedantic) |
| 189 | +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${WARNING_CXX_FLAGS}") |
| 190 | + |
| 191 | +################################################# |
| 192 | +# OS Specific initialization |
| 193 | +if (UNIX) |
| 194 | + ign_setup_unix() |
| 195 | +else (WIN32) |
| 196 | + ign_setup_windows() |
| 197 | +endif() |
| 198 | + |
| 199 | +if(APPLE) |
| 200 | + ign_setup_apple() |
| 201 | +endif() |
| 202 | + |
| 203 | +################################################# |
| 204 | +# Print warnings and errors |
| 205 | +if ( build_warnings ) |
| 206 | + message(STATUS "BUILD WARNINGS") |
| 207 | + foreach (msg ${build_warnings}) |
| 208 | + message(STATUS ${msg}) |
| 209 | + endforeach () |
| 210 | + message(STATUS "END BUILD WARNINGS\n") |
| 211 | +endif (build_warnings) |
| 212 | + |
| 213 | +########### Add uninstall target ############### |
| 214 | +configure_file( |
| 215 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" |
| 216 | + "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake" |
| 217 | + IMMEDIATE @ONLY) |
| 218 | +add_custom_target(uninstall |
| 219 | + "${CMAKE_COMMAND}" -P |
| 220 | + "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake") |
| 221 | + |
| 222 | +if (build_errors) |
| 223 | + message(STATUS "BUILD ERRORS: These must be resolved before compiling.") |
| 224 | + foreach (msg ${build_errors}) |
| 225 | + message(STATUS ${msg}) |
| 226 | + endforeach () |
| 227 | + message(STATUS "END BUILD ERRORS\n") |
| 228 | + message (FATAL_ERROR "Errors encountered in build. " |
| 229 | + "Please see the BUILD ERRORS above.") |
| 230 | +else (build_errors) |
| 231 | + |
| 232 | + ######################################## |
| 233 | + # Write the config.h file |
| 234 | + configure_file (${project_cmake_dir}/config.hh.in |
| 235 | + ${PROJECT_BINARY_DIR}/include/ignition/${IGN_PROJECT_NAME}/config.hh) |
| 236 | + ign_install_includes(${IGN_PROJECT_NAME} |
| 237 | + ${PROJECT_BINARY_DIR}/include/ignition/${IGN_PROJECT_NAME}/config.hh) |
| 238 | + |
| 239 | + include_directories( |
| 240 | + ${PROJECT_SOURCE_DIR}/include |
| 241 | + ${PROJECT_BINARY_DIR}/include |
| 242 | + ) |
| 243 | + link_directories(${PROJECT_BINARY_DIR}/src) |
| 244 | + |
| 245 | + if (DEFINED CMAKE_CXX_FLAGS) |
| 246 | + message (STATUS "Custom CFlags:${CMAKE_CXX_FLAGS}") |
| 247 | + else() |
| 248 | + message (STATUS "Use default CFlags") |
| 249 | + endif() |
| 250 | + message (STATUS "Build Type: ${CMAKE_BUILD_TYPE}") |
| 251 | + message (STATUS "Install path: ${CMAKE_INSTALL_PREFIX}") |
| 252 | + |
| 253 | + |
| 254 | + if (BUILD_IGNITION) |
| 255 | + set(TEST_TYPE "UNIT") |
| 256 | + add_subdirectory(src) |
| 257 | + add_subdirectory(include) |
| 258 | + add_subdirectory(test) |
| 259 | + endif (BUILD_IGNITION) |
| 260 | + |
| 261 | + ######################################## |
| 262 | + # Make the package config files |
| 263 | + configure_file( |
| 264 | + ${CMAKE_SOURCE_DIR}/cmake/pkgconfig/ignition.in |
| 265 | + ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${PROJECT_NAME_LOWER}.pc @ONLY) |
| 266 | + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/pkgconfig/${PROJECT_NAME_LOWER}.pc |
| 267 | + DESTINATION ${LIB_INSTALL_DIR_ARCH_INDEPENDENT}/pkgconfig |
| 268 | + COMPONENT pkgconfig) |
| 269 | + |
| 270 | + ######################################## |
| 271 | + # Make the cmake config files |
| 272 | + set(PKG_NAME ${PROJECT_NAME_UPPER}) |
| 273 | + set(PKG_LIBRARIES ${PROJECT_NAME_LOWER}${PROJECT_MAJOR_VERSION}) |
| 274 | + set(cmake_conf_file "${PROJECT_NAME_LOWER}${PROJECT_MAJOR_VERSION}-config.cmake") |
| 275 | + set(cmake_conf_version_file "${PROJECT_NAME_LOWER}${PROJECT_MAJOR_VERSION}-config-version.cmake") |
| 276 | + |
| 277 | + set(PKG_DEPENDS) |
| 278 | + |
| 279 | + configure_file( |
| 280 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME_LOWER}-config.cmake.in" |
| 281 | + "${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file}" @ONLY) |
| 282 | + |
| 283 | + # Use write_basic_package_version_file to generate a ConfigVersion file that |
| 284 | + # allow users of gazebo to specify the API or version to depend on |
| 285 | + # TODO: keep this instruction until deprecate Ubuntu/Precise and update with |
| 286 | + # https://github.com/Kitware/CMake/blob/v2.8.8/Modules/CMakePackageConfigHelpers.cmake |
| 287 | + include(WriteBasicConfigVersionFile) |
| 288 | + write_basic_config_version_file( |
| 289 | + ${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_version_file} |
| 290 | + VERSION "${PROJECT_VERSION_FULL}" |
| 291 | + COMPATIBILITY SameMajorVersion) |
| 292 | + |
| 293 | + install(FILES |
| 294 | + ${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file} |
| 295 | + ${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_version_file} |
| 296 | + DESTINATION ${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME_LOWER}${PROJECT_MAJOR_VERSION}/ COMPONENT cmake) |
| 297 | + |
| 298 | + ######################################## |
| 299 | + # If present, load platform-specific build hooks. This system is used, |
| 300 | + # for example, by the Ubuntu overlay, to arrange for installation of |
| 301 | + # Ubuntu-specific application-launching configuration. |
| 302 | + if (EXISTS ${PROJECT_SOURCE_DIR}/cmake/packager-hooks/CMakeLists.txt) |
| 303 | + message(STATUS "Loading packager build hooks from cmake/packager-hooks") |
| 304 | + add_subdirectory(cmake/packager-hooks) |
| 305 | + endif() |
| 306 | + |
| 307 | + message(STATUS "Configuration successful. Type make to compile |
| 308 | + ${PROJECT_NAME_LOWER}") |
| 309 | +endif(build_errors) |
0 commit comments