summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-11-12 14:43:00 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-11-12 14:43:11 (GMT)
commit43ef704d51af61427ea856634731acd031bda646 (patch)
tree3340878402479bbfb05361a643b3cd7e8a66ff31
parent44f4042f89900229e3442eb45b1196ece63c8652 (diff)
parentbb42e1ed43cc56581e7d16ec93a417b7971d108b (diff)
downloadCMake-43ef704d51af61427ea856634731acd031bda646.zip
CMake-43ef704d51af61427ea856634731acd031bda646.tar.gz
CMake-43ef704d51af61427ea856634731acd031bda646.tar.bz2
Merge topic 'objc-xcode-flags'
bb42e1ed43 ObjC: Add OBJC/OBJCXX flags to Xcode projects Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4020
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx25
-rw-r--r--Tests/RunCMake/XcodeProject/RunCMakeTest.cmake14
-rw-r--r--Tests/RunCMake/XcodeProject/XcodeObjcFlags.cmake12
-rw-r--r--Tests/RunCMake/XcodeProject/XcodeObjcxxFlags.cmake12
-rw-r--r--Tests/RunCMake/XcodeProject/myfuncs.m3
-rw-r--r--Tests/RunCMake/XcodeProject/myfuncs.mm3
6 files changed, 61 insertions, 8 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 998ffa6..df30e7e 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -2223,7 +2223,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];
@@ -2232,8 +2232,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));
+ }
}
}
@@ -2247,16 +2250,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));
diff --git a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
index 9e82841..6ecf3f2 100644
--- a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
+++ b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
@@ -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})
diff --git a/Tests/RunCMake/XcodeProject/XcodeObjcFlags.cmake b/Tests/RunCMake/XcodeProject/XcodeObjcFlags.cmake
new file mode 100644
index 0000000..4840276
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeObjcFlags.cmake
@@ -0,0 +1,12 @@
+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)
diff --git a/Tests/RunCMake/XcodeProject/XcodeObjcxxFlags.cmake b/Tests/RunCMake/XcodeProject/XcodeObjcxxFlags.cmake
new file mode 100644
index 0000000..0ad942f
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/XcodeObjcxxFlags.cmake
@@ -0,0 +1,12 @@
+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)
diff --git a/Tests/RunCMake/XcodeProject/myfuncs.m b/Tests/RunCMake/XcodeProject/myfuncs.m
new file mode 100644
index 0000000..742ba8e
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/myfuncs.m
@@ -0,0 +1,3 @@
+#if defined(HAVE_OBJC_ARC) && ! __has_feature(objc_arc)
+#error THIS CODE MUST BE COMPILED WITH ARC ENABLED!
+#endif
diff --git a/Tests/RunCMake/XcodeProject/myfuncs.mm b/Tests/RunCMake/XcodeProject/myfuncs.mm
new file mode 100644
index 0000000..742ba8e
--- /dev/null
+++ b/Tests/RunCMake/XcodeProject/myfuncs.mm
@@ -0,0 +1,3 @@
+#if defined(HAVE_OBJC_ARC) && ! __has_feature(objc_arc)
+#error THIS CODE MUST BE COMPILED WITH ARC ENABLED!
+#endif