CMake: Conditionally define symbols based on target platform?
Unsolved
Qt Creator and other tools
-
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.
-
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()