From ca1751638e571b2506ff4456e4a20982fb1ae461 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 19 Aug 2024 09:54:31 -0400 Subject: [PATCH] CPP 20 flags (#296) Sigh. CPP20 has .u8string and .string not compatible. Apply the flag in a few places we were missing to fix this with the appropriate generator expression --- CMakeLists.txt | 24 +++++++++++++++++------- cmake/shared_prologue.cmake | 10 ++++++++-- cmake/wrap_auv2.cmake | 1 + cmake/wrap_standalone.cmake | 3 +-- cmake/wrap_vst3.cmake | 5 ++++- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e5608fc..31b7844f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,8 +24,13 @@ cmake_minimum_required(VERSION 3.21) cmake_policy(SET CMP0091 NEW) -set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13 CACHE STRING "Minimum macOS version") -set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build Universal Always") +if (NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET) + message(STATUS "[clap-wrapper]: OSX_DEPLOYEMNT_TARGET is undefined. Setting to 10.13") + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13 CACHE STRING "Minimum macOS version") +endif() +if (NOT DEFINED CMAKE_OSX_ARCHITECTURES) + message(STATUS "[clap-wrapper]: CMAKE_OSX_ARCHITECTURES is not set. Using native build for clap wrapper") +endif() if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) if (WIN32) message(STATUS "CMAKE_MSVC_RUNTIME_LIBRARY not defined. Setting to static link") @@ -52,13 +57,18 @@ if (APPLE) enable_language(OBJCXX) endif() -if (DEFINED CLAP_WRAPPER_CXX_STANDARD) - set(CMAKE_CXX_STANDARD ${CLAP_WRAPPER_CXX_STANDARD}) -else() - set(CMAKE_CXX_STANDARD 17) +if (PROJECT_IS_TOP_LEVEL) + if (DEFINED CLAP_WRAPPER_CXX_STANDARD) + set(CMAKE_CXX_STANDARD ${CLAP_WRAPPER_CXX_STANDARD}) + else() + if (NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) + elseif ( ${CMAKE_CXX_STANDARD} VERSION_LESS 17) + message(WARNING "CMAKE_CXX_STANDARD of ${CMAKE_CXX_STANDARD} < 17 not well tested") + endif() + endif() endif() message(STATUS "clap-wrapper: Building with C++ standard ${CMAKE_CXX_STANDARD}") - set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_OBJC_VISIBILITY_PRESET hidden) diff --git a/cmake/shared_prologue.cmake b/cmake/shared_prologue.cmake index 16c444d9..f527ade3 100644 --- a/cmake/shared_prologue.cmake +++ b/cmake/shared_prologue.cmake @@ -34,6 +34,12 @@ endif() # Compiler options for warnings, errors etc add_library(clap-wrapper-compile-options INTERFACE) +add_library(clap-wrapper-compile-options-public INTERFACE) +target_link_libraries(clap-wrapper-compile-options INTERFACE clap-wrapper-compile-options-public) + +# This is useful for debugging cmake link problems2 +# target_compile_definitions(clap-wrapper-compile-options INTERFACE -DTHIS_BUILD_USED_CLAP_WRAPPER_COMPILE_OPTIONS=1) +# target_compile_definitions(clap-wrapper-compile-options-public INTERFACE -DTHIS_BUILD_USED_CLAP_WRAPPER_COMPILE_OPTIONS_PUBLIC=1) add_library(clap-wrapper-sanitizer-options INTERFACE) target_compile_options(clap-wrapper-compile-options INTERFACE -D${CLAP_WRAPPER_PLATFORM}=1 -DCLAP_WRAPPER_VERSION="${CLAP_WRAPPER_VERSION}") @@ -58,7 +64,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") endif() if (${CMAKE_CXX_STANDARD} GREATER_EQUAL 20) message(STATUS "clap-wrapper: Turning off char8_t c++20 changes") - target_compile_options(clap-wrapper-compile-options INTERFACE -fno-char8_t) + target_compile_options(clap-wrapper-compile-options-public INTERFACE -fno-char8_t) endif() if (${CLAP_WRAPPER_ENABLE_SANITIZER}) message(STATUS "clap-wrapper: enabling sanitizer build") @@ -82,7 +88,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(clap-wrapper-compile-options INTERFACE /utf-8) if (${CMAKE_CXX_STANDARD} GREATER_EQUAL 20) message(STATUS "clap-wrapper: Turning off char8_t c++20 changes") - target_compile_options(clap-wrapper-compile-options INTERFACE /Zc:char8_t-) + target_compile_options(clap-wrapper-compile-options-public INTERFACE /Zc:char8_t-) endif() endif() diff --git a/cmake/wrap_auv2.cmake b/cmake/wrap_auv2.cmake index e02bc447..70b64855 100644 --- a/cmake/wrap_auv2.cmake +++ b/cmake/wrap_auv2.cmake @@ -53,6 +53,7 @@ function(target_add_auv2_wrapper) set(bhsc "${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/build-helper/") add_executable(${bhtg} ${bhsc}/build-helper.cpp) target_link_libraries(${bhtg} PRIVATE + clap-wrapper-compile-options clap-wrapper-shared-detail macos_filesystem_support "-framework Foundation" diff --git a/cmake/wrap_standalone.cmake b/cmake/wrap_standalone.cmake index 5c238665..5001cdac 100644 --- a/cmake/wrap_standalone.cmake +++ b/cmake/wrap_standalone.cmake @@ -53,11 +53,11 @@ function(target_add_standalone_wrapper) ) target_link_libraries(${salib} PUBLIC - clap-wrapper-compile-options clap-wrapper-shared-detail base-sdk-rtmidi base-sdk-rtaudio ) + target_link_libraries(${salib} PRIVATE clap-wrapper-compile-options) if (APPLE) target_sources(${salib} PRIVATE) @@ -185,7 +185,6 @@ function(target_add_standalone_wrapper) ) target_link_libraries(${SA_TARGET} PRIVATE - clap-wrapper-compile-options ${salib} ) endfunction(target_add_standalone_wrapper) diff --git a/cmake/wrap_vst3.cmake b/cmake/wrap_vst3.cmake index 2164bc84..5b74e61d 100644 --- a/cmake/wrap_vst3.cmake +++ b/cmake/wrap_vst3.cmake @@ -86,7 +86,10 @@ function(target_add_vst3_wrapper) target_link_libraries(${V3_TARGET}-clap-wrapper-vst3-lib PUBLIC clap base-sdk-vst3) # clap-wrapper-extensions are PUBLIC, so a clap linking the library can access the clap-wrapper-extensions - target_link_libraries(${V3_TARGET}-clap-wrapper-vst3-lib PUBLIC clap-wrapper-extensions clap-wrapper-shared-detail) + target_link_libraries(${V3_TARGET}-clap-wrapper-vst3-lib PUBLIC + clap-wrapper-compile-options-public + clap-wrapper-extensions + clap-wrapper-shared-detail) target_link_libraries(${V3_TARGET}-clap-wrapper-vst3-lib PRIVATE clap-wrapper-compile-options) target_compile_options(${V3_TARGET}-clap-wrapper-vst3-lib PRIVATE