build-cpp / cmkr

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

How can I add a compile definition to a subdirectory? #75

Closed xtremegamer1 closed 1 year ago

xtremegamer1 commented 1 year ago

I imagine it should look something like this:

[subdir.asmjit]
compile_definitions = [
    "ASMJIT_STATIC"
]
gmh5225 commented 1 year ago

Maybe you could try it this way

[subdir.asmjit]
include-before = ["asmjit-static.cmake"]

In asmjit-static.cmake: add_definitions(-DASMJIT_STATIC)

mrexodia commented 1 year ago

Yeah you can do this, but it’s not the correct way to do this. Asmjit has a CMake option to build statically and you should set that instead:

[subdir.asmjit]
cmake-before = "set(ASMJIT_STATIC ON)"

The DEFINED keyword in CMake (confusingly) has nothing to do with compile definitions and instead checks if a CMake variable is defined.