From e69ad1e4eea269bfbe802adb5e9894fddaef23fc Mon Sep 17 00:00:00 2001 From: Alex Beimler Date: Fri, 14 Oct 2022 13:24:38 +0200 Subject: [PATCH 1/3] add cross_build_mingw task --- Taskfile.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Taskfile.yml b/Taskfile.yml index 7712fd5..fbbb37a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -50,6 +50,13 @@ tasks: FEATURE_TESTS: OFF CMAKE_BUILD_TYPE: Debug + cross_build_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" + install: - task: build - cmake --install ./build --prefix {{.INSTALL_PREFIX | default "./install"}} From c70406474527bf49869330ff5bf270619eda00dd Mon Sep 17 00:00:00 2001 From: abeimler Date: Thu, 29 Dec 2022 22:18:31 +0100 Subject: [PATCH 2/3] 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 From 323b70787b99b7edb3eabe314bca055420213f0d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 10 Jan 2023 15:09:05 -0800 Subject: [PATCH 3/3] fix: use FetchContent to download the project_options This makes the integration self-contained. CPM is a great project, but I think FetchContent is a simpler entry. We can add CPM to ProjectOptions later. --- CMakeLists.txt | 16 ++++------------ cmake/CPM.cmake | 21 --------------------- 2 files changed, 4 insertions(+), 33 deletions(-) delete mode 100644 cmake/CPM.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f6d87b..17e153a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,21 +4,13 @@ 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 # https://github.com/aminya/project_options # 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() +include(FetchContent) +FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.26.3.zip) +FetchContent_MakeAvailable(_project_options) +include(${_project_options_SOURCE_DIR}/Index.cmake) # Define the features of the project include("./Features.cmake") diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake deleted file mode 100644 index 0679cef..0000000 --- a/cmake/CPM.cmake +++ /dev/null @@ -1,21 +0,0 @@ -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