Commit bb42e1ed authored by Cristian Adam's avatar Cristian Adam

ObjC: Add OBJC/OBJCXX flags to Xcode projects

Fixes: #19936
parent 5e328c6d
......@@ -2220,7 +2220,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
// extract C++ stdlib
for (auto const& language : languages) {
if (language != "CXX") {
if (language != "CXX" && language != "OBJCXX") {
continue;
}
std::string& flags = cflags[language];
......@@ -2229,8 +2229,11 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
this->ExtractFlagRegex("(^| )(-stdlib=[^ ]+)( |$)", 2, flags);
if (stdlib.size() > 8) {
const auto cxxLibrary = stdlib.substr(8);
buildSettings->AddAttribute("CLANG_CXX_LIBRARY",
this->CreateString(cxxLibrary));
if (language == "CXX" ||
!buildSettings->GetObject("CLANG_CXX_LIBRARY")) {
buildSettings->AddAttribute("CLANG_CXX_LIBRARY",
this->CreateString(cxxLibrary));
}
}
}
......@@ -2244,16 +2247,22 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
this->CreateString("NO"));
buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
this->CreateString("NO"));
for (auto const& language : languages) {
std::string flags = cflags[language] + " " + defFlags;
if (language == "CXX") {
buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
this->CreateString(flags));
if (language == "CXX" || language == "OBJCXX") {
if (language == "CXX" ||
!buildSettings->GetObject("OTHER_CPLUSPLUSFLAGS")) {
buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
this->CreateString(flags));
}
} else if (language == "Fortran") {
buildSettings->AddAttribute("IFORT_OTHER_FLAGS",
this->CreateString(flags));
} else if (language == "C") {
buildSettings->AddAttribute("OTHER_CFLAGS", this->CreateString(flags));
} else if (language == "C" || language == "OBJC") {
if (language == "C" || !buildSettings->GetObject("OTHER_CFLAGS")) {
buildSettings->AddAttribute("OTHER_CFLAGS", this->CreateString(flags));
}
} else if (language == "Swift") {
buildSettings->AddAttribute("OTHER_SWIFT_FLAGS",
this->CreateString(flags));
......
......@@ -54,6 +54,20 @@ endfunction()
XcodeDependOnZeroCheck()
function(XcodeObjcxxFlags testName)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(${testName})
run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
endfunction()
XcodeObjcxxFlags(XcodeObjcFlags)
XcodeObjcxxFlags(XcodeObjcxxFlags)
# Isolate device tests from host architecture selection.
unset(ENV{CMAKE_OSX_ARCHITECTURES})
......
cmake_minimum_required(VERSION 3.15)
project(objctest LANGUAGES C OBJC)
include(CheckOBJCCompilerFlag)
check_objc_compiler_flag(-fobjc-arc HAVE_OBJC_ARC)
if(HAVE_OBJC_ARC)
add_compile_options(-fobjc-arc)
add_compile_definitions(HAVE_OBJC_ARC)
endif()
add_library(myfuncs STATIC myfuncs.m)
cmake_minimum_required(VERSION 3.15)
project(objcxxtest LANGUAGES CXX OBJCXX)
include(CheckOBJCXXCompilerFlag)
check_objcxx_compiler_flag(-fobjc-arc HAVE_OBJC_ARC)
if(HAVE_OBJC_ARC)
add_compile_options(-fobjc-arc)
add_compile_definitions(HAVE_OBJC_ARC)
endif()
add_library(myfuncs STATIC myfuncs.mm)
#if defined(HAVE_OBJC_ARC) && ! __has_feature(objc_arc)
#error THIS CODE MUST BE COMPILED WITH ARC ENABLED!
#endif
#if defined(HAVE_OBJC_ARC) && ! __has_feature(objc_arc)
#error THIS CODE MUST BE COMPILED WITH ARC ENABLED!
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment