From 4147f50d771992a70e1742c82f96ae34e2e9c60b Mon Sep 17 00:00:00 2001 From: Daniel Nachbaur Date: Tue, 5 Apr 2016 16:35:51 +0200 Subject: [PATCH] CMake3 port and various cleanups --- CHANGES.md | 30 +++ CMakeInstallPath.cmake | 7 - Common.cmake | 111 ++++----- CommonApplication.cmake | 20 +- CommonCPPCTest.cmake | 11 +- CommonCPack.cmake | 7 +- CommonClangCheck.cmake | 12 +- CommonCode.cmake | 16 -- CommonCompiler.cmake | 223 ++++++++++++++++++ Coverage.cmake => CommonCoverage.cmake | 8 +- CommonDocumentation.cmake | 60 ----- ...onPackage.cmake => CommonFindPackage.cmake | 67 +++--- CommonGraph.cmake | 4 +- CommonLibrary.cmake | 77 ++---- CommonPackageConfig.cmake | 23 +- CommonQtSupport.cmake | 45 ---- Compiler.cmake | 164 ------------- CompilerIdentification.cmake | 81 ------- CompilerVersion.cmake | 12 - DoxygenRule.cmake | 2 +- FindVTune.cmake | 4 - GitExternal.cmake | 6 +- InstallSymlink.cmake | 19 -- LibFindMacros.cmake | 103 ++++---- README.md | 30 +-- SubProject.cmake | 69 +----- System.cmake | 29 --- TestCPP11.cmake | 113 --------- cpp/defines.h | 2 +- cpp/dummy.cpp | 1 - cpp/test.h | 136 ----------- cpp/version.h | 8 +- 32 files changed, 479 insertions(+), 1021 deletions(-) delete mode 100644 CMakeInstallPath.cmake delete mode 100644 CommonCode.cmake create mode 100644 CommonCompiler.cmake rename Coverage.cmake => CommonCoverage.cmake (94%) delete mode 100644 CommonDocumentation.cmake rename CommonPackage.cmake => CommonFindPackage.cmake (84%) delete mode 100644 CommonQtSupport.cmake delete mode 100644 Compiler.cmake delete mode 100644 CompilerIdentification.cmake delete mode 100644 CompilerVersion.cmake delete mode 100644 InstallSymlink.cmake delete mode 100644 System.cmake delete mode 100644 TestCPP11.cmake delete mode 100644 cpp/dummy.cpp delete mode 100644 cpp/test.h diff --git a/CHANGES.md b/CHANGES.md index 258e880..6be6603 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,35 @@ # git master +* [478](https://github.com/Eyescale/CMake/pull/478): + CMake3 port and various cleanups + * CMake 3.1 is now required + * Renames of files + * CommonPackage.cmake -> CommonFindPackage.cmake + * Compiler.cmake -> CommonCompiler.cmake + * Coverage.cmake -> CommonCoverage.cmake + * Renames of variables and options + * CMAKE_COMPILER_IS_GNUCXX -> CMAKE_COMPILER_IS_GCC + * COMMON_PACKAGE_DEFINES -> COMMON_FIND_PACKAGE_DEFINES + * COMMON_PACKAGE_USE_QUIET -> COMMON_FIND_PACKAGE_QUIET + * DOC_DIR -> COMMON_DOC_DIR + * ENABLE_CLANGCHECK_TESTS -> COMMON_ENABLE_CLANGCHECK_TESTS + * ENABLE_COVERAGE -> COMMON_ENABLE_COVERAGE + * ENABLE_CXX11_STDLIB -> COMMON_ENABLE_CXX11_STDLIB + * ENABLE_WARN_DEPRECATED -> COMMON_WARN_DEPRECATED + * GIT_EXTERNAL_VERBOSE -> COMMON_GIT_EXTERNAL_VERBOSE + * VERSION_ABI -> ${PROJECT_NAME}_VERSION_ABI + * VERSION -> ${PROJECT_NAME}_VERSION + * Renames of functions + * common_compiler_flags() -> common_compiler_options(${target}) + * common_package() -> common_find_package() + * common_package_post() -> common_find_package_post() + * VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH are now part of project() + * OUTPUT_INCLUDE_DIR removed; use ${PROJECT_BINARY_DIR}/include instead + * Per-target include directories and definitions instead of global pollution + * Qt support is now implicit thanks to AUTOMOC, AUTORCC and AUTOUIC feature: + NAME_MOC_HEADERS, NAME_UI_FORMS and NAME_RESOURCES are not supported + anymore; use NAME_PUBLIC_HEADERS, NAME_HEADERS and NAME_SOURCES + accordingly * [477](https://github.com/Eyescale/CMake/pull/477): Rename functions to common_cppcheck, common_clangcheck and common_cpplint to solve a name clash with ITK diff --git a/CMakeInstallPath.cmake b/CMakeInstallPath.cmake deleted file mode 100644 index 659fd9b..0000000 --- a/CMakeInstallPath.cmake +++ /dev/null @@ -1,7 +0,0 @@ -# sets CMAKE_MODULE_INSTALL_PATH to where CMake script should be installed - -if(MSVC) - set(CMAKE_MODULE_INSTALL_PATH ${PROJECT_NAME}/CMake) -else() - set(CMAKE_MODULE_INSTALL_PATH share/${PROJECT_NAME}/CMake) -endif() diff --git a/Common.cmake b/Common.cmake index d840761..48e9b01 100644 --- a/Common.cmake +++ b/Common.cmake @@ -1,54 +1,45 @@ # Common settings # # Output variables -# VERSION - ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} # UPPER_PROJECT_NAME - lower-case ${PROJECT_NAME} # LOWER_PROJECT_NAME - upper-case ${PROJECT_NAME} # TRAVIS - if environment is travis build system # BLUEGENE - if machine is BlueGene # LINUX - if machine is Linux # LINUX_PPC - if machine is PowerPC Linux -# DOC_DIR - folder for documentation, share/${PROJECT_NAME}/doc +# COMMON_DOC_DIR - folder for documentation, share/${PROJECT_NAME}/doc # COMMON_OSX_TARGET_VERSION - OS X target version # +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) + if(CMAKE_INSTALL_PREFIX STREQUAL PROJECT_BINARY_DIR) message(FATAL_ERROR "Cannot install into build directory") endif() -cmake_minimum_required(VERSION 2.8.9 FATAL_ERROR) - -string(TOUPPER ${PROJECT_NAME} UPPER_PROJECT_NAME) -string(TOLOWER ${PROJECT_NAME} LOWER_PROJECT_NAME) - -include(ChoosePython) # Must be before any find_package to python - -if(EXISTS ${PROJECT_SOURCE_DIR}/CMake/${PROJECT_NAME}.cmake) - include(${PROJECT_SOURCE_DIR}/CMake/${PROJECT_NAME}.cmake) -endif() - -include(CommonPackage) +cmake_policy(SET CMP0020 NEW) # Automatically link Qt executables to qtmain target on Windows. +cmake_policy(SET CMP0037 NEW) # Target names should not be reserved and should match a validity pattern. +cmake_policy(SET CMP0038 NEW) # Targets may not link directly to themselves. +cmake_policy(SET CMP0048 NEW) # The project() command manages VERSION variables. +cmake_policy(SET CMP0054 OLD) # Only interpret if() arguments as variables or keywords when unquoted. +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) # -fPIC +set(CMAKE_INSTALL_MESSAGE LAZY) # no up-to-date messages on installation +set(CMAKE_CXX_STANDARD_REQUIRED ON) # value of CXX_STANDARD on targets is required +set_property(GLOBAL PROPERTY USE_FOLDERS ON) # organize targets into folders enable_testing() -set_property(GLOBAL PROPERTY USE_FOLDERS ON) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE) endif() -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_INSTALL_MESSAGE LAZY) # no up-to-date messages on installation - -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) -add_definitions(-D${UPPER_PROJECT_NAME}_VERSION=${VERSION}) -# Linux libraries must have an SONAME to expose their ABI version to users. -# If VERSION_ABI has not been declared, use the following common conventions: -# - ABI version matches MAJOR version (ABI only changes with MAJOR releases) -# - MINOR and PATCH releases preserve backward ABI compatibility -# - PATCH releases preseve forward+backward API compatibility (no new features) -if(NOT DEFINED VERSION_ABI) - set(VERSION_ABI ${VERSION_MAJOR}) - message(STATUS "VERSION_ABI not set for ${PROJECT_NAME}. Using VERSION_MAJOR=${VERSION_MAJOR} as the ABI version.") +if(MSVC) + set(CMAKE_MODULE_INSTALL_PATH ${PROJECT_NAME}/CMake) +else() + set(CMAKE_MODULE_INSTALL_PATH share/${PROJECT_NAME}/CMake) endif() if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND NOT MSVC) @@ -56,26 +47,26 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND NOT MSVC) "${PROJECT_NAME} install prefix" FORCE) endif() -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - -set(DOC_DIR share/${PROJECT_NAME}/doc) -include(${CMAKE_CURRENT_LIST_DIR}/CMakeInstallPath.cmake) +# Linux libraries must have an SONAME to expose their ABI version to users. +# If VERSION_ABI has not been declared, use the following common conventions: +# - ABI version matches MAJOR version (ABI only changes with MAJOR releases) +# - MINOR and PATCH releases preserve backward ABI compatibility +# - PATCH releases preseve forward+backward API compatibility (no new features) +if(NOT DEFINED ${PROJECT_NAME}_VERSION_ABI) + set(${PROJECT_NAME}_VERSION_ABI ${${PROJECT_NAME}_VERSION_MAJOR}) + message(STATUS "VERSION_ABI not set for ${PROJECT_NAME}. Using VERSION_MAJOR=${${PROJECT_NAME}_VERSION_MAJOR} as the ABI version.") +endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux") include(LSBInfo) set(LINUX TRUE) if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc") set(LINUX_PPC 1) - else() - add_definitions(-fPIC) endif() -endif() -set(LIBRARY_DIR lib) - -if(APPLE) - cmake_policy(SET CMP0042 NEW) +elseif(APPLE) + cmake_policy(SET CMP0042 NEW) # MACOSX_RPATH is enabled by default. + execute_process(COMMAND sw_vers -productVersion OUTPUT_VARIABLE OSX_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) list(APPEND CMAKE_PREFIX_PATH /opt/local/ /opt/local/lib /opt/local/libexec/qt5-mac) # Macports set(ENV{PATH} "/opt/local/bin:$ENV{PATH}") # dito @@ -83,8 +74,11 @@ if(APPLE) set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OS X" FORCE) endif() - set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ") - set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ") + # https://cmake.org/Bug/view.php?id=15953 + if(CMAKE_VERSION VERSION_LESS 3.6) + set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ") + set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ") + endif() if(NOT CMAKE_INSTALL_NAME_DIR) set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib") endif() @@ -94,37 +88,46 @@ if(APPLE) execute_process(COMMAND sw_vers -productVersion OUTPUT_VARIABLE COMMON_OSX_TARGET_VERSION) endif() -endif() -if(MSVC) - # http://www.cmake.org/cmake/help/v3.0/policy/CMP0020.html - cmake_policy(SET CMP0020 NEW) +elseif(IS_DIRECTORY "/bgsys") + set(BLUEGENE TRUE) endif() if($ENV{TRAVIS}) set(TRAVIS ON) endif() -if(IS_DIRECTORY "/bgsys") - set(BLUEGENE TRUE) +string(TOUPPER ${PROJECT_NAME} UPPER_PROJECT_NAME) +string(TOLOWER ${PROJECT_NAME} LOWER_PROJECT_NAME) + +set(PROJECT_INCLUDE_NAME ${${UPPER_PROJECT_NAME}_INCLUDE_NAME}) +if(NOT PROJECT_INCLUDE_NAME) + set(PROJECT_INCLUDE_NAME ${LOWER_PROJECT_NAME}) endif() +set(PROJECT_namespace ${${UPPER_PROJECT_NAME}_namespace}) +if(NOT PROJECT_namespace) + set(PROJECT_namespace ${PROJECT_INCLUDE_NAME}) +endif() + +set(COMMON_DOC_DIR share/${PROJECT_NAME}/doc) + +include(ChoosePython) # Must be before any find_package to python +include(CommonFindPackage) + # OPT if(NOT DOXYGEN_FOUND) find_package(Doxygen QUIET) endif() include(CommonApplication) -include(CommonCode) -include(CommonDocumentation) include(CommonInstall) include(CommonLibrary) -include(Compiler) -include(Coverage) +include(CommonCompiler) +include(CommonCoverage) include(GitInfo) include(GitTargets) include(Maturity) include(ProjectInfo) -include(TestCPP11) include(UpdateGitExternal) include(SubProject) diff --git a/CommonApplication.cmake b/CommonApplication.cmake index 038398b..4c9d39a 100644 --- a/CommonApplication.cmake +++ b/CommonApplication.cmake @@ -15,10 +15,6 @@ # * NAME_LINK_LIBRARIES for dependencies of name # * NAME_OMIT_CHECK_TARGETS do not create cppcheck targets # * ARGN for optional add_executable parameters -# * Optional Qt support: -# ** NAME_MOC_HEADERS list of all moc input headers -# ** NAME_UI_FORMS list of all .ui input files -# ** NAME_RESOURCES list of all .qrc resource files # * NAME_DATA files for share/Project/data (in binary and install dir) # * NAME_ICON optional .icns file (Mac OS GUI applications only) # * NAME_COPYRIGHT optional copyright notice (Mac OS GUI applications only) @@ -27,18 +23,10 @@ include(AppleCheckOpenGL) include(CommonCheckTargets) -include(CommonQtSupport) include(CMakeParseArguments) include(StringifyShaders) -# applying CMAKE_C(XX)_FLAGS to add_executable only works from parent -# scope, hence the macro calling the function _common_application -macro(COMMON_APPLICATION Name) - common_compiler_flags() - _common_application(${Name} ${ARGN}) -endmacro() - -function(_common_application Name) +function(common_application Name) set(_opts GUI EXAMPLE) set(_singleArgs) set(_multiArgs) @@ -48,13 +36,10 @@ function(_common_application Name) string(TOUPPER ${Name} NAME) string(TOLOWER ${Name} name) set(SOURCES ${${NAME}_SOURCES}) - set(HEADERS ${${NAME}_HEADERS} ${${NAME}_MOC_HEADERS}) + set(HEADERS ${${NAME}_HEADERS}) set(LINK_LIBRARIES ${${NAME}_LINK_LIBRARIES}) set(ICON ${${NAME}_ICON}) - common_qt_support(${NAME}) - list(APPEND SOURCES ${COMMON_QT_SUPPORT_SOURCES}) - if(${NAME}_SHADERS) stringify_shaders(${${NAME}_SHADERS}) list(APPEND SOURCES ${SHADER_SOURCES}) @@ -71,6 +56,7 @@ function(_common_application Name) add_executable(${Name} ${OPTIONS} ${ICON} ${HEADERS} ${SOURCES}) set_target_properties(${Name} PROPERTIES FOLDER ${PROJECT_NAME}) + common_compile_options(${Name}) target_link_libraries(${Name} ${LINK_LIBRARIES}) install(TARGETS ${Name} DESTINATION bin COMPONENT apps) diff --git a/CommonCPPCTest.cmake b/CommonCPPCTest.cmake index 06b7708..968a88f 100644 --- a/CommonCPPCTest.cmake +++ b/CommonCPPCTest.cmake @@ -38,10 +38,6 @@ if(NOT WIN32) # tests want to be with DLLs on Windows - no rpath support set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) endif() -include_directories(${CMAKE_CURRENT_LIST_DIR}/cpp ${PROJECT_SOURCE_DIR}) - -common_compiler_flags() - file(GLOB_RECURSE TEST_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c *.cpp) foreach(FILE ${EXCLUDE_FROM_TESTS}) list(REMOVE_ITEM TEST_FILES ${FILE}) @@ -68,6 +64,7 @@ macro(common_add_cpp_test NAME FILE) endif() add_executable(${TEST_NAME} ${FILE}) + common_compile_options(${TEST_NAME}) common_check_targets(${TEST_NAME}) set_target_properties(${TEST_NAME} PROPERTIES FOLDER ${PROJECT_NAME}/tests OUTPUT_NAME ${NAME}) @@ -75,8 +72,8 @@ macro(common_add_cpp_test NAME FILE) # for DoxygenRule.cmake and SubProject.cmake set_property(GLOBAL APPEND PROPERTY ${PROJECT_NAME}_ALL_DEP_TARGETS ${TEST_NAME}) - # Per target INCLUDE_DIRECTORIES if supported - if(CMAKE_VERSION VERSION_GREATER 2.8.7 AND ${NAME}_INCLUDE_DIRECTORIES) + # Per target INCLUDE_DIRECTORIES + if(${NAME}_INCLUDE_DIRECTORIES) set_target_properties(${TEST_NAME} PROPERTIES INCLUDE_DIRECTORIES "${${NAME}_INCLUDE_DIRECTORIES}") endif() @@ -169,7 +166,7 @@ add_dependencies(${PROJECT_NAME}-tests ${PROJECT_NAME}-cpptests) add_dependencies(tests ${PROJECT_NAME}-tests) add_dependencies(${PROJECT_NAME}-nightlytests ${PROJECT_NAME}-perftests) -if(ENABLE_COVERAGE) +if(COMMON_ENABLE_COVERAGE) foreach(TEST_FILE ${TEST_FILES}) list(APPEND LCOV_EXCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE}") endforeach() diff --git a/CommonCPack.cmake b/CommonCPack.cmake index 7c7e608..b98267b 100644 --- a/CommonCPack.cmake +++ b/CommonCPack.cmake @@ -48,9 +48,9 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") set(CPACK_PACKAGE_NAME "${LOWER_PACKAGE_NAME_PREFIX}") set(OLD_PACKAGES) - if(VERSION_ABI) - set(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}${VERSION_ABI}") - math(EXPR NUM_OLD_PACKAGES "${VERSION_ABI} - 1") + if(${PROJECT_NAME}_VERSION_ABI) + set(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}${${PROJECT_NAME}_VERSION_ABI}") + math(EXPR NUM_OLD_PACKAGES "${${PROJECT_NAME}_VERSION_ABI} - 1") foreach(i RANGE ${NUM_OLD_PACKAGES}) list(APPEND OLD_PACKAGES "${LOWER_PACKAGE_NAME_PREFIX}${i},") endforeach() @@ -69,7 +69,6 @@ set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}) set(CPACK_PACKAGE_VERSION ${VERSION}) if(NOT CPACK_DEBIAN_BUILD_DEPENDS) - # setup'd by Buildyard config, same as for travis CI set(CPACK_DEBIAN_BUILD_DEPENDS ${${UPPER_PROJECT_NAME}_BUILD_DEBS}) endif() diff --git a/CommonClangCheck.cmake b/CommonClangCheck.cmake index ad696c4..b50ec63 100644 --- a/CommonClangCheck.cmake +++ b/CommonClangCheck.cmake @@ -24,6 +24,8 @@ if(NOT CLANGCHECK) endif() endif() +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # write compile_commands.json for clangcheck + if(NOT TARGET clangcheck) add_custom_target(clangcheck) endif() @@ -51,12 +53,12 @@ function(common_clangcheck _name) set(_files ${${_name}_FILES}) endif() - if(ENABLE_CLANGCHECK_TESTS) - add_test(NAME ${_name}_clangcheck_test + if(COMMON_ENABLE_CLANGCHECK_TESTS) + add_test(NAME ${_name}-clangcheck-test COMMAND "${CLANGCHECK}" ${_clangcheck_args} ${_files} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") - set_tests_properties(${_name}_clangcheck_test + set_tests_properties(${_name}-clangcheck-test PROPERTIES FAIL_REGULAR_EXPRESSION " (warning|error): ") endif() @@ -66,6 +68,6 @@ function(common_clangcheck _name) COMMENT "Running clangcheck on target ${_name}..." VERBATIM) add_dependencies(clangcheck ${_name}-clangcheck) - set_target_properties(${_name}-clangcheck PROPERTIES - EXCLUDE_FROM_DEFAULT_BUILD ON FOLDER ${PROJECT_NAME}/tests) + set_target_properties(${_name}-clangcheck PROPERTIES + EXCLUDE_FROM_DEFAULT_BUILD ON FOLDER ${PROJECT_NAME}/tests) endfunction() diff --git a/CommonCode.cmake b/CommonCode.cmake deleted file mode 100644 index 32c0dc5..0000000 --- a/CommonCode.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# Common.cmake include and cpp files and setting, do not use directly - -set(OUTPUT_INCLUDE_DIR ${PROJECT_BINARY_DIR}/include) -file(MAKE_DIRECTORY ${OUTPUT_INCLUDE_DIR}) -include_directories(BEFORE ${PROJECT_SOURCE_DIR} ${OUTPUT_INCLUDE_DIR}) - -set(PROJECT_INCLUDE_NAME ${${UPPER_PROJECT_NAME}_INCLUDE_NAME}) -set(PROJECT_namespace ${${UPPER_PROJECT_NAME}_namespace}) - -if(NOT PROJECT_INCLUDE_NAME) - set(PROJECT_INCLUDE_NAME ${LOWER_PROJECT_NAME}) -endif() -if(NOT PROJECT_namespace) - set(PROJECT_namespace ${PROJECT_INCLUDE_NAME}) -endif() -string(TOUPPER ${PROJECT_namespace} PROJECT_NAMESPACE) diff --git a/CommonCompiler.cmake b/CommonCompiler.cmake new file mode 100644 index 0000000..4bb0fc1 --- /dev/null +++ b/CommonCompiler.cmake @@ -0,0 +1,223 @@ +# Copyright (c) 2012-2014 Fabien Delalondre +# Stefan.Eilemann@epfl.ch +# +# Sets compiler optimization, definition and warnings according to +# chosen compiler. Supported compilers are XL, Intel, Clang, gcc (4.4 +# or later) and Visual Studio (2008 or later). +# +# This defines the common_compile_options() function to apply compiler flags and +# features for the given target. +# +# Input Variables +# * COMMON_MINIMUM_GCC_VERSION check for a minimum gcc version, default 4.4 +# * COMMON_USE_CXX03 When set, do not enable C++11 language features +# +# Output Variables +# * CMAKE_COMPILER_IS_XLCXX for IBM XLC +# * CMAKE_COMPILER_IS_INTEL for Intel C++ Compiler +# * CMAKE_COMPILER_IS_CLANG for clang +# * CMAKE_COMPILER_IS_GCC for gcc +# * GCC_COMPILER_VERSION The compiler version if gcc is used + +# OPT: necessary only once, included by Common.cmake +if(COMPILER_DONE) + return() +endif() +set(COMPILER_DONE ON) + +# Compiler name +if(CMAKE_CXX_COMPILER_ID STREQUAL "XL") + set(CMAKE_COMPILER_IS_XLCXX ON) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + set(CMAKE_COMPILER_IS_INTEL ON) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR + CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + set(CMAKE_COMPILER_IS_CLANG ON) +elseif(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_COMPILER_IS_GCC ON) +endif() +# use MSVC for Visual Studio + +option(COMMON_WARN_DEPRECATED "Enable compiler deprecation warnings" ON) +option(COMMON_ENABLE_CXX11_STDLIB "Enable C++11 stdlib" OFF) + +if(COMMON_WARN_DEPRECATED) + add_definitions(-DWARN_DEPRECATED) # projects have to pick this one up +endif() + +# https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html +set(COMMON_CXX11_FEATURES + cxx_alias_templates cxx_nullptr cxx_override cxx_final cxx_noexcept) + +function(compiler_dumpversion OUTPUT_VERSION) + execute_process(COMMAND + ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion + OUTPUT_VARIABLE DUMP_COMPILER_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1.\\2" + DUMP_COMPILER_VERSION "${DUMP_COMPILER_VERSION}") + + set(${OUTPUT_VERSION} ${DUMP_COMPILER_VERSION} PARENT_SCOPE) +endfunction() + +if(CMAKE_COMPILER_IS_GCC OR CMAKE_COMPILER_IS_CLANG) + compiler_dumpversion(GCC_COMPILER_VERSION) + if(NOT COMMON_MINIMUM_GCC_VERSION) + set(COMMON_MINIMUM_GCC_VERSION 4.4) + endif() + if(CMAKE_COMPILER_IS_GCC) + if(GCC_COMPILER_VERSION VERSION_LESS COMMON_MINIMUM_GCC_VERSION) + message(FATAL_ERROR "Using gcc ${GCC_COMPILER_VERSION}, need at least ${COMMON_MINIMUM_GCC_VERSION}") + endif() + if(GCC_COMPILER_VERSION VERSION_LESS 4.5) + set(COMMON_USE_CXX03 ON) + endif() + if(GCC_COMPILER_VERSION VERSION_LESS 4.8) + # http://stackoverflow.com/questions/4438084 + add_definitions(-D_GLIBCXX_USE_NANOSLEEP) + endif() + endif() + + set(COMMON_C_FLAGS + -Wall -Wextra -Winvalid-pch -Winit-self -Wno-unknown-pragmas -Wshadow) + set(COMMON_CXX_FLAGS + -Wnon-virtual-dtor -Wsign-promo -Wvla -fno-strict-aliasing) + + if(NOT WIN32 AND NOT XCODE_VERSION) + list(APPEND COMMON_C_FLAGS -Werror) + endif() + + if(CMAKE_COMPILER_IS_CLANG) + list(APPEND COMMON_C_FLAGS + -Qunused-arguments -ferror-limit=5 -ftemplate-depth-1024 -Wheader-hygiene) + if(COMMON_ENABLE_CXX11_STDLIB) + list(APPEND COMMON_CXX_FLAGS -stdlib=libc++) + endif() + else() + if(GCC_COMPILER_VERSION VERSION_GREATER 4.5) + list(APPEND COMMON_C_FLAGS -fmax-errors=5) + endif() + endif() + + list(APPEND COMMON_CXX_FLAGS_RELEASE -Wuninitialized) + +elseif(CMAKE_COMPILER_IS_INTEL) + set(COMMON_C_FLAGS + -Wall -Wextra -Winvalid-pch -Winit-self -Wno-unknown-pragmas) + set(COMMON_CXX_FLAGS + -Wno-deprecated -Wno-unknown-pragmas -Wshadow -fno-strict-aliasing -Wuninitialized -Wsign-promo -Wnon-virtual-dtor) + + # Release: automatically generate instructions for the highest + # supported compilation host + set(COMMON_C_FLAGS_RELEASE -xhost) + set(COMMON_CXX_FLAGS_RELEASE -xhost) + + set(CMAKE_CXX11_COMPILE_FEATURES ${COMMON_CXX11_FEATURES}) + set(CMAKE_CXX_COMPILE_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES}) + set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11") + set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=c++11") + if(NOT COMMON_USE_CXX03) + list(APPEND COMMON_CXX_FLAGS -std=c++11) + endif() + +elseif(CMAKE_COMPILER_IS_XLCXX) + # default: Maintain code semantics Fix to link dynamically. On the + # next pass should add an if statement: 'if shared ...'. Overriding + # default release flags since the default were '-O -NDEBUG'. By + # default, set flags for backend since this is the most common use + # case + option(XLC_BACKEND "Compile for BlueGene compute nodes using XLC compilers" + ON) + if(XLC_BACKEND) + set(COMMON_CXX_FLAGS_RELEASE + -O3 -qtune=qp -qarch=qp -q64 -qstrict -qnohot -qnostaticlink -DNDEBUG) + set(COMMON_C_FLAGS_RELEASE ${COMMON_CXX_FLAGS_RELEASE}) + set(COMMON_LIBRARY_TYPE STATIC) + set(COMPILE_LIBRARY_TYPE STATIC) + else() + set(COMMON_CXX_FLAGS_RELEASE + -O3 -q64 -qstrict -qnostaticlink -qnostaticlink=libgcc -DNDEBUG) + set(COMMON_C_FLAGS_RELEASE ${COMMON_CXX_FLAGS_RELEASE}) + endif() + +elseif(MSVC) + # By default, do not warn when built on machines using only VS Express + # http://cmake.org/gitweb?p=cmake.git;a=commit;h=fa4a3b04d0904a2e93242c0c3dd02a357d337f77 + if(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS) + set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON) + endif() + + # http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60015&start=0 + set(COMMON_CXX_FLAGS /DWIN32 /D_WINDOWS /W3 /Zm500 /EHsc /GR + /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS + /wd4068 # disable unknown pragma warnings + /wd4244 # conversion from X to Y, possible loss of data + /wd4800 # forcing value to bool 'true' or 'false' (performance warning) + /wd4351 # new behavior: elements of array 'array' will be default initialized + ) + set(COMMON_CXX_FLAGS_DEBUG /WX) +else() + message(FATAL_ERROR "Unknown/unsupported compiler ${CMAKE_CXX_COMPILER_ID}") +endif() + +set(COMMON_C_FLAGS_RELWITHDEBINFO -DNDEBUG) +set(COMMON_CXX_FLAGS_RELWITHDEBINFO -DNDEBUG) + +list(APPEND COMMON_CXX_FLAGS ${COMMON_C_FLAGS}) + +function(common_compile_options Name) + get_target_property(__type ${Name} TYPE) + set(__visibility PUBLIC) + if(__type STREQUAL INTERFACE_LIBRARY) + set(__interface 1) + set(__visibility INTERFACE) + endif() + if(COMMON_USE_CXX03) + target_compile_definitions(${Name} ${__visibility} + ${UPPER_PROJECT_NAME}_USE_CXX03) + if(NOT __interface) + set_property(TARGET ${Name} PROPERTY C_STANDARD 99) + set_property(TARGET ${Name} PROPERTY CXX_STANDARD 98) + endif() + else() + if(NOT __interface) + set_property(TARGET ${Name} PROPERTY C_STANDARD 11) + set_property(TARGET ${Name} PROPERTY CXX_STANDARD 11) + endif() + target_compile_features(${Name} ${__visibility} ${COMMON_CXX11_FEATURES}) + endif() + if(NOT __interface) + if(CMAKE_VERSION VERSION_LESS 3.3) + target_compile_options(${Name} PRIVATE + "$<$:${COMMON_CXX_FLAGS_DEBUG}>" + "$<$:${COMMON_CXX_FLAGS_RELWITHDEBINFO}>" + "$<$:${COMMON_CXX_FLAGS_RELEASE}>" + "${COMMON_CXX_FLAGS}" + "$<$:${COMMON_C_FLAGS_DEBUG}>" + "$<$:${COMMON_C_FLAGS_RELWITHDEBINFO}>" + "$<$:${COMMON_C_FLAGS_RELEASE}>" + "${COMMON_C_FLAGS}" + ) + else() + target_compile_options(${Name} PRIVATE + "$<$,$>:${COMMON_CXX_FLAGS_DEBUG}>" + "$<$,$>:${COMMON_CXX_FLAGS_RELWITHDEBINFO}>" + "$<$,$>:${COMMON_CXX_FLAGS_RELEASE}>" + "$<$:${COMMON_CXX_FLAGS}>" + "$<$,$>:${COMMON_C_FLAGS_DEBUG}>" + "$<$,$>:${COMMON_C_FLAGS_RELWITHDEBINFO}>" + "$<$,$>:${COMMON_C_FLAGS_RELEASE}>" + "$<$:${COMMON_C_FLAGS}>" + ) + endif() + if(TARGET Qt5::Core) + set_target_properties(${Name} PROPERTIES AUTOMOC TRUE AUTORCC TRUE) + endif() + if(TARGET Qt5::Widgets) + set_target_properties(${Name} PROPERTIES AUTOUIC TRUE) + endif() + if(CMAKE_COMPILER_IS_GCC) + set_target_properties(${Name} PROPERTIES LINK_FLAGS "-Wl,--no-as-needed") + endif() + endif() +endfunction() diff --git a/Coverage.cmake b/CommonCoverage.cmake similarity index 94% rename from Coverage.cmake rename to CommonCoverage.cmake index eacfa55..f475541 100644 --- a/Coverage.cmake +++ b/CommonCoverage.cmake @@ -3,8 +3,8 @@ # - provides a function to add 'coverage' targets # # CMake options: -# ENABLE_COVERAGE Must be explicitly enabled by the user since adding code -# coverage compiler flags may break downstream projects. +# COMMON_ENABLE_COVERAGE Must be explicitly enabled by the user since adding +# code coverage compiler flags may break downstream projects. # # Input variables: # * LCOV_EXCLUDE Extra files to exclude from the coverage report @@ -20,9 +20,9 @@ # * ${PROJECT_NAME}-coverage generate a coverage report for a specific project # * coverage run all ${PROJECT_NAME}-coverage -option(ENABLE_COVERAGE "Enable code coverage testing" OFF) +option(COMMON_ENABLE_COVERAGE "Enable code coverage testing" OFF) -if(ENABLE_COVERAGE) +if(COMMON_ENABLE_COVERAGE) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG) find_program(GENHTML genhtml) find_program(LCOV lcov) diff --git a/CommonDocumentation.cmake b/CommonDocumentation.cmake deleted file mode 100644 index 5b7c8d6..0000000 --- a/CommonDocumentation.cmake +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2012-2014 Raphael Dumusc - -# Configure the build for a documentation project: -# common_documentation() -# -# Generates: -# * doxygit target -# * install target (optional) -# -# The doxygit target executes Doxygit.cmake as a script in the source -# directory of the project. It updates the index page, removes outdated -# documentation folders and 'git add' the changes. -# -# Input (optional): -# * DOXYGIT_GENERATE_INDEX generate an index.html page (default: OFF) -# * DOXYGIT_MAX_VERSIONS number of versions to keep in directory (default: 10) -# * DOXYGIT_TOC_POST html content to insert in 'index.html' (default: '') -# -# * COMMON_INSTALL_DOCUMENTATION if set to ON, generate a 'make install' target -# which installs all the documentation under share/${PROJECT_NAME}/. -# Default: OFF because it is called by each dependant project when doing a -# regular release build using Buildyard, which can be very time consuming. - -function(COMMON_DOCUMENTATION) - add_custom_command(OUTPUT ${PROJECT_NAME}-index-generated - COMMAND ${CMAKE_COMMAND} - -DPROJECT_NAME="${PROJECT_NAME}" - -DDOXYGIT_GENERATE_INDEX="${DOXYGIT_GENERATE_INDEX}" - -DDOXYGIT_TOC_POST:STRING="${DOXYGIT_TOC_POST}" - -DDOXYGIT_MAX_VERSIONS="${DOXYGIT_MAX_VERSIONS}" - -DDOXYGIT_STATE_FILE="${PROJECT_BINARY_DIR}/doxygit-generated" - -P "${CMAKE_SOURCE_DIR}/CMake/common/Doxygit.cmake" - COMMENT "Updating ${PROJECT_NAME} pages in ${PROJECT_SOURCE_DIR}" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}") - add_custom_target(${PROJECT_NAME}-doxygit ALL - DEPENDS ${PROJECT_NAME}-index-generated) - set_property(GLOBAL APPEND PROPERTY - ${PROJECT_NAME}_ALL_DEP_TARGETS ${PROJECT_NAME}-doxygit) - - # For meta project, separate doxygit and ${PROJECT_NAME}-doxygit - if(NOT TARGET doxygit) - add_custom_target(doxygit ALL) - endif() - add_dependencies(doxygit ${PROJECT_NAME}-doxygit) - - if(COMMON_INSTALL_DOCUMENTATION) - file(GLOB Folders RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *-*) - - foreach(FOLDER ${Folders}) - install(DIRECTORY ${FOLDER} DESTINATION share/${PROJECT_NAME} - CONFIGURATIONS Release) - endforeach() - # need at least one file for 'make install' - install(FILES index.html DESTINATION share/${PROJECT_NAME} - CONFIGURATIONS Release) - else() - # Buildyard expects an install target for all projects - install(CODE "MESSAGE(\"Nothing to install, done.\")") - endif() -endfunction() diff --git a/CommonPackage.cmake b/CommonFindPackage.cmake similarity index 84% rename from CommonPackage.cmake rename to CommonFindPackage.cmake index 2e26c4b..43210dc 100644 --- a/CommonPackage.cmake +++ b/CommonFindPackage.cmake @@ -1,34 +1,34 @@ # Copyright (c) 2014-2015 Stefan.Eilemann@epfl.ch # Daniel.Nachbaur@epfl.ch -# Provides common_package(Package_Name args) and common_package_post() which -# improves find_package. +# Provides common_find_package(Package_Name args) and common_find_package_post() +# which improves find_package. # -# common_package() -# - QUIET if COMMON_PACKAGE_USE_QUIET option is set +# common_find_package() +# - QUIET if COMMON_FIND_PACKAGE_QUIET option is set # - -isystem if SYSTEM argument is passed; for convenience, Boost is always # SYSTEM # - first tries find_package with all the given arguments, and then falls back # to using pkg_config if available (no component support for pkg_config though) # - processes ${PROJECT_SOURCE_DIR}/CMake/FindPackagesPost.cmake to tweak result -# of common_package_post() +# of common_find_package_post() # - sets include_directories() and link_directories() accordingly # -# common_package_disable() +# common_find_package_disable() # Disables the previous found package(s) # -# common_package_post() +# common_find_package_post() # - generates defines.h and options.cmake for found packages. # - prints status message of found and not-found packages # # Input variables # - CMAKE_INSTALL_PREFIX - install prefix, comes from Common.cmake -# - CMAKE_MODULE_INSTALL_PATH - module install prefix, comes from CMakeInstallPath.cmake +# - CMAKE_MODULE_INSTALL_PATH - module install prefix, comes from Common.cmake # - UPPER_PROJECT_NAME - upper-case project name, comes from Common.cmake # # Output variables -# - COMMON_PACKAGE_DEFINES - accumulated defines of found packages for -# options.cmake and defines.h, written by common_package_post() +# - COMMON_FIND_PACKAGE_DEFINES - accumulated defines of found packages for +# options.cmake and defines.h, written by common_find_package_post() # - ${PROJECT_NAME}_FIND_PACKAGES_FOUND - string of found packages # - ${PROJECT_NAME}_FIND_PACKAGES_NOTFOUND - string of not-found packages @@ -38,17 +38,24 @@ endif() set(ENV{PKG_CONFIG_PATH} "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") -option(COMMON_PACKAGE_USE_QUIET "Use QUIET for common_package command" ON) +option(COMMON_FIND_PACKAGE_QUIET "Use QUIET for common_find_package command" ON) -include(System) include(CommonGraph) if(COMMON_USE_CXX03) - set(COMMON_PACKAGE_DEFINES ${SYSTEM} COMMON_USE_CXX03) + set(COMMON_FIND_PACKAGE_DEFINES ${SYSTEM} ${UPPER_PROJECT_NAME}_USE_CXX03) else() - set(COMMON_PACKAGE_DEFINES ${SYSTEM} COMMON_USE_CXX11) + set(COMMON_FIND_PACKAGE_DEFINES ${SYSTEM} ${UPPER_PROJECT_NAME}_USE_CXX11) endif() -macro(common_package Package_Name) +include(TestBigEndian) +test_big_endian(BIGENDIAN) +if(BIGENDIAN) + set(COMMON_FIND_PACKAGE_DEFINES ${SYSTEM} ${UPPER_PROJECT_NAME}_BIGENDIAN) +else() + set(COMMON_FIND_PACKAGE_DEFINES ${SYSTEM} ${UPPER_PROJECT_NAME}_LITTLEENDIAN) +endif() + +macro(common_find_package Package_Name) string(TOUPPER ${Package_Name} PACKAGE_NAME) set(__args ${ARGN}) # ARGN is not a list. make one. @@ -75,7 +82,7 @@ macro(common_package Package_Name) # QUIET either via as global option or as argument set(__find_quiet) - if(COMMON_PACKAGE_USE_QUIET) + if(COMMON_FIND_PACKAGE_QUIET) set(__find_quiet "QUIET") else() list(FIND __args "QUIET" __quiet_pos) @@ -109,10 +116,6 @@ macro(common_package Package_Name) common_graph_dep(${PROJECT_NAME} ${Package_Name} TRUE FALSE) endif() - if(EXISTS ${PROJECT_SOURCE_DIR}/CMake/FindPackagesPost.cmake) - include(${PROJECT_SOURCE_DIR}/CMake/FindPackagesPost.cmake) - endif() - if(${PACKAGE_NAME}_FOUND) set(${Package_Name}_name ${PACKAGE_NAME}) set(${Package_Name}_FOUND TRUE) @@ -120,12 +123,12 @@ macro(common_package Package_Name) set(${Package_Name}_name ${Package_Name}) set(${PACKAGE_NAME}_FOUND TRUE) else() - # for common_package_post() + # for common_find_package_post() set(${PROJECT_NAME}_FIND_PACKAGES_NOTFOUND "${${PROJECT_NAME}_FIND_PACKAGES_NOTFOUND} ${Package_Name}") endif() if(${Package_Name}_name) - # for common_package_post() + # for common_find_package_post() set(${PROJECT_NAME}_FIND_PACKAGES_FOUND "${${PROJECT_NAME}_FIND_PACKAGES_FOUND} ${Package_Name}") @@ -133,7 +136,7 @@ macro(common_package Package_Name) set(__use_package_define "${UPPER_PROJECT_NAME}_USE_${PACKAGE_NAME}") string(REPLACE "-" "_" __use_package_define ${__use_package_define}) string(REPLACE "+" "P" __use_package_define ${__use_package_define}) - list(APPEND COMMON_PACKAGE_DEFINES ${__use_package_define}) + list(APPEND COMMON_FIND_PACKAGE_DEFINES ${__use_package_define}) # for CommonPackageConfig.cmake if(NOT COMMON_LIBRARY_TYPE MATCHES "SHARED") @@ -165,7 +168,7 @@ macro(common_package Package_Name) endif() endmacro() -macro(common_package_disable) +macro(common_find_package_disable) set(__args ${ARGN}) # ARGN is not a list. make one. foreach(Package_Name ${__args}) string(TOUPPER ${Package_Name} PACKAGE_NAME) @@ -174,7 +177,7 @@ macro(common_package_disable) set(${PACKAGE_NAME}_FOUND) set(__use_package_define "${UPPER_PROJECT_NAME}_USE_${PACKAGE_NAME}") string(REGEX REPLACE "-" "_" __use_package_define ${__use_package_define}) - list(REMOVE_ITEM COMMON_PACKAGE_DEFINES ${__use_package_define}) + list(REMOVE_ITEM COMMON_FIND_PACKAGE_DEFINES ${__use_package_define}) string(REPLACE " ${Package_Name}" "" ${PROJECT_NAME}_FIND_PACKAGES_FOUND "${${PROJECT_NAME}_FIND_PACKAGES_FOUND}") set(${PROJECT_NAME}_FIND_PACKAGES_NOTFOUND @@ -182,7 +185,7 @@ macro(common_package_disable) endforeach() endmacro() -macro(common_package_post) +macro(common_find_package_post) # Write defines.h and options.cmake if(NOT PROJECT_INCLUDE_NAME) message(FATAL_ERROR "PROJECT_INCLUDE_NAME not set, old or missing Common.cmake?") @@ -192,20 +195,20 @@ macro(common_package_post) endif() configure_file(${CMAKE_SOURCE_DIR}/CMake/common/cpp/defines.h - ${OUTPUT_INCLUDE_DIR}/${PROJECT_INCLUDE_NAME}/defines.h @ONLY) + ${PROJECT_BINARY_DIR}/include/${PROJECT_INCLUDE_NAME}/defines.h @ONLY) set(__defines_file "${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_INCLUDE_NAME}/defines${SYSTEM}.h") set(COMMON_DEFINES_FILE - ${OUTPUT_INCLUDE_DIR}/${PROJECT_INCLUDE_NAME}/defines.h ${__defines_file}) + ${PROJECT_BINARY_DIR}/include/${PROJECT_INCLUDE_NAME}/defines.h ${__defines_file}) set(__defines_file_in ${__defines_file}.in) set(__options_cmake_file_in ${__options_cmake_file}.in) file(WRITE ${__defines_file_in} - "// generated by CommonPackage.cmake, do not edit.\n\n" + "// generated by CommonFindPackage.cmake, do not edit.\n\n" "#ifndef ${PROJECT_NAME}_DEFINES_${SYSTEM}_H\n" "#define ${PROJECT_NAME}_DEFINES_${SYSTEM}_H\n\n") file(WRITE ${__options_cmake_file_in} "# Optional modules enabled during build\n") - foreach(DEF ${COMMON_PACKAGE_DEFINES}) + foreach(DEF ${COMMON_FIND_PACKAGE_DEFINES}) add_definitions(-D${DEF}=1) file(APPEND ${__defines_file_in} "#ifndef ${DEF}\n" @@ -235,10 +238,6 @@ macro(common_package_post) set(Boost_VERSION ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}) endif() - if(CUDA_FOUND) - string(REPLACE "-std=c++11" "" CUDA_HOST_FLAGS "${CUDA_HOST_FLAGS}") - string(REPLACE "-std=c++0x" "" CUDA_HOST_FLAGS "${CUDA_HOST_FLAGS}") - endif() if(OPENMP_FOUND) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") diff --git a/CommonGraph.cmake b/CommonGraph.cmake index 7e0c9a6..0f8fbf9 100644 --- a/CommonGraph.cmake +++ b/CommonGraph.cmake @@ -1,5 +1,5 @@ # Provides functions to generate dependency graph images using graphviz. -# Used by common_package. +# Used by common_find_package. # common_graph_dep(): Write a dependency from->to into global properties # common_graph(): Write .dot from the global properties and add Name-graph rule @@ -68,7 +68,7 @@ function(common_graph Name) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${Name}_tred.dot COMMAND ${TRED_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/${Name}.dot > ${CMAKE_CURRENT_BINARY_DIR}/${Name}_tred.dot - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${Name}.dot) + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${Name}.dot) add_custom_command(OUTPUT ${dest}/${Name}.png COMMAND ${CMAKE_COMMAND} -E make_directory ${dest} COMMAND ${DOT_EXECUTABLE} -o ${dest}/${Name}.png -Tpng ${CMAKE_CURRENT_BINARY_DIR}/${Name}_tred.dot diff --git a/CommonLibrary.cmake b/CommonLibrary.cmake index 54ba60c..a0c330c 100644 --- a/CommonLibrary.cmake +++ b/CommonLibrary.cmake @@ -21,13 +21,8 @@ # * NAME_OMIT_CHECK_TARGETS do not create cppcheck targets # * NAME_OMIT_EXPORT do not export target in CommonPackageConfig.cmake # * NAME_OMIT_INSTALL do not install, for example a library for unit tests -# * VERSION for the API version -# * VERSION_ABI for the ABI version -# * Optional Qt support: -# ** NAME_MOC_HEADERS list of internal moc input headers -# ** NAME_MOC_PUBLIC_HEADERS list of public moc input headers, to be installed -# ** NAME_UI_FORMS list of all .ui input files -# ** NAME_RESOURCES list of all .qrc resource files +# * ${PROJECT_NAME}_VERSION for the API version +# * ${PROJECT_NAME}_VERSION_ABI for the ABI version # # If NAME_LIBRARY_TYPE is a list, libraries are built of each specified # (i.e. shared and static) type. Whichever is first becomes the library @@ -43,26 +38,13 @@ # include(CommonCheckTargets) -include(CommonQtSupport) include(InstallFiles) set(COMMON_LIBRARY_TYPE SHARED CACHE STRING "Library type {any combination of SHARED, STATIC}") set_property(CACHE COMMON_LIBRARY_TYPE PROPERTY STRINGS SHARED STATIC) - -# applying CMAKE_C(XX)_FLAGS to add_library only works from parent scope, hence -# the macro calling the function _common_library -macro(common_library Name) - common_compiler_flags() - _common_library(${Name} ${ARGN}) -endmacro() - -#------------------------------------------------------------------------------- -# Implementation -#------------------------------------------------------------------------------- - -function(_common_library Name) +function(common_library Name) string(TOUPPER ${Name} NAME) set(INCLUDE_NAME ${${NAME}_INCLUDE_NAME}) @@ -77,20 +59,21 @@ function(_common_library Name) string(TOUPPER ${namespace} NAMESPACE) set(SOURCES ${${NAME}_SOURCES}) - set(HEADERS ${${NAME}_HEADERS} ${${NAME}_MOC_HEADERS}) - set(PUBLIC_HEADERS ${${NAME}_PUBLIC_HEADERS} ${${NAME}_MOC_PUBLIC_HEADERS}) + set(HEADERS ${${NAME}_HEADERS}) + set(PUBLIC_HEADERS ${${NAME}_PUBLIC_HEADERS}) set(LINK_LIBRARIES ${${NAME}_LINK_LIBRARIES}) # Generate api.h and version.h/cpp for non-interface libraries if(${NAME}_SOURCES) + set(PROJECT_VERSION_ABI ${${PROJECT_NAME}_VERSION_ABI}) configure_file(${CMAKE_SOURCE_DIR}/CMake/common/cpp/api.h - ${OUTPUT_INCLUDE_DIR}/${INCLUDE_NAME}/api.h @ONLY) + ${PROJECT_BINARY_DIR}/include/${INCLUDE_NAME}/api.h @ONLY) configure_file(${CMAKE_SOURCE_DIR}/CMake/common/cpp/version.h - ${OUTPUT_INCLUDE_DIR}/${INCLUDE_NAME}/version.h @ONLY) + ${PROJECT_BINARY_DIR}/include/${INCLUDE_NAME}/version.h @ONLY) configure_file(${CMAKE_SOURCE_DIR}/CMake/common/cpp/version.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.cpp @ONLY) - # Exclude this file for coverage report in Coverage.cmake + # Exclude this file for coverage report in CommonCoverage.cmake set_property(GLOBAL APPEND PROPERTY COMMON_GENERATED_FILES ${CMAKE_CURRENT_BINARY_DIR}/version.cpp) @@ -99,8 +82,8 @@ function(_common_library Name) -D${NAME}_STATIC= -D${NAMESPACE}_API=) list(APPEND PUBLIC_HEADERS - ${OUTPUT_INCLUDE_DIR}/${INCLUDE_NAME}/api.h - ${OUTPUT_INCLUDE_DIR}/${INCLUDE_NAME}/version.h) + ${PROJECT_BINARY_DIR}/include/${INCLUDE_NAME}/api.h + ${PROJECT_BINARY_DIR}/include/${INCLUDE_NAME}/version.h) list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/version.cpp) endif() @@ -108,12 +91,9 @@ function(_common_library Name) generate_library_header(${NAME}) endif() - # from CommonPackage.cmake + # from CommonFindPackage.cmake list(APPEND PUBLIC_HEADERS ${COMMON_DEFINES_FILE}) - common_qt_support(${NAME}) - list(APPEND SOURCES ${COMMON_QT_SUPPORT_SOURCES}) - if(SOURCES) list(SORT SOURCES) endif() @@ -124,6 +104,7 @@ function(_common_library Name) list(SORT PUBLIC_HEADERS) endif() + source_group(\\ FILES CMakeLists.txt) source_group(${INCLUDE_NAME} FILES ${SOURCES} ${HEADERS} ${PUBLIC_HEADERS}) if(NOT ${NAME}_LIBRARY_TYPE) @@ -139,15 +120,7 @@ function(_common_library Name) endif() if(NOT ${NAME}_SOURCES) - if(CMAKE_MAJOR_VERSION GREATER 2) - add_library(${LibName} INTERFACE) - else() - add_library(${LibName} ${PUBLIC_HEADERS} - ${CMAKE_SOURCE_DIR}/CMake/common/cpp/dummy.cpp) - set_target_properties(${LibName} PROPERTIES - LINKER_LANGUAGE CXX FOLDER ${PROJECT_NAME}) - endif() - + add_library(${LibName} INTERFACE) _target_include_directories(INTERFACE) else() # append a debug suffix to library name on windows or if user requests it @@ -155,7 +128,7 @@ function(_common_library Name) add_library(${LibName} ${LIBRARY_TYPE} ${SOURCES} ${HEADERS} ${PUBLIC_HEADERS}) set_target_properties(${LibName} PROPERTIES - VERSION ${VERSION} SOVERSION ${VERSION_ABI} + VERSION ${${PROJECT_NAME}_VERSION} SOVERSION ${${PROJECT_NAME}_VERSION_ABI} OUTPUT_NAME ${Name} FOLDER ${PROJECT_NAME}) target_link_libraries(${LibName} ${LINK_LIBRARIES}) @@ -168,6 +141,8 @@ function(_common_library Name) common_enable_dlopen_usage(${LibName}) endif() + common_compile_options(${LibName}) + # for DoxygenRule.cmake and SubProject.cmake set_property(GLOBAL APPEND PROPERTY ${PROJECT_NAME}_ALL_DEP_TARGETS ${LibName}) @@ -183,16 +158,16 @@ function(_common_library Name) # CommonPackageConfig.cmake if(${NAME}_OMIT_EXPORT) install(TARGETS ${LibName} - ARCHIVE DESTINATION ${LIBRARY_DIR} COMPONENT dev + ARCHIVE DESTINATION lib COMPONENT dev RUNTIME DESTINATION bin COMPONENT lib - LIBRARY DESTINATION ${LIBRARY_DIR} COMPONENT lib + LIBRARY DESTINATION lib COMPONENT lib INCLUDES DESTINATION include) else() install(TARGETS ${LibName} EXPORT ${PROJECT_NAME}Targets - ARCHIVE DESTINATION ${LIBRARY_DIR} COMPONENT dev + ARCHIVE DESTINATION lib COMPONENT dev RUNTIME DESTINATION bin COMPONENT lib - LIBRARY DESTINATION ${LIBRARY_DIR} COMPONENT lib + LIBRARY DESTINATION lib COMPONENT lib INCLUDES DESTINATION include) endif() endif() @@ -208,14 +183,14 @@ function(_common_library Name) # install(TARGETS ... PUBLIC_HEADER ...) flattens directories install_files(include/${INCLUDE_NAME} FILES ${PUBLIC_HEADERS} - COMPONENT dev BASE ${OUTPUT_INCLUDE_DIR}/${INCLUDE_NAME}) + COMPONENT dev BASE ${PROJECT_BINARY_DIR}/include/${INCLUDE_NAME}) endif() endfunction() macro(generate_library_header NAME) get_filename_component(__base_name ${INCLUDE_NAME} NAME) - set(__generated_header ${OUTPUT_INCLUDE_DIR}/${INCLUDE_NAME}/${__base_name}.h) + set(__generated_header ${PROJECT_BINARY_DIR}/include/${INCLUDE_NAME}/${__base_name}.h) set(__generated_header_in ${__generated_header}.in) file(WRITE ${__generated_header_in} @@ -259,9 +234,9 @@ function(common_enable_dlopen_usage Target) set(_DSOName ${CMAKE_SHARED_LIBRARY_PREFIX}${Target}${CMAKE_SHARED_LIBRARY_SUFFIX}) else() if(APPLE) - set(_DSOName ${CMAKE_SHARED_LIBRARY_PREFIX}${Target}.${VERSION_ABI}${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(_DSOName ${CMAKE_SHARED_LIBRARY_PREFIX}${Target}.${${PROJECT_NAME}_VERSION_ABI}${CMAKE_SHARED_LIBRARY_SUFFIX}) else() - set(_DSOName ${CMAKE_SHARED_LIBRARY_PREFIX}${Target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${VERSION_ABI}) + set(_DSOName ${CMAKE_SHARED_LIBRARY_PREFIX}${Target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${${PROJECT_NAME}_VERSION_ABI}) endif() endif() string(TOUPPER ${Target} TARGET) @@ -278,7 +253,7 @@ macro(_target_include_directories _type) target_include_directories( ${LibName} ${_type} "$" - "$" + "$" "$" ) if(${NAME}_PUBLIC_INCLUDE_DIRECTORIES) diff --git a/CommonPackageConfig.cmake b/CommonPackageConfig.cmake index 084e89d..6b757c6 100644 --- a/CommonPackageConfig.cmake +++ b/CommonPackageConfig.cmake @@ -4,11 +4,7 @@ # ${PROJECT_NAME}Targets.cmake like CMake suggests to create a 'package' that # can be found by downstream projects, either from the build tree (subproject) # or from the install tree (package/module). -# http://www.cmake.org/cmake/help/v3.2/manual/cmake-packages.7.html#creating-packages -# -# Note that the install tree export target set creation is only supported if -# CMake 3 is used. On the other hand, a CMake 3 generated install tree can be -# consumed either by CMake 2 or 3. +# http://www.cmake.org/cmake/help/v3.1/manual/cmake-packages.7.html#creating-packages # # Uses: # * ${UPPER_PROJECT_NAME}_DEPENDENT_LIBRARIES - list of 'leaking'/public @@ -25,22 +21,16 @@ write_basic_package_version_file( VERSION ${VERSION} COMPATIBILITY SameMajorVersion ) -# Add find_package/find_dependency (CMake2/3) calls for leaking dependent -# libraries to ${PROJECT_NAME}Config.cmake +# Add find_dependency calls for leaking dependent libraries to +# ${PROJECT_NAME}Config.cmake if(${UPPER_PROJECT_NAME}_DEPENDENT_LIBRARIES) set(DEPENDENT_LIBRARIES " # find dependent libraries which provide dependent targets\n" - " if(CMAKE_MAJOR_VERSION GREATER 2)\n" - " include(CMakeFindDependencyMacro)\n") + " include(CMakeFindDependencyMacro)\n") foreach(_dependent ${${UPPER_PROJECT_NAME}_DEPENDENT_LIBRARIES}) - list(APPEND DEPENDENT_LIBRARIES " find_dependency(${_dependent})\n") - endforeach() - list(APPEND DEPENDENT_LIBRARIES " else()\n") - foreach(_dependent ${${UPPER_PROJECT_NAME}_DEPENDENT_LIBRARIES}) - list(APPEND DEPENDENT_LIBRARIES " find_package(${_dependent} QUIET)\n") + list(APPEND DEPENDENT_LIBRARIES " find_dependency(${_dependent})\n") endforeach() - list(APPEND DEPENDENT_LIBRARIES " endif()\n") string(REGEX REPLACE ";" " " DEPENDENT_LIBRARIES ${DEPENDENT_LIBRARIES}) endif() @@ -58,8 +48,7 @@ install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION ${CMAKE_MODULE_INSTALL_PATH} ) -# No export(EXPORT) in CMake 2 or if common_library has not been used. -if(CMAKE_MAJOR_VERSION LESS 3 OR NOT TARGET ${PROJECT_NAME}_ALIAS) +if(NOT TARGET ${PROJECT_NAME}_ALIAS) return() endif() diff --git a/CommonQtSupport.cmake b/CommonQtSupport.cmake deleted file mode 100644 index c13340c..0000000 --- a/CommonQtSupport.cmake +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) 2015 raphael.dumusc@epfl.ch - -# Provides Qt support for CommonLibrary and CommonApplication: -# common_qt_support() -# -# Uses: -# * NAME_MOC_HEADERS, NAME_MOC_PUBLIC_HEADERS list of all moc input headers -# * NAME_UI_FORMS list of all .ui input files -# * NAME_RESOURCES list of all .qrc resource files -# * Sets the output to the following variables in parent scope: -# * COMMON_QT_SUPPORT_SOURCES - -macro(COMMON_QT_SUPPORT NAME) - set(COMMON_QT_SUPPORT_SOURCES "") - if(${NAME}_MOC_HEADERS) - if(NOT Qt5Core_FOUND) - message(FATAL_ERROR "Qt5Core not found, needed for MOC of application ${Name}") - endif() - qt5_wrap_cpp(MOC_SOURCES ${${NAME}_MOC_HEADERS}) - list(APPEND COMMON_QT_SUPPORT_SOURCES ${MOC_SOURCES}) - endif() - if(${NAME}_MOC_PUBLIC_HEADERS) - if(NOT Qt5Core_FOUND) - message(FATAL_ERROR "Qt5Core not found, needed for MOC of application ${Name}") - endif() - qt5_wrap_cpp(MOC_SOURCES ${${NAME}_MOC_PUBLIC_HEADERS}) - list(APPEND COMMON_QT_SUPPORT_SOURCES ${MOC_SOURCES}) - endif() - if(${NAME}_UI_FORMS) - if(NOT Qt5Widgets_FOUND) - message(FATAL_ERROR "Qt5Widgets not found, needed for UIC of application ${Name}") - endif() - qt5_wrap_ui(UI_SOURCES ${${NAME}_UI_FORMS}) - list(APPEND COMMON_QT_SUPPORT_SOURCES ${UI_SOURCES}) - include_directories(${PROJECT_BINARY_DIR}) - endif() - if(${NAME}_RESOURCES) - if(NOT Qt5Core_FOUND) - message(FATAL_ERROR "Qt5Core not found, needed for QRC of application ${Name}") - endif() - qt5_add_resources(QRC_SOURCES ${${NAME}_RESOURCES}) - list(APPEND COMMON_QT_SUPPORT_SOURCES ${QRC_SOURCES}) - endif() - set(COMMON_QT_SUPPORT_SOURCES ${COMMON_QT_SUPPORT_SOURCES} PARENT_SCOPE) -endmacro() diff --git a/Compiler.cmake b/Compiler.cmake deleted file mode 100644 index 8f45d9a..0000000 --- a/Compiler.cmake +++ /dev/null @@ -1,164 +0,0 @@ -# Copyright (c) 2012-2014 Fabien Delalondre -# Stefan.Eilemann@epfl.ch -# -# Sets compiler optimization, definition and warnings according to -# chosen compiler. Supported compilers are XL, Intel, Clang, gcc (4.4 -# or later) and Visual Studio (2008 or later). -# -# This defines the common_compiler_flags() macro to set -# CMAKE_C[XX]_FLAGS[_CMAKE_BUILD_TYPE] flags accordingly. -# -# Input Variables -# * COMMON_MINIMUM_GCC_VERSION check for a minimum gcc version, default 4.4 -# * COMMON_USE_CXX03 When set, do not enable C++11 language features -# -# Output Variables -# * GCC_COMPILER_VERSION The compiler version if gcc is used -# * COMMON_C_FLAGS The common flags for C compiler -# * COMMON_C_FLAGS_DEBUG The common flags for C compiler in Debug build -# * COMMON_C_FLAGS_RELWITHDEBINFO The common flags for C compiler in RelWithDebInfo build -# * COMMON_C_FLAGS_RELEASE The common flags for C compiler in Release build -# * COMMON_CXX_FLAGS The common flags for C++ compiler -# * COMMON_CXX_FLAGS_DEBUG The common flags for C++ compiler in Debug build -# * COMMON_CXX_FLAGS_RELWITHDEBINFO The common flags for C++ compiler in RelWithDebInfo build -# * COMMON_CXX_FLAGS_RELEASE The common flags for C++ compiler in Release build - -# OPT: necessary only once, included by Common.cmake -if(COMPILER_DONE) - return() -endif() -set(COMPILER_DONE ON) - -include(${CMAKE_CURRENT_LIST_DIR}/CompilerIdentification.cmake) - -option(ENABLE_WARN_DEPRECATED "Enable deprecation warnings" ON) -option(ENABLE_CXX11_STDLIB "Enable C++11 stdlib" OFF) - -if(ENABLE_WARN_DEPRECATED) - add_definitions(-DWARN_DEPRECATED) # projects have to pick this one up -endif() - -if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG) - if(NOT COMMON_MINIMUM_GCC_VERSION) - set(COMMON_MINIMUM_GCC_VERSION 4.4) - endif() - - set(COMMON_C_FLAGS - "-Wall -Wextra -Winvalid-pch -Winit-self -Wno-unknown-pragmas") - - if(NOT WIN32 AND NOT XCODE_VERSION) - set(COMMON_C_FLAGS "${COMMON_C_FLAGS} -Werror") - endif() - - if(GCC_COMPILER_VERSION VERSION_GREATER 4.1) - set(COMMON_C_FLAGS "${COMMON_C_FLAGS} -Wshadow") - endif() - - if(CMAKE_COMPILER_IS_CLANG) - set(COMMON_C_FLAGS - "${COMMON_C_FLAGS} -Qunused-arguments -ferror-limit=5 -ftemplate-depth-1024 -Wheader-hygiene") - set(COMMON_CXX11_STDLIB "-stdlib=libc++") - else() - if(GCC_COMPILER_VERSION VERSION_LESS COMMON_MINIMUM_GCC_VERSION) - message(FATAL_ERROR "Using gcc ${GCC_COMPILER_VERSION}, need at least ${COMMON_MINIMUM_GCC_VERSION}") - endif() - if(GCC_COMPILER_VERSION VERSION_GREATER 4.5) - set(COMMON_C_FLAGS "${COMMON_C_FLAGS} -fmax-errors=5") - endif() - endif() - - set(COMMON_CXX_FLAGS "-Wnon-virtual-dtor -Wsign-promo -Wvla -fno-strict-aliasing") - set(COMMON_CXX_FLAGS_RELEASE "${COMMON_CXX_FLAGS_RELEASE} -Wuninitialized") - - if(APPLE AND OSX_VERSION VERSION_LESS 10.9) - # use C++03 std and stdlib, which is the default used by all - # software, including all MacPorts. - elseif(NOT COMMON_USE_CXX03) - set(COMMON_CXXSTD_FLAGS ${CXX_DIALECT_11}) - if(CMAKE_COMPILER_IS_GNUCXX_PURE AND GCC_COMPILER_VERSION VERSION_LESS 4.8) - # http://stackoverflow.com/questions/4438084 - add_definitions(-D_GLIBCXX_USE_NANOSLEEP) - endif() - endif() - -elseif(CMAKE_COMPILER_IS_INTEL) - set(COMMON_C_FLAGS - "-Wall -Wextra -Winvalid-pch -Winit-self -Wno-unknown-pragmas") - set(COMMON_CXX_FLAGS - "-Wno-deprecated -Wno-unknown-pragmas -Wshadow -fno-strict-aliasing -Wuninitialized -Wsign-promo -Wnon-virtual-dtor") - - # Release: automatically generate instructions for the highest - # supported compilation host - set(COMMON_C_FLAGS_RELEASE "${COMMON_C_FLAGS_RELEASE} -xhost") - set(COMMON_CXX_FLAGS_RELEASE "${COMMON_CXX_FLAGS_RELEASE} -xhost") - - if(NOT COMMON_USE_CXX03) - set(COMMON_CXXSTD_FLAGS ${CXX_DIALECT_11}) - endif() - -elseif(CMAKE_COMPILER_IS_XLCXX) - # default: Maintain code semantics Fix to link dynamically. On the - # next pass should add an if statement: 'if shared ...'. Overriding - # default release flags since the default were '-O -NDEBUG'. By - # default, set flags for backend since this is the most common use - # case - option(XLC_BACKEND "Compile for BlueGene compute nodes using XLC compilers" - ON) - if(XLC_BACKEND) - set(COMMON_CXX_FLAGS_RELEASE - "-O3 -qtune=qp -qarch=qp -q64 -qstrict -qnohot -qnostaticlink -DNDEBUG") - set(COMMON_C_FLAGS_RELEASE ${COMMON_CXX_FLAGS_RELEASE}) - set(COMMON_LIBRARY_TYPE STATIC) - set(COMPILE_LIBRARY_TYPE STATIC) - else() - set(COMMON_CXX_FLAGS_RELEASE - "-O3 -q64 -qstrict -qnostaticlink -qnostaticlink=libgcc -DNDEBUG") - set(COMMON_C_FLAGS_RELEASE ${COMMON_CXX_FLAGS_RELEASE}) - endif() - - set(CMAKE_C_FLAGS_RELEASE ${COMMON_C_FLAGS_RELEASE}) - set(CMAKE_CXX_FLAGS_RELEASE ${COMMON_CXX_FLAGS_RELEASE}) - -endif() - -if(MSVC) - add_definitions( - /D_CRT_SECURE_NO_WARNINGS - /D_SCL_SECURE_NO_WARNINGS - /wd4068 # disable unknown pragma warnings - /wd4244 # conversion from X to Y, possible loss of data - /wd4800 # forcing value to bool 'true' or 'false' (performance warning) - /wd4351 # new behavior: elements of array 'array' will be default initialized - ) - - # By default, do not warn when built on machines using only VS Express - # http://cmake.org/gitweb?p=cmake.git;a=commit;h=fa4a3b04d0904a2e93242c0c3dd02a357d337f77 - if(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS) - set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON) - endif() - - # http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60015&start=0 - set(COMMON_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /Zm500 /EHsc /GR") - set(COMMON_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS_RELEASE} /WX") -endif() - -set(COMMON_C_FLAGS_RELWITHDEBINFO "${COMMON_C_FLAGS_RELWITHDEBINFO} -DNDEBUG") -set(COMMON_CXX_FLAGS_RELWITHDEBINFO "${COMMON_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG") - -set(COMMON_CXX_FLAGS "${COMMON_C_FLAGS} ${COMMON_CXX_FLAGS}") - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CXXSTD_FLAGS}") -if(ENABLE_CXX11_STDLIB) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CXX11_STDLIB}") -endif() - -macro(common_compiler_flags) - set(CMAKE_C_FLAGS "${COMMON_C_FLAGS} ${CMAKE_C_FLAGS}") - set(CMAKE_C_FLAGS_DEBUG "${COMMON_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}") - set(CMAKE_C_FLAGS_RELWITHDEBINFO "${COMMON_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_FLAGS_RELWITHDEBINFO}") - set(CMAKE_C_FLAGS_RELEASE "${COMMON_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}") - set(CMAKE_CXX_FLAGS "${COMMON_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${COMMON_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") - set(CMAKE_CXX_FLAGS_RELEASE "${COMMON_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}") -endmacro() diff --git a/CompilerIdentification.cmake b/CompilerIdentification.cmake deleted file mode 100644 index a0b04c3..0000000 --- a/CompilerIdentification.cmake +++ /dev/null @@ -1,81 +0,0 @@ -# Detects the compiler, and sets the following: -# CMAKE_COMPILER_IS_XLCXX for IBM XLC -# CMAKE_COMPILER_IS_INTEL for Intel C++ Compiler -# CMAKE_COMPILER_IS_CLANG for clang -# CMAKE_COMPILER_IS_GNUCXX_PURE for *real* gcc -# -# Also sets the following, so that the correct C dialect flags can be used -# * C_DIALECT_OPT_C89 Compiler flag to select C89 C dialect -# * C_DIALECT_OPT_C89EXT Compiler flag to select C89 C dialect with extensions -# * C_DIALECT_OPT_C99 Compiler flag to select C99 C dialect -# * C_DIALECT_OPT_C99EXT Compiler flag to select C99 C dialect with extensions -# -# COMMON_USE_CXX03 Set if the compiler only supports C++03 -# -# C++ dialect options are setup as follows: -# * CXX_DIALECT_PRE_11 Pre-C++11, note: this could be C++98 or C++03, largely -# because g++ aliases the two, and the other compilers -# don't allow one to distinguish -# * CXX_DIALECT_11 C++11 standard - -include(TestBigEndian) -test_big_endian(BIGENDIAN) - -if(BIGENDIAN) - add_definitions(-DCOMMON_BIGENDIAN) -else() - add_definitions(-DCOMMON_LITTLEENDIAN) -endif() - -# Compiler name -if(CMAKE_CXX_COMPILER_ID STREQUAL "XL") - set(CMAKE_COMPILER_IS_XLCXX ON) -elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") - set(CMAKE_COMPILER_IS_INTEL ON) -elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_COMPILER_IS_CLANG ON) -elseif(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_COMPILER_IS_GNUCXX_PURE ON) -endif() -# use MSVC for Visual Studio - -if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG) - include(${CMAKE_CURRENT_LIST_DIR}/CompilerVersion.cmake) - compiler_dumpversion(GCC_COMPILER_VERSION) - - set(CXX_DIALECT_PRE_11 "-std=c++98") - - set(CXX_DIALECT_11 "-std=c++11") - if(CMAKE_COMPILER_IS_GNUCXX_PURE AND GCC_COMPILER_VERSION VERSION_LESS 4.7) - set(CXX_DIALECT_11 "-std=c++0x") - endif() - - if(CMAKE_COMPILER_IS_GNUCXX_PURE AND GCC_COMPILER_VERSION VERSION_LESS 4.5) - set(COMMON_USE_CXX03 ON) - endif() - - set(C_DIALECT_OPT_C89 "-std=c89") - set(C_DIALECT_OPT_C99 "-std=c99") - set(C_DIALECT_OPT_C89EXT "-std=gnu89") - set(C_DIALECT_OPT_C99EXT "-std=gnu99") - -elseif(CMAKE_COMPILER_IS_INTEL) - set(CXX_DIALECT_11 "-std=c++11") - set(CXX_DIALECT_PRE_11 "-std=gnu++98") - - set(C_DIALECT_OPT_C89 "-std=c89") - set(C_DIALECT_OPT_C99 "-std=c99") - set(C_DIALECT_OPT_C89EXT "-std=gnu89") - set(C_DIALECT_OPT_C99EXT "-std=gnu99") - -elseif(CMAKE_COMPILER_IS_XLCXX) - #read up on the features with 'xlc++ -qhelp' - set(COMMON_USE_CXX03 ON) - set(CXX_DIALECT_PRE_11 "-qlanglvl=extended") #strict98, with some ... extra features - set(CXX_DIALECT_11 "-qlanglvl=extended0x") - - set(C_DIALECT_OPT_C89 "-qlanglvl=stdc89") - set(C_DIALECT_OPT_C99 "-qlanglvl=stdc99") - set(C_DIALECT_OPT_C89EXT "-qlanglvl=extc89") - set(C_DIALECT_OPT_C99EXT "-qlanglvl=extc99") -endif() diff --git a/CompilerVersion.cmake b/CompilerVersion.cmake deleted file mode 100644 index 4868d4c..0000000 --- a/CompilerVersion.cmake +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2011-2012 Stefan Eilemann - -function(COMPILER_DUMPVERSION OUTPUT_VERSION) - execute_process(COMMAND - ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion - OUTPUT_VARIABLE DUMP_COMPILER_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE - ) - string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1.\\2" - DUMP_COMPILER_VERSION "${DUMP_COMPILER_VERSION}") - - set(${OUTPUT_VERSION} ${DUMP_COMPILER_VERSION} PARENT_SCOPE) -endfunction() diff --git a/DoxygenRule.cmake b/DoxygenRule.cmake index 6bd5975..0646d4c 100644 --- a/DoxygenRule.cmake +++ b/DoxygenRule.cmake @@ -139,7 +139,7 @@ add_dependencies(doxygen ${PROJECT_NAME}-doxygen) make_directory(${PROJECT_BINARY_DIR}/doc/html) install(DIRECTORY ${PROJECT_BINARY_DIR}/doc/html - DESTINATION ${DOC_DIR}/API + DESTINATION ${COMMON_DOC_DIR}/API COMPONENT doc CONFIGURATIONS Release) set(README) diff --git a/FindVTune.cmake b/FindVTune.cmake index 6c0a72e..96cade9 100644 --- a/FindVTune.cmake +++ b/FindVTune.cmake @@ -4,10 +4,6 @@ # if not found, installs a dummy ittnotify.h to build_dir/include to eliminate # the need to protect the itt calls with ifdefs -if(CMAKE_VERSION VERSION_LESS 2.8.3) # WAR bug - get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) -endif() - find_program(VTUNE_EXECUTABLE amplxe-cl) if(NOT VTUNE_EXECUTABLE) set(VTUNE_FOUND) diff --git a/GitExternal.cmake b/GitExternal.cmake index 0b70be2..f530bee 100644 --- a/GitExternal.cmake +++ b/GitExternal.cmake @@ -33,7 +33,7 @@ # * rebase: Rebases all git externals, including sub projects # # Options (global) which control behaviour: -# GIT_EXTERNAL_VERBOSE +# COMMON_GIT_EXTERNAL_VERBOSE # This is a global option which has the same effect as the VERBOSE option, # with the difference that output information will be produced for all # external repos when set. @@ -56,7 +56,7 @@ if(NOT GIT_EXECUTABLE) endif() include(CMakeParseArguments) -option(GIT_EXTERNAL_VERBOSE "Print git commands as they are executed" OFF) +option(COMMON_GIT_EXTERNAL_VERBOSE "Print git commands as they are executed" OFF) if(NOT GITHUB_USER AND DEFINED ENV{GITHUB_USER}) set(GITHUB_USER $ENV{GITHUB_USER} CACHE STRING @@ -64,7 +64,7 @@ if(NOT GITHUB_USER AND DEFINED ENV{GITHUB_USER}) endif() macro(GIT_EXTERNAL_MESSAGE msg) - if(GIT_EXTERNAL_VERBOSE OR GIT_EXTERNAL_LOCAL_VERBOSE) + if(COMMON_GIT_EXTERNAL_VERBOSE) message(STATUS "${NAME}: ${msg}") endif() endmacro() diff --git a/InstallSymlink.cmake b/InstallSymlink.cmake deleted file mode 100644 index 175108f..0000000 --- a/InstallSymlink.cmake +++ /dev/null @@ -1,19 +0,0 @@ - -# Creates a FROM->TO symlink during installation -function(INSTALL_SYMLINK) - cmake_parse_arguments(THIS "" "" "FROM;TO;WORKING_DIRECTORY;COMPONENT" ${ARGN}) - if(MSVC) - install(CODE - "message(\"mklink /j \${THIS_TO} \${THIS_FROM}\") - execute_process(COMMAND mklink /j \${THIS_TO} \${THIS_FROM} - WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${THIS_WORKING_DIRECTORY})" - COMPONENT "${THIS_COMPONENT}") - else() - install(CODE - "execute_process(COMMAND rm -f ${THIS_TO} - WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${THIS_WORKING_DIRECTORY}) - execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${THIS_FROM} ${THIS_TO} - WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${THIS_WORKING_DIRECTORY})" - COMPONENT "${THIS_COMPONENT}") - endif() -endfunction() diff --git a/LibFindMacros.cmake b/LibFindMacros.cmake index 4b71b0c..9c096be 100644 --- a/LibFindMacros.cmake +++ b/LibFindMacros.cmake @@ -2,32 +2,27 @@ # used for the current package. For this to work, the first parameter must be the # prefix of the current package, then the prefix of the new package etc, which are # passed to find_package. -macro (libfind_package PREFIX) - set (LIBFIND_PACKAGE_ARGS ${ARGN}) - if (${PREFIX}_FIND_QUIETLY) - set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) - endif (${PREFIX}_FIND_QUIETLY) - if (${PREFIX}_FIND_REQUIRED) - set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) - endif (${PREFIX}_FIND_REQUIRED) +macro(libfind_package PREFIX) + set(LIBFIND_PACKAGE_ARGS ${ARGN}) + if(${PREFIX}_FIND_QUIETLY) + set(LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) + endif() + if(${PREFIX}_FIND_REQUIRED) + set(LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) + endif() find_package(${LIBFIND_PACKAGE_ARGS} QUIET) -endmacro (libfind_package) +endmacro() # CMake developers made the UsePkgConfig system deprecated in the same release (2.6) # where they added pkg_check_modules. Consequently I need to support both in my scripts # to avoid those deprecated warnings. Here's a helper that does just that. # Works identically to pkg_check_modules, except that no checks are needed prior to use. -macro (libfind_pkg_check_modules PREFIX PKGNAME) - if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) - include(UsePkgConfig) - pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) - else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) - find_package(PkgConfig QUIET) - if (PKG_CONFIG_FOUND) - pkg_check_modules(${PREFIX} ${PKGNAME} QUIET) - endif (PKG_CONFIG_FOUND) - endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) -endmacro (libfind_pkg_check_modules) +macro(libfind_pkg_check_modules PREFIX PKGNAME) + find_package(PkgConfig QUIET) + if (PKG_CONFIG_FOUND) + pkg_check_modules(${PREFIX} ${PKGNAME} QUIET) + endif() +endmacro() # Do the final processing once the paths have been detected. # If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain @@ -35,64 +30,64 @@ endmacro (libfind_pkg_check_modules) # Ditto for ${PREFIX}_PROCESS_LIBS and library files. # Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. # Also handles errors in case library detection was required, etc. -macro (libfind_process PREFIX) +macro(libfind_process PREFIX) # Skip processing if already processed during this run - if (NOT ${PREFIX}_FOUND) + if(NOT ${PREFIX}_FOUND) # Start with the assumption that the library was found - set (${PREFIX}_FOUND TRUE) + set(${PREFIX}_FOUND TRUE) # Process all includes and set _FOUND to false if any are missing - foreach (i ${${PREFIX}_PROCESS_INCLUDES}) - if (${i}) - set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) + foreach(i ${${PREFIX}_PROCESS_INCLUDES}) + if(${i}) + set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) mark_as_advanced(${i}) - else (${i}) - set (${PREFIX}_FOUND FALSE) - endif (${i}) - endforeach (i) + else() + set(${PREFIX}_FOUND FALSE) + endif() + endforeach() # Process all libraries and set _FOUND to false if any are missing - foreach (i ${${PREFIX}_PROCESS_LIBS}) - if (${i}) - set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) + foreach(i ${${PREFIX}_PROCESS_LIBS}) + if(${i}) + set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) mark_as_advanced(${i}) - else (${i}) - set (${PREFIX}_FOUND FALSE) - endif (${i}) - endforeach (i) + else() + set(${PREFIX}_FOUND FALSE) + endif() + endforeach() # Print message and/or exit on fatal error - if (${PREFIX}_FOUND) - if (NOT ${PREFIX}_FIND_QUIETLY) - message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION} in ${${PREFIX}_INCLUDE_DIRS};${${PREFIX}_LIBRARIES}") - endif (NOT ${PREFIX}_FIND_QUIETLY) - else (${PREFIX}_FOUND) - if (${PREFIX}_FIND_REQUIRED) - foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) + if(${PREFIX}_FOUND) + if(NOT ${PREFIX}_FIND_QUIETLY) + message(STATUS "Found ${PREFIX} ${${PREFIX}_VERSION} in ${${PREFIX}_INCLUDE_DIRS};${${PREFIX}_LIBRARIES}") + endif() + else() + if(${PREFIX}_FIND_REQUIRED) + foreach(i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) message("${i}=${${i}}") - endforeach (i) - message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") - endif (${PREFIX}_FIND_REQUIRED) - endif (${PREFIX}_FOUND) - endif (NOT ${PREFIX}_FOUND) -endmacro (libfind_process) + endforeach() + message(FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") + endif() + endif() + endif() +endmacro() macro(libfind_library PREFIX basename) set(TMP "") if(MSVC80) set(TMP -vc80) - endif(MSVC80) + endif() if(MSVC90) set(TMP -vc90) - endif(MSVC90) + endif() set(${PREFIX}_LIBNAMES ${basename}${TMP}) if(${ARGC} GREATER 2) set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) - endif(${ARGC} GREATER 2) + endif() find_library(${PREFIX}_LIBRARY NAMES ${${PREFIX}_LIBNAMES} PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} ) -endmacro(libfind_library) +endmacro() diff --git a/README.md b/README.md index 73dc5ea..3f4792f 100644 --- a/README.md +++ b/README.md @@ -26,16 +26,17 @@ The following CMake modules can be included in your project: * [Common](Common.cmake) does a common CMake setup, and also includes: * [CommonLibrary](CommonLibrary.cmake) *common_library* function to build a - shared library using a standard recipe and generates header files for the - library (api.h, version.h). + (shared) library using a standard recipe and generates header files for + the library (api.h, version.h). * [CommonApplication](CommonApplication.cmake) *common_application* function to build an application using a standard recipe. - * [CommonPackage](CommonPackage.cmake) *common_package* for more convenience - over find_package and *common_package_post* (last after all common_package - calls) to generate defines.h and options.cmake for feature checking. - * [Compiler](Compiler.cmake): Default compiler flags applied via - common_compiler_flags(), useful default warnings and 'safe' C++11 - features. + * [CommonFindPackage](CommonFindPackage.cmake) *common_find_package* for + more convenience over find_package and *common_find_package_post* (must be + last after all common_find_package calls) to generate defines.h and + options.cmake for feature checking. + * [CommonCompiler](CommonCompiler.cmake): Default compiler flags can be set + on given target to common_compile_options(), useful default warnings and + 'safe' C++11 features. * [GitInfo](GitInfo.cmake) sets variables with information about the git source tree. * [GitTargets](GitTargets.cmake) *branch*, *cut*, *tag*, *erase*, *retag*, @@ -43,19 +44,20 @@ The following CMake modules can be included in your project: * [CommonCTest](CommonCTest.cmake) should be included from a tests subfolder. Does a common CTest setup, automatically adding all .cpp files in the current folder as unit tests to a *tests* target. It also includes: - * [Coverage](Coverage.cmake) *coverage* target to generate a code coverage - report as html, if ENABLE_COVERAGE option is also set. Additional compiler - flags are set in that case, so it should be enabled only for debug builds. + * [CommonCoverage](CommonCoverage.cmake) *coverage* target to generate a + code coverage report as html, if COMMON_ENABLE_COVERAGE option is set. + Additional compiler flags are set in that case, so it should be enabled + only for debug builds. * [CommonCPPCheck](CommonCPPCheck.cmake): *cppcheck* target for static code analysis. Also adds all cppcheck targets to *tests* target. - * [CommandClangCheck](CommandClangCheck.cmake): *clangcheck* target for + * [CommonClangCheck](CommonClangCheck.cmake): *clangcheck* target for clang-check code analysis. Adds all clangcheck targets to *tests* if - ENABLE_CLANGCHECK_TESTS is set. + COMMON_ENABLE_CLANGCHECK_TESTS is set. * [CommonPackageConfig](CommonPackageConfig.cmake) generates cmake package information files for the project. These files let other CMake-based projects locate it through find_package (in config mode, without the need for a finder script). Must be included at the end of the CMakeLists.txt, after all targets - have been added via common_library(). + have been added via common_library() and common_application(). * [CommonCPack](CommonCPack.cmake) Configures the CPack package generator to redistribute the project as an installable package. Also includes CommonPackageConfig. diff --git a/SubProject.cmake b/SubProject.cmake index fed3183..c71a5f5 100644 --- a/SubProject.cmake +++ b/SubProject.cmake @@ -6,8 +6,6 @@ # present in the same CMake source directory. The .gitsubprojects file # contains lines in the form: # "git_subproject( )" -# Will also parse Buildyard config files in the current directory and -# activate all configurations which have _SUBPROJECT set. # # All the subprojects will be cloned and configured during the CMake configure # step thanks to the 'git_subproject(project giturl gittag)' macro @@ -69,20 +67,16 @@ set(__common_source_dir ${COMMON_SOURCE_DIR}) get_filename_component(__common_source_dir ${__common_source_dir} ABSOLUTE) file(MAKE_DIRECTORY ${__common_source_dir}) -function(subproject_install_packages file name) +function(subproject_install_packages name) if(NOT INSTALL_PACKAGES) return() endif() - if(EXISTS ${file}) - include(${file}) - endif() - string(TOUPPER ${name} NAME) - list(APPEND ${NAME}_DEB_DEPENDS pkg-config git subversion cmake autoconf - automake git-review doxygen ${OPTIONAL_DEBS}) + list(APPEND ${NAME}_DEB_DEPENDS pkg-config git cmake git-review doxygen + ${OPTIONAL_DEBS}) set(${NAME}_BUILD_DEBS ${NAME}_DEB_DEPENDS) - list(APPEND ${NAME}_DEB_DEPENDS ninja-build lcov cppcheck git-svn clang + list(APPEND ${NAME}_DEB_DEPENDS ninja-build lcov cppcheck clang clang-format-3.5) # optional deb packages, not added to build spec list(APPEND ${NAME}_PORT_DEPENDS cppcheck) @@ -148,8 +142,7 @@ function(add_subproject name) "Location of ${name} project" FORCE) endif() - subproject_install_packages( - "${__common_source_dir}/${path}/CMake/${name}.cmake" ${name}) + subproject_install_packages(${name}) # add the source sub directory to our build and set the binary dir # to the build tree @@ -171,7 +164,7 @@ endfunction() macro(git_subproject name url tag) # enter early to catch all dependencies common_graph_dep(${PROJECT_NAME} ${name} TRUE TRUE) - if(NOT BUILDYARD AND NOT DISABLE_SUBPROJECTS) + if(NOT DISABLE_SUBPROJECTS) string(TOUPPER ${name} NAME) if(NOT ${NAME}_FOUND AND NOT ${name}_FOUND) get_property(__included GLOBAL PROPERTY ${name}_IS_SUBPROJECT) @@ -200,8 +193,7 @@ endmacro() # Interpret .gitsubprojects if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitsubprojects") - subproject_install_packages( - "${CMAKE_SOURCE_DIR}/CMake/${PROJECT_NAME}.cmake" ${PROJECT_NAME}) + subproject_install_packages(${PROJECT_NAME}) set(__subprojects) # appended on each git_subproject invocation include(.gitsubprojects) @@ -250,50 +242,3 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitsubprojects") add_dependencies(update ${PROJECT_NAME}-update-git-subprojects) endif() endif() - -function(subproject_configure) - # interpret Buildyard project.cmake and depends.txt configurations - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/depends.txt") - file(READ depends.txt SUBPROJECT_DEPENDS) - string(REGEX REPLACE "#[^\n]*" "" SUBPROJECT_DEPENDS - "${SUBPROJECT_DEPENDS}") - string(REGEX REPLACE "^\n" "" SUBPROJECT_DEPENDS "${SUBPROJECT_DEPENDS}") - string(REGEX REPLACE "[ \n]" ";" SUBPROJECT_DEPENDS "${SUBPROJECT_DEPENDS}") - - list(LENGTH SUBPROJECT_DEPENDS SUBPROJECT_DEPENDS_LEFT) - while(SUBPROJECT_DEPENDS_LEFT GREATER 2) - list(GET SUBPROJECT_DEPENDS 0 SUBPROJECT_DEPENDS_DIR) - list(GET SUBPROJECT_DEPENDS 1 SUBPROJECT_DEPENDS_REPO) - list(GET SUBPROJECT_DEPENDS 2 SUBPROJECT_DEPENDS_TAG) - list(REMOVE_AT SUBPROJECT_DEPENDS 0 1 2) - list(LENGTH SUBPROJECT_DEPENDS SUBPROJECT_DEPENDS_LEFT) - - git_subproject(${SUBPROJECT_DEPENDS_DIR} ${SUBPROJECT_DEPENDS_REPO} - ${SUBPROJECT_DEPENDS_TAG}) - endwhile() - endif() - - file(GLOB _files *.cmake) - list(SORT _files) - foreach(_file ${_files}) - string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" _config ${_file}) - list(APPEND _localFiles ${_config}) - - string(REPLACE ".cmake" "" Name ${_config}) - get_filename_component(NAME ${Name} NAME) - string(TOUPPER ${NAME} NAME) - set(${NAME}_DIR ${BASEDIR}) - include(${_file}) - - if(${NAME}_SUBPROJECT) - if(NOT ${NAME}_REPO_TAG) - set(${NAME}_REPO_TAG master) - endif() - git_subproject(${Name} ${${NAME}_REPO_URL} ${${NAME}_REPO_TAG}) - endif() - endforeach() - - if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") - unset(INSTALL_PACKAGES CACHE) # Remove after install in SubProject.cmake - endif() -endfunction() diff --git a/System.cmake b/System.cmake deleted file mode 100644 index 4da1af2..0000000 --- a/System.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2013-2015 Stefan.Eilemann@epfl.ch -# Daniel.Nachbaur@epfl.ch -# -# Output variables -# - SYSTEM - a human-readable string identifier for the current platform -# (Win32, Darwin or Linux) -# - OSX_VERSION - the two numbers OS X version (e.g. 10.9) - -if(SYSTEM) - return() -endif() - -if(WIN32) - set(SYSTEM Win32) -endif() -if(APPLE) - set(SYSTEM Darwin) - execute_process(COMMAND sw_vers -productVersion OUTPUT_VARIABLE OSX_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() -if(CMAKE_SYSTEM_NAME MATCHES "Linux") - set(SYSTEM Linux) -endif() -if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - set(SYSTEM FreeBSD) -endif() -if(NOT SYSTEM) - message(FATAL_ERROR "Unable to determine OS") -endif() diff --git a/TestCPP11.cmake b/TestCPP11.cmake deleted file mode 100644 index 66a78cb..0000000 --- a/TestCPP11.cmake +++ /dev/null @@ -1,113 +0,0 @@ -# Copyright (c) 2013-2015 ahmet.bilgili@epfl.ch -# Stefan.Eilemann@epfl.ch -# Daniel.Nachbaur@epfl.ch - -# OPT: do this only once, included by Common.cmake, don't do if C++03 -if(TESTS_CPP11_DONE OR COMMON_USE_CXX03) - return() -endif() -set(TESTS_CPP11_DONE ON) - -if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - message(WARNING "For better performance, include TestCPP11 in the top-level " - "project so that it is run only once.") -endif() - -set(TESTS_CPP11 sharedptr tuple auto nullptr array final_override noexcept - unordered_map template_alias) - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_sharedptr.cpp -"#include -int main() -{ - std::shared_ptr< int > a( new int ); - return 0; -}") - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_tuple.cpp -"#include -int main() -{ - std::tuple< int, char> foo(10,'x'); - return 0; -}") - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_auto.cpp -"int main() -{ - int a = 2; - auto foo = a; - foo++; - return 0; -}") - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_nullptr.cpp -"int main() -{ - int *ptr = nullptr; - ptr++; - return 0; -}") - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_array.cpp -"#include -int main() -{ - std::array a2 = {{1, 2, 3}}; - a2[ 0 ] = 1; - return 0; -}") - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_final_override.cpp -"class Foo -{ -public: - virtual void one(); - virtual void two() final; - virtual ~Foo(); -}; - -class Bar : public Foo -{ - virtual void one() override; - virtual ~Bar(); -}; - -int main() {}") - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_noexcept.cpp -"bool foo() noexcept { return false; } -int main() {}") - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_unordered_map.cpp -"#include -int main() -{ - std::unordered_map< int, int > test; - test[ 42 ] = 17; - return 0; -}") - -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_template_alias.cpp -"#include -template using FooVector = std::vector< T >; -int main() -{ - FooVector< int > foo; - return 0; -}") - -while(TESTS_CPP11) - list(GET TESTS_CPP11 0 TEST_CPP11_name) - list(REMOVE_AT TESTS_CPP11 0) - string(TOUPPER ${TEST_CPP11_name} TEST_CPP11_NAME) - - try_compile(CXX_${TEST_CPP11_NAME}_SUPPORTED - ${CMAKE_CURRENT_BINARY_DIR}/cpp11_${TEST_CPP11_name} - ${CMAKE_CURRENT_BINARY_DIR}/cpp11_${TEST_CPP11_name}.cpp OUTPUT_VARIABLE output) - - if(CXX_${TEST_CPP11_NAME}_SUPPORTED) - add_definitions(-DCXX_${TEST_CPP11_NAME}_SUPPORTED) - endif() -endwhile() - diff --git a/cpp/defines.h b/cpp/defines.h index ea69a3a..5793001 100644 --- a/cpp/defines.h +++ b/cpp/defines.h @@ -1,4 +1,4 @@ -// generated by CommonPackage.cmake, do not edit. +// generated by CommonFindPackage.cmake, do not edit. /** * @file include/@PROJECT_INCLUDE_NAME@/defines.h diff --git a/cpp/dummy.cpp b/cpp/dummy.cpp deleted file mode 100644 index 13778b6..0000000 --- a/cpp/dummy.cpp +++ /dev/null @@ -1 +0,0 @@ -// used by CommonLibrary.cmake to fake INTERFACE library for CMake 2 diff --git a/cpp/test.h b/cpp/test.h deleted file mode 100644 index 1cd35b0..0000000 --- a/cpp/test.h +++ /dev/null @@ -1,136 +0,0 @@ - -/* Copyright (c) 2005-2014, Stefan Eilemann - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of Eyescale Software GmbH nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef LBTEST_TEST_H -#define LBTEST_TEST_H - -#include -#include -#include - -#include -#include -#include - -#define OUTPUT lunchbox::Log::instance( __FILE__, __LINE__ ) - -#define TEST( x ) \ - { \ - LBVERB << "Test " << #x << std::endl; \ - if( !(x) ) \ - { \ - OUTPUT << #x << " failed (l." << __LINE__ << ')' << std::endl; \ - lunchbox::abort(); \ - ::exit( EXIT_FAILURE ); \ - } \ - } - -#define TESTINFO( x, info ) \ - { \ - LBVERB << "Test " << #x << ": " << info << std::endl; \ - if( !(x) ) \ - { \ - OUTPUT << #x << " failed (l." << __LINE__ << "): " << info \ - << std::endl; \ - lunchbox::abort(); \ - ::exit( EXIT_FAILURE ); \ - } \ - } - -#define TESTRESULT( x, type ) \ - { \ - LBVERB << "Test " << #x << std::endl; \ - const type& testRes = (x); \ - if( !testRes ) \ - { \ - OUTPUT << #x << " failed with " << testRes << " (l." \ - << __LINE__ << ")" << std::endl; \ - lunchbox::abort(); \ - ::exit( EXIT_FAILURE ); \ - } \ - } - -int testMain( int argc, char **argv ); - -namespace -{ -class Watchdog : public lunchbox::Thread -{ -public: - explicit Watchdog( const std::string& name ) : _name( name ) {} - - virtual void run() - { - lunchbox::Thread::setName( "Watchdog" ); -#ifdef TEST_RUNTIME - lunchbox::sleep( TEST_RUNTIME * 1000 ); - std::cerr << "Watchdog triggered - " << _name - << " did not terminate within " << TEST_RUNTIME << "s" - << std::endl; -#else - lunchbox::sleep( 60000 ); - std::cerr << "Watchdog triggered - " << _name - << " did not terminate within 1 minute" << std::endl; -#endif - lunchbox::abort( true /*dumpThreads*/ ); - } - -private: - const std::string _name; -}; -} - -int main( int argc, char **argv ) -{ -#ifndef TEST_NO_WATCHDOG - Watchdog watchdog( argv[0] ); - watchdog.start(); -#endif - - try - { - const int result = testMain( argc, argv ); - if( result != EXIT_SUCCESS ) - return result; - } - catch( const std::runtime_error& e ) - { - LBINFO << e.what() << std::endl; - return EXIT_FAILURE; - } - -#ifndef TEST_NO_WATCHDOG - watchdog.cancel(); - lunchbox::sleep( 10 ); // give watchdog time to terminate -#endif - return EXIT_SUCCESS; -} - -# define main testMain - -#endif // LBTEST_TEST_H diff --git a/cpp/version.h b/cpp/version.h index 1ed224f..6bba57c 100644 --- a/cpp/version.h +++ b/cpp/version.h @@ -14,19 +14,19 @@ namespace @namespace@ { /** The current major version. */ -# define @NAMESPACE@_VERSION_MAJOR @VERSION_MAJOR@ +# define @NAMESPACE@_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ /** The current minor version. */ -# define @NAMESPACE@_VERSION_MINOR @VERSION_MINOR@ +# define @NAMESPACE@_VERSION_MINOR @PROJECT_VERSION_MINOR@ /** The current patch level. */ -# define @NAMESPACE@_VERSION_PATCH @VERSION_PATCH@ +# define @NAMESPACE@_VERSION_PATCH @PROJECT_VERSION_PATCH@ /** The current SCM revision. */ # define @NAMESPACE@_VERSION_REVISION 0x@GIT_REVISION@ /** The current binary interface. */ -# define @NAMESPACE@_VERSION_ABI @VERSION_ABI@ +# define @NAMESPACE@_VERSION_ABI @PROJECT_VERSION_ABI@ /** True if the current version is newer than the given one. */ # define @NAMESPACE@_VERSION_GT( MAJOR, MINOR, PATCH ) \