build-cpp / cmkr

Modern build system based on CMake and TOML.
https://cmkr.build
MIT License
453 stars 29 forks source link

Abiity to build a project with two different architectures #151

Closed realoriginal closed 1 month ago

realoriginal commented 1 month ago

Bit of an odd request, unless it already exists - I've been unable to achieve it. I attempted to essentially have singular cmkr.toml file that builds an x86, and x64 variation of the same code base using the following TOML:

[cmake]
version = "3.19"
cmkr-include = "cmake/cmkr.cmake"

[project]
name = "reaper"

[target.reaper-x64]
type = "executable"
sources = [ "src/*.c" ]
include-before = [ "cmake/toolchain-x64.cmake" ]

[target.reaper-x86]
type = "executable"
sources = [ "src/*.c" ]
include-before = [ "cmake/toolchain-x86.cmake" ]

With the toolchain files containing the respective overwrites for the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER variables. However, understandably, the include-before of the last target ( x86 ) overwrites the CMAKE_C_COMPILER for the x64 build. Would it be plausible to achieve this - Or is it generally recommended to instead build each part separately by overwriting it during the build time -DCMAKE_C_COMPILER={CROSS_PREFIX}-clang etc

realoriginal commented 1 month ago

The intention is that so I may be run cmkr build that builds the [project] as two different architectures/compilers in one singular build.

realoriginal commented 1 month ago

Went with a somewhat moronic alternative of using the compile flags feature to achieve it, forcing the injection of the flag I needed.

mrexodia commented 1 month ago

Just FYI, this is very much not recommended with CMake.