aminya / project_options

A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.
https://aminya.github.io/project_options/
MIT License
343 stars 52 forks source link

Add toolchain support #140

Open abeimler opened 2 years ago

abeimler commented 2 years ago

Add function to setup -DCMAKE_TOOLCHAIN_FILE/-DVCPKG_TOOLCHAIN_FILE and include() toolchain via -DOPT_TARGET_TRIPLET:STRING=x64-mingw-dynamic option.

Example:

project_options(
   TARGET_TRIPLET "x64-mingw-dynamic"
)

or with cmake arguments:

# for custom toolchains
cmake ... -DOPT_TOOLCHAIN_FILE:STRING="..." -DOPT_TARGET_TRIPLET:STRING="..."
## setup vcpkg and more

# use project_options toolchains
cmake ... -DOPT_TARGET_TRIPLET:STRING="..."
## setup vcpkg and more

# use vcpkg arguments
cmake ... -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="..." -DVCPKG_TARGET_TRIPLET="..."
## read vcpkg triplet and set OPT_TARGET_TRIPLET etc.

Notes

Upvote & Fund

Fund with Polar

aminya commented 2 years ago

I have taken the automated approach to the toolchains; the user should not need to specify the toolchains manually. We detect the proper toolchain based on the compiler settings and the target system.

For example, for the msvc toolchain: https://github.com/aminya/project_options/blob/370900da1d9df08146c1690a2a2c978122979716/src/VCEnvironment.cmake#L58-L64

aminya commented 1 year ago

We already detect MinGW and apply some fixes for it for VCPKG. You can use the same function to detect MinGW and include its toolchain.

https://github.com/aminya/project_options/blob/370900da1d9df08146c1690a2a2c978122979716/src/MinGW.cmake#L4