From 64eff6740195e605069fe0bc58e51c803223150e Mon Sep 17 00:00:00 2001 From: FurudBat Date: Thu, 29 Dec 2022 22:18:31 +0100 Subject: [PATCH] fix: update task for new cross-compile with project_options --- CMakeLists.txt | 24 ++++++++++++++++++------ Features.cmake | 2 ++ Taskfile.yml | 4 ++-- cmake/CPM.cmake | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 cmake/CPM.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 184b1e3..2f6d87b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,17 +4,29 @@ cmake_minimum_required(VERSION 3.16) # If commented, the latest supported standard for your compiler is automatically set. # set(CMAKE_CXX_STANDARD 20) -# Add project_options v0.26.2 + +# Add project_options # https://github.com/aminya/project_options -# Change the version in the following URL to update the package (watch the releases of the repository for future updates) -include(FetchContent) -FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.26.2.zip) -FetchContent_MakeAvailable(_project_options) -include(${_project_options_SOURCE_DIR}/Index.cmake) +# Change the version to update the package (watch the releases of the repository for future updates) +include(cmake/CPM.cmake) +CPMAddPackage( + NAME project_options + GITHUB_REPOSITORY aminya/project_options + #VERSION 0.26.3 + GIT_TAG main + DOWNLOAD_ONLY +) +if(project_options_ADDED) + include(${project_options_SOURCE_DIR}/Index.cmake) +endif() # Define the features of the project include("./Features.cmake") +# enable cross-compiling: - should be called before run_vcpkg() +if(ENABLE_CROSS_COMPILING) + enable_cross_compiler() +endif() # install vcpkg dependencies: - should be called before defining project() run_vcpkg() diff --git a/Features.cmake b/Features.cmake index 53e461c..2e81967 100644 --- a/Features.cmake +++ b/Features.cmake @@ -9,3 +9,5 @@ option(FEATURE_DOCS "Enable the docs" OFF) # fuzz tests option(FEATURE_FUZZ_TESTS "Enable the fuzz tests" OFF) + +option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF) \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml index fbbb37a..66c1aad 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -50,12 +50,12 @@ tasks: FEATURE_TESTS: OFF CMAKE_BUILD_TYPE: Debug - cross_build_mingw: + build_cross_mingw: - task: build_template vars: FEATURE_TESTS: OFF CMAKE_BUILD_TYPE: Release - CONFIGURE_FLAGS: -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="/home/cmake/toolchains/x86_64-w64-mingw32.toolchain.cmake" -DVCPKG_TARGET_TRIPLET="x64-mingw-dynamic" + CONFIGURE_FLAGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=x64-mingw-dynamic install: - task: build diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..0679cef --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,21 @@ +set(CPM_DOWNLOAD_VERSION 0.35.0) + +if(CPM_SOURCE_CACHE) + # Expand relative path. This is important if the provided path contains a tilde (~) + get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE) + 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/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} + ) +endif() + +include(${CPM_DOWNLOAD_LOCATION}) \ No newline at end of file