diff --git a/.cmake-format b/.cmake-format new file mode 100644 index 0000000..787f6a7 --- /dev/null +++ b/.cmake-format @@ -0,0 +1,71 @@ +format: + tab_size: 2 + line_width: 100 + dangle_parens: true + +parse: + additional_commands: + cpmaddpackage: + pargs: + nargs: '*' + flags: [] + spelling: CPMAddPackage + kwargs: &cpmaddpackagekwargs + NAME: 1 + FORCE: 1 + VERSION: 1 + GIT_TAG: 1 + DOWNLOAD_ONLY: 1 + GITHUB_REPOSITORY: 1 + GITLAB_REPOSITORY: 1 + GIT_REPOSITORY: 1 + SVN_REPOSITORY: 1 + SVN_REVISION: 1 + SOURCE_DIR: 1 + DOWNLOAD_COMMAND: 1 + FIND_PACKAGE_ARGUMENTS: 1 + NO_CACHE: 1 + GIT_SHALLOW: 1 + URL: 1 + URL_HASH: 1 + URL_MD5: 1 + DOWNLOAD_NAME: 1 + DOWNLOAD_NO_EXTRACT: 1 + HTTP_USERNAME: 1 + HTTP_PASSWORD: 1 + OPTIONS: + + cpmfindpackage: + pargs: + nargs: '*' + flags: [] + spelling: CPMFindPackage + kwargs: *cpmaddpackagekwargs + cpmdeclarepackage: + pargs: + nargs: '*' + flags: [] + spelling: CPMDeclarePackage + kwargs: *cpmaddpackagekwargs + packageproject: + pargs: + nargs: '*' + flags: [] + spelling: packageProject + kwargs: + NAME: 1 + VERSION: 1 + INCLUDE_DIR: 1 + INCLUDE_DESTINATION: 1 + BINARY_DIR: 1 + COMPATIBILITY: 1 + VERSION_HEADER: 1 + DEPENDENCIES: + + cpmusepackagelock: + pargs: 1 + spelling: CPMUsePackageLock + cpmregisterpackage: + pargs: 1 + spelling: CPMRegisterPackage + cpmgetpackageversion: + pargs: 2 + spelling: CPMGetPackageVersion diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..6e2798f --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,25 @@ +name: Check + +on: + push: + branches: [master, main] + pull_request: + branches: [master, main] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: write licences + run: | + cmake -S test/project -B build/test + cmake --build build/test --target write-licences + + - name: check licences + run: | + grep -q Catch2 build/third_party.txt + grep -q fmt build/third_party.txt diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml new file mode 100644 index 0000000..4a0c8ac --- /dev/null +++ b/.github/workflows/style.yml @@ -0,0 +1,26 @@ +name: Style + +on: + push: + branches: [master, main] + pull_request: + branches: [master, main] + +jobs: + style: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v1 + + - name: Install format dependencies + run: | + brew install clang-format + pip3 install cmake_format==0.6.11 pyyaml + + - name: configure + run: cmake -Htest/style -Bbuild/style + + - name: check style + run: cmake --build build/style --target check-format diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cd80ce1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,52 @@ +function(write_licence_disclaimer FILE_NAME PACKAGES) + file(WRITE ${FILE_NAME} "") + set(PRINT_DELIMITER OFF) + foreach(package ${PACKAGES}) + if(PRINT_DELIMITER) + file(APPEND ${FILE_NAME} "\n-----\n") + endif() + file(GLOB licences "${${package}_SOURCE_DIR}/LICENSE*" "${${package}_SOURCE_DIR}/LICENCE*") + list(LENGTH licences LICENSE_COUNT) + if(LICENSE_COUNT GREATER_EQUAL 1) + list(GET licences 0 licence) + file(READ ${licence} LICENCE_TEXT) + file(APPEND ${FILE_NAME} + "The following software may be included in this product: ${package}\n\n${LICENCE_TEXT}\n" + ) + set(PRINT_DELIMITER ON) + else() + message("WARNING: no licence files found for package \"${package}\".") + endif() + if(LICENSE_COUNT GREATER 1) + message( + "WARNING: multiple licence files found for package \"${package}\": ${licences}. Only first file will be used." + ) + endif() + endforeach() + message("wrote licences to ${FILE_NAME}") +endfunction() + +set(CPMLicences_SCRIPT_PATH + ${CMAKE_CURRENT_LIST_FILE} + CACHE INTERNAL "" +) + +function(create_write_licence_disclaimer_target TARGET_NAME FILE_NAME PACKAGES) + message("add target for licences: ${PACKAGES}") + + set(PACKAGE_SOURCES "") + foreach(package ${PACKAGES}) + list(APPEND PACKAGE_SOURCES "-D${package}_SOURCE_DIR=\"${${package}_SOURCE_DIR}\"") + endforeach() + + add_custom_target( + ${TARGET_NAME} + COMMAND + ${CMAKE_COMMAND} -DPRINT_LICENCE_FILE_NAME=${FILE_NAME} + "-DPRINT_LICENCE_PACKAGES=\"${PACKAGES}\"" ${PACKAGE_SOURCES} -P ${CPMLicences_SCRIPT_PATH} + ) +endfunction() + +if(PRINT_LICENCE_FILE_NAME) + write_licence_disclaimer(${PRINT_LICENCE_FILE_NAME} "${PRINT_LICENCE_PACKAGES}") +endif() diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..f069733 --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,19 @@ +set(CPM_DOWNLOAD_VERSION 0.27.5) + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) + message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") + file(DOWNLOAD + https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} + ) +endif() + +include(${CPM_DOWNLOAD_LOCATION}) diff --git a/test/project/CMakeLists.txt b/test/project/CMakeLists.txt new file mode 100644 index 0000000..f3c05ae --- /dev/null +++ b/test/project/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) +project(CPMLicenceTest) + +include(../../cmake/CPM.cmake) + +CPMAddPackage(NAME CPMLicences SOURCE_DIR ..) + +CPMAddPackage( + NAME Catch2 + GITHUB_REPOSITORY catchorg/Catch2 + VERSION 2.5.0 +) + +CPMAddPackage( + NAME fmt + GIT_TAG 6.1.2 + GITHUB_REPOSITORY fmtlib/fmt +) + +create_write_licence_disclaimer_target( + write-licences "${CMAKE_CURRENT_BINARY_DIR}/third_party.txt" "${CPM_PACKAGES}" +) diff --git a/test/style/CMakeLists.txt b/test/style/CMakeLists.txt new file mode 100644 index 0000000..59baba0 --- /dev/null +++ b/test/style/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) +project(CPMLicenceTest) + +include(../../cmake/CPM.cmake) + +CPMAddPackage( + NAME Format.cmake + VERSION 1.6 + GITHUB_REPOSITORY TheLartians/Format.cmake + OPTIONS "FORMAT_CHECK_CMAKE ON" +)