CMake: Conditionally define symbols based on target platform?
-
wrote on 31 Jan 2025, 18:28 last edited by
I'm new to CMake after using QMake for many years. I mostly have my project working, but I can't find how to conditionally define symbols based on the platform I'm building for. In QMake, I could just do something like this:
macx: DEFINES += MAC_ONLY_SYMBOL
What's the equivalent in CMake?
-
You should read about target_compile_definitions() to add a compile definition to your target and conditions to check for APPLE.
-
wrote on 1 Feb 2025, 00:21 last edited by Ron Menelli 2 Jan 2025, 00:22
Thanks very much! The other piece I was missing is that CMake uses if/else statements. So, the result is:
if(APPLE) target_compile_options(mytarget PRIVATE -DMAC_ONLY_SYMBOL) else() target_compile_options(mytarget PRIVATE -DOTHER_SYMBOL) endif()
1/3