Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake3 port and various cleanups #478

Merged
merged 1 commit into from
Apr 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 0 additions & 7 deletions CMakeInstallPath.cmake

This file was deleted.

111 changes: 57 additions & 54 deletions Common.cmake
Original file line number Diff line number Diff line change
@@ -1,90 +1,84 @@
# 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)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH
"${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
if(NOT CMAKE_OSX_ARCHITECTURES OR CMAKE_OSX_ARCHITECTURES STREQUAL "")
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()
Expand All @@ -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)
20 changes: 3 additions & 17 deletions CommonApplication.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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})
Expand All @@ -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)

Expand Down
11 changes: 4 additions & 7 deletions CommonCPPCTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -68,15 +64,16 @@ 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})

# 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()
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions CommonCPack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand Down
12 changes: 7 additions & 5 deletions CommonClangCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand All @@ -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()
16 changes: 0 additions & 16 deletions CommonCode.cmake

This file was deleted.

Loading