From fc7928a4b74df73024f9d8a9698c9e5b46e18a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Blissing?= Date: Sat, 19 Jun 2021 11:22:31 +0200 Subject: [PATCH] Use target_compile_definitions for custom defines Replace `add_definitions` with `target_compile_definitions` for specified targets. Multiple options are separated using the `separate_arguments` function, which converts any string using space-separated arguments into a semicolon-separated list. --- CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index daf3aa8..6a9e1c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,8 @@ cmake_dependent_option(PUGIXML_BUILD_TESTS "BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF) # Custom build defines -set(PUGIXML_BUILD_DEFINES CACHE STRING "Build defines") +set(PUGIXML_BUILD_DEFINES CACHE STRING "Build defines for custom options") +separate_arguments(PUGIXML_BUILD_DEFINES) option(PUGIXML_BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" OFF) @@ -47,12 +48,6 @@ if (NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) endif() -if (DEFINED PUGIXML_BUILD_DEFINES) - foreach(DEFINE ${PUGIXML_BUILD_DEFINES}) - add_definitions("-D" ${DEFINE}) - endforeach() -endif() - if (PUGIXML_USE_POSTFIX) set(CMAKE_RELWITHDEBINFO_POSTFIX _r) set(CMAKE_MINSIZEREL_POSTFIX _m) @@ -90,6 +85,8 @@ if (PUGIXML_BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS) PUBLIC $) target_compile_definitions(pugixml-shared + PUBLIC + ${PUGIXML_BUILD_DEFINES} PRIVATE $<$:PUGIXML_API=__declspec\(dllexport\)>) target_compile_options(pugixml-shared @@ -110,6 +107,9 @@ if (NOT PUGIXML_BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS) target_include_directories(pugixml-static PUBLIC $) + target_compile_definitions(pugixml-static + PUBLIC + ${PUGIXML_BUILD_DEFINES}) target_compile_options(pugixml-static PRIVATE ${msvc-rt-mtd-shared}