how to exclude the compile definitions inherited from the linked library

The find_package command automatically sets up the necessary preprocessor definitions, and also sets up other configurations for its linked target.

I want a way to exclude some compile definitions inherited from the linked library.

Example:

CMakelists.txt

cmake_minimum_required(VERSION 3.27)

project(qt_opengl_test)

find_package(Qt6 COMPONENTS OpenGL OpenGLWidgets REQUIRED QUIET)

link_libraries(Qt6::OpenGL Qt6::OpenGLWidgets)

add_executable(“proj1” main.cpp)

Qt OpenGL adds (WIN32, _ENABLE_EXTENDED_ALIGNED_STORAGE, WIN64, and _WIN64) compile definitions to Proj1, how can I prevent this from happening?

No, there’s no way to drop them (without also dropping -I flags by wrapping the target in $<LINK_ONLY>). File an issue with Qt to not add those as PUBLIC compile definitions.

1 Like