diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..5a6467e --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,83 @@ +image: Visual Studio 2017 + +platform: + - x64 + +configuration: + - Debug + - Release + +environment: + QT_VERSION: 5.9 + QT_COMPILED: msvc2017 + matrix: + - SHARED: ON + - SHARED: OFF + +install: + ############################################################################ + # Install Ninja + ############################################################################ + - set NINJA_URL="https://github.com/ninja-build/ninja/releases/download/v1.6.0/ninja-win.zip" + - appveyor DownloadFile %NINJA_URL% -FileName ninja.zip + - 7z x ninja.zip -oC:\projects\deps\ninja > nul + - set PATH=C:\projects\deps\ninja;%PATH% + - ninja --version + + ############################################################################ + # set correct QTDIR in the PATH environment variable + ############################################################################ + - set VS_FULL=%VS_VERSION% Win64 + - set QTDIR=C:/Qt/%QT_VERSION%/%QT_COMPILED%_64 + - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64 + - set PATH=%PATH%;%QTDIR%/bin + +build_script: +# Clone examples: they are the code to test against. + - git clone https://github.com/frederikvannoote/cmake-common-examples.git examples + - set CMAKE_COMMON=C:/projects/cmake-common + - mkdir installed + +test_script: + # Build and install simplelib + - mkdir simplelib-build + - cd simplelib-build + - cmake -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=../installed -G Ninja ../examples/simplelib + - cmake --build . --config %configuration% --target all + - cmake --build . --config %configuration% --target install + - cmake --build . --config %configuration% --target sdk + - cd .. + + # Relocate library + - xcopy /E installed relocated\ + + # Build and install Simpleapp + - mkdir simpleapp-build + - cd simpleapp-build + - cmake -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=../installed -DCC1simplelib_DIR=../relocated/lib/cmake/CC1simplelib -G Ninja ../examples/simpleapp + - cmake --build . --config %configuration% --target all + - cmake --build . --config %configuration% --target install + - cd .. + + # Build and install QSimpleApp + - mkdir QSimpleApp-build + - cd QSimpleApp-build + - cmake -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=../installed -DCC1simplelib_DIR=../relocated/lib/cmake/CC1simplelib -G Ninja ../examples/QSimpleApp/ + - cmake --build . --config %configuration% --target all + - cmake --build . --config %configuration% --target install + - cd .. + + # Build and install complex lib + - mkdir complexlib-build + - cd complexlib-build + - cmake -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=../installed -G Ninja ../examples/complexlib + - cmake --build . --config %configuration% --target all + - cmake --build . --config %configuration% --target install + - cmake --build . --config %configuration% --target sdk + - cd .. + +# uncomment following lines to be able to debug the appveyor image through RDP protocol when build finished +# https://www.appveyor.com/docs/how-to/rdp-to-build-worker/ +# on_finish: +# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6feb084 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,103 @@ +language: cpp +sudo: false +dist: trusty + +os: + - linux + - osx + +compiler: + - gcc + - clang + +env: + global: + - + + matrix: + - CMAKE_BUILD_TYPE=Debug + - CMAKE_BUILD_TYPE=Release + +matrix: + exclude: + - os: linux + compiler: clang + - os: osx + compiler: gcc + +addons: + apt: + packages: + - ninja-build + - qtbase5-dev + +before_install: + - | + # Install cmake + if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then + CMAKE_URL="http://www.cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz" + cd /tmp + mkdir cmake + travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake + export PATH=/tmp/cmake/bin:${PATH} + else + if ! brew ls --version cmake &>/dev/null; then brew install cmake; fi + fi + - | + # Install cmake and ninja + if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then + export QTDIR=/usr/lib/x86_64-linux-gnu/qt5 + export PATH="$QTDIR/bin:$PATH" + else + brew update > /dev/null + brew tap homebrew/versions + brew install ninja + brew install qt + export QTDIR="/usr/local/opt/qt5" + export PATH="$QTDIR/bin:$PATH" + fi + +install: +# Clone examples: they are the code to test against. + - git clone https://github.com/frederikvannoote/cmake-common-examples.git ${HOME}/examples + - export CMAKE_COMMON=${TRAVIS_BUILD_DIR} + - mkdir /tmp/installed + +script: + - | + # Build and install simplelib + mkdir /tmp/simplelib-build + cd /tmp/simplelib-build + cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/installed -G Ninja ${HOME}/examples/simplelib + cmake --build . --target all + cmake --build . --target install + cmake --build . --target sdk + - | + # Relocate library + cp -r /tmp/installed /tmp/relocated + + - | + # Build and install Simpleapp + mkdir /tmp/simpleapp-build + cd /tmp/simpleapp-build + cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/installed -DCC1simplelib_DIR=/tmp/relocated/lib/cmake/CC1simplelib -G Ninja ${HOME}/examples/simpleapp + cmake --build . --target all + cmake --build . --target install + + - | + # Build and install QSimpleApp + mkdir /tmp/QSimpleApp-build + cd /tmp/QSimpleApp-build + cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/installed -DCC1simplelib_DIR=/tmp/relocated/lib/cmake/CC1simplelib -G Ninja ${HOME}/examples/QSimpleApp/ + cmake --build . --target all + cmake --build . --target install + + - | + # Build and install complex lib + mkdir /tmp/complexlib-build + cd /tmp/complexlib-build + cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/installed -G Ninja ${HOME}/examples/complexlib + cmake --build . --target all + cmake --build . --target install + cmake --build . --target sdk + diff --git a/AddQtTest.cmake b/AddQtTest.cmake index 557480c..b83ae8f 100644 --- a/AddQtTest.cmake +++ b/AddQtTest.cmake @@ -19,9 +19,13 @@ endmacro() option(MANUAL_TESTS_ENABLED "Enable manual tests" OFF) macro(add_manual_qt_test TEST_NAME SRCS) + find_package(Qt5Test REQUIRED) + add_executable(${TEST_NAME} ${SRCS}) + target_link_libraries(${TEST_NAME} PUBLIC Qt5::Test) + if(DEFINED MANUAL_TESTS_ENABLED) if(${MANUAL_TESTS_ENABLED}) - add_qt_test(${TEST_NAME} "${SRCS}") + add_test(NAME ${TEST_NAME} COMMAND $) endif(${MANUAL_TESTS_ENABLED}) endif(DEFINED MANUAL_TESTS_ENABLED) endmacro() diff --git a/AddResourceInfo.cmake b/AddResourceInfo.cmake index ac4a4ed..4c6643e 100644 --- a/AddResourceInfo.cmake +++ b/AddResourceInfo.cmake @@ -20,8 +20,12 @@ macro(add_resource_info PROJECT ISLIBRARY FILE_VER_MAJOR FILE_VER_MINOR FILE_VER #If we are creating an RC file for a library, make sure it is a DLL and not a static one. If it's an application, no need to do this check. set(IS_APPLICABLE_RESOURCE (NOT ${ISLIBRARY} OR (${BUILD_SHARED_LIBS} AND ${ISLIBRARY}))) if(WIN32 AND NOT UNIX AND ${IS_APPLICABLE_RESOURCE}) - # Finish creating the relevant data for the RC file. - get_git_head_revision(GIT_REFSPEC GIT_COMMIT_HASH) + + if(NOT CMAKE_BUILD_TYPE MATCHES Debug) + # Finish creating the relevant data for the RC file. + get_git_head_revision(GIT_REFSPEC GIT_COMMIT_HASH) + endif() + string(TIMESTAMP CURRENT_YEAR "%Y") if(CMAKE_SIZEOF_VOID_P EQUAL 4) set(ARCHITECTURE_DESC "32-bit") diff --git a/CodeCoverage.cmake b/CodeCoverage.cmake index 623c412..ce3ba49 100644 --- a/CodeCoverage.cmake +++ b/CodeCoverage.cmake @@ -69,7 +69,8 @@ if(CODE_COVERAGE) COMMAND ${LCOV_EXECUTABLE} --quiet --capture --directory . --base-directory ${CMAKE_SOURCE_DIR} --no-external -o coverage.info COMMAND ${LCOV_EXECUTABLE} --quiet --remove coverage.info ${CODE_COVERAGE_EXCLUDES} -o coverage.info COMMAND ${LCOV_EXECUTABLE} --quiet --remove coverage.info \*test_\* -o coverage.info - COMMAND ${LCOV_EXECUTABLE} --quiet --remove coverage.info catch.hpp -o coverage.info + COMMAND ${LCOV_EXECUTABLE} --quiet --remove coverage.info \*catch.hpp\* -o coverage.info + COMMAND ${LCOV_EXECUTABLE} --quiet --remove coverage.info \*contract.cpp\* -o coverage.info COMMAND ${LCOV_EXECUTABLE} --list coverage.info COMMAND ${LCOV_EXECUTABLE} --summary coverage.info WORKING_DIRECTORY ${CMAKE_BINARY_DIR} diff --git a/CompilerFlags.cmake b/CompilerFlags.cmake index cd07f59..758fe24 100644 --- a/CompilerFlags.cmake +++ b/CompilerFlags.cmake @@ -195,6 +195,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") "/wd4714" # suppress warning: marked __forceinline but are not inlined # Fixed in Qt 5.10.0 (https://bugreports.qt.io/browse/QTBUG-55042) # Check later with Qt >= 5.10.0 if warning suppression can be removed + "/wd4718" # Workaround for https://bugreports.qt.io/browse/QTBUG-54089 "/nologo" "/EHsc-" # disable exceptions "/GR-" # disable RTTI diff --git a/Doxyfile.in b/Doxyfile.in index 2d9c6a1..c452bc8 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -67,3 +67,5 @@ SORT_MEMBER_DOCS = YES SORT_MEMBERS_CTORS_1ST = YES USE_MATHJAX = YES + +EXAMPLE_PATH = @CMAKE_SOURCE_DIR@ diff --git a/Doxygen.cmake b/Doxygen.cmake index 2be0c21..4f0fabe 100644 --- a/Doxygen.cmake +++ b/Doxygen.cmake @@ -1,20 +1,22 @@ -# check if Doxygen is installed -find_package(Doxygen) -if (DOXYGEN_FOUND) - # set input and output files - set(DOXYGEN_IN ${CMAKE_CURRENT_LIST_DIR}/Doxyfile.in) - set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) +if (NOT TARGET doxygen) + # check if Doxygen is installed + find_package(Doxygen) + if (DOXYGEN_FOUND) + # set input and output files + set(DOXYGEN_IN ${CMAKE_CURRENT_LIST_DIR}/Doxyfile.in) + set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) - # request to configure the file - configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) - message("Doxygen build started") + # request to configure the file + configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) + message("Doxygen build started") - # note the option ALL which allows to build the docs together with the application - add_custom_target(doxygen - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Generating API documentation with Doxygen" - VERBATIM ) -else (DOXYGEN_FOUND) - message("Doxygen need to be installed to generate the doxygen documentation") -endif (DOXYGEN_FOUND) + # note the option ALL which allows to build the docs together with the application + add_custom_target(doxygen + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" + VERBATIM ) + else (DOXYGEN_FOUND) + message("Doxygen need to be installed to generate the doxygen documentation") + endif (DOXYGEN_FOUND) +endif() diff --git a/FindGcov.cmake b/FindGcov.cmake index cdc52a1..888482b 100644 --- a/FindGcov.cmake +++ b/FindGcov.cmake @@ -13,7 +13,7 @@ if(GCOV_EXECUTABLE AND NOT EXISTS "${GCOV_EXECUTABLE}") set(GCOV_EXECUTABLE "notfound" CACHE PATH FORCE "") endif() -IF(NOT CMAKE_COMPILER_IS_GNUCXX AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +IF(NOT CMAKE_COMPILER_IS_GNUCXX AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") MESSAGE(WARNING "Compiler is not GNU gcc or Clang!") set(GCOV_EXECUTABLE "notfound" CACHE PATH FORCE "") ELSEIF( NOT CMAKE_BUILD_TYPE STREQUAL "Debug" ) @@ -21,7 +21,7 @@ ELSEIF( NOT CMAKE_BUILD_TYPE STREQUAL "Debug" ) set(GCOV_EXECUTABLE "notfound" CACHE PATH FORCE "") ELSE() find_program(GCOV_EXECUTABLE NAMES gcov) -ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") include(FindPackageHandleStandardArgs) find_package_handle_standard_args( Gcov DEFAULT_MSG diff --git a/GeneratePackage.cmake b/GeneratePackage.cmake index 1d70c06..5bd9ad4 100644 --- a/GeneratePackage.cmake +++ b/GeneratePackage.cmake @@ -49,17 +49,18 @@ write_basic_package_version_file( # Create import targets install(TARGETS ${TARGET_NAME} EXPORT ${TARGET_NAME}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR} - PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}/private + RUNTIME DESTINATION ${BIN_INSTALL_DIR} + LIBRARY DESTINATION ${LIB_INSTALL_DIR} + ARCHIVE DESTINATION ${LIB_INSTALL_DIR} + PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR} + PRIVATE_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}/private ) # Export the import targets -export(EXPORT ${TARGET_NAME}Targets - FILE "${CMAKE_BINARY_DIR}/${CMAKE_CONFIG_FILE_BASE_NAME}Targets.cmake" +install(EXPORT ${TARGET_NAME}Targets + FILE "${CMAKE_CONFIG_FILE_BASE_NAME}Targets.cmake" NAMESPACE ${PROJECT_NAMESPACE}:: + DESTINATION ${CMAKE_INSTALL_DIR} ) # Now install the 3 config files @@ -68,15 +69,6 @@ install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_CONFIG_FILE_BASE_NAME}Config.cmake DESTINATION ${CMAKE_INSTALL_DIR} ) -install(EXPORT ${TARGET_NAME}Targets - FILE - ${CMAKE_CONFIG_FILE_BASE_NAME}Targets.cmake - NAMESPACE - ${PROJECT_NAMESPACE}:: - DESTINATION - ${CMAKE_INSTALL_DIR} -) - # Create and install a global module include file # This makes it possible to include all header files of the module by using # #include <${PROJECT_NAME}> diff --git a/readme.md b/readme.md index 2a2b0a6..7340f41 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,19 @@ You can fetch the files during your git clone using a submodule. git submodule add -b git@github.com:barco-healthcare/cmake-common.git path/to/cmake/common ``` +## Cloning during cmake run +Add this snippet to your CMakeLists.txt +``` +# Download build system +if(NOT EXISTS "${CMAKE_BINARY_DIR}/buildsys/v2.0") + message(STATUS "Downloading buildsystem...") + + find_package(Git REQUIRED) + execute_process(COMMAND ${GIT_EXECUTABLE} clone --branch v2.0 https://github.com/frederikvannoote/cmake-common.git ${CMAKE_BINARY_DIR}/buildsys/v2.0) +endif() +list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/buildsys/v2.0") +``` + # Usage You can include these files in your CMakeLists.txt