I have project where I need some specific preprocessor definitions. Nothing less, nothing more. I tried various solutions:
set(DEFINES MY_DEFINE)
target_compile_definitions(my_target PRIVATE ${DEFINES})
and
set(DEFINES -DMY_DEFINE)
add_definitions(${DEFINES})
even
set(DEFINES MY_DEFINE)
set_property(TARGET my_target PROPERTY CACHE COMPILE_DEFINITIONS ${DEFINES})
Every time CMake still injects some other defines:
WIN32
_WINDOWS
CMAKE_INTDIR="$(CONFIG)"
My target is a static library and generator is Visual Studio 2015, in case it matters. How can I get CMake to set only my defines?
Since those are platform specific defines in CMake, you can only remove them "globally" for your current CMakeList.txt
scope (not for an idividual target) with something like:
string(REGEX REPLACE "(-D|/D)[^ ]* " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Reference