From 5ee2ebfb4fd8b6ac3ad41c4e8eec87cc0f50f186 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 2 Feb 2025 20:32:24 +0100 Subject: [PATCH] build: Fix addXXXFlag functions for interface targets --- cmake/build_helpers.cmake | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index 14a4caed1..9cc5e3664 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -10,11 +10,21 @@ if (POLICY CMP0177) cmake_policy(SET CMP0177 OLD) endif() +function(getTarget target type) + get_target_property(TARGET_TYPE ${target} TYPE) + if (${TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY") + set(${type} INTERFACE PARENT_SCOPE) + else() + set(${type} PRIVATE PARENT_SCOPE) + endif() +endfunction() + function(addCFlag) if (ARGC EQUAL 1) add_compile_options($<$:${ARGV0}>) elseif (ARGC EQUAL 2) - target_compile_options(${ARGV1} PRIVATE $<$:${ARGV0}>) + getTarget(${ARGV1} TYPE) + target_compile_options(${ARGV1} ${TYPE} $<$:${ARGV0}>) endif() endfunction() @@ -22,7 +32,8 @@ function(addCXXFlag) if (ARGC EQUAL 1) add_compile_options($<$:${ARGV0}>) elseif (ARGC EQUAL 2) - target_compile_options(${ARGV1} PRIVATE $<$:${ARGV0}>) + getTarget(${ARGV1} TYPE) + target_compile_options(${ARGV1} ${TYPE} $<$:${ARGV0}>) endif() endfunction() @@ -30,7 +41,8 @@ function(addObjCFlag) if (ARGC EQUAL 1) add_compile_options($<$:${ARGV0}>) elseif (ARGC EQUAL 2) - target_compile_options(${ARGV1} PRIVATE $<$:${ARGV0}>) + getTarget(${ARGV1} TYPE) + target_compile_options(${ARGV1} ${TYPE} $<$:${ARGV0}>) endif() endfunction()