How do I turn on optimization in Xcode? - xcode

I have some Swift code in Xcode 7.2 that runs well, but when I run swift -O main.swift from a command line to run an optimized build of it, my code runs really fast.
How do I turn on code optimization in Xcode? I've tried Product -> Build For -> Running, but that isn't running it at optimized speed. I don't see anything in the project settings for "enable optimization" or "make a release build".

If you select Product -> Scheme -> Edit Scheme, then target the Run scheme, you'll see that it has two build configurations:
Debug: Builds with option -O0 for no optimization.
Release: Builds with option -Os for fastest/smallest optimization.
You can find those values in the project's Build Settings, under Apple LLVM 7.0 - Code Generation, Optimization Level.
One option is to edit the Run scheme's build configuration, which defaults to Debug, and change it to Release.
Another option is to build for profiling which defaults to Release, and will build an optimized version that can be profiled.

Related

Generate a universal binary Xcode project to include two sets of pre-compiled libraries

I am trying to build Blender as a universal binary. Blender has a lot of libraries that can be downloaded completely pre-compiled from their subversion servers. They have one set for x86 and one set for arm64. Blender docs instruct me to run cmake . -B ../build_xcode/ -G "Xcode" which generated a Blender.xcodeproj file and other build files. I noticed that cmake is only picking up the arm64 dependencies, however which might explain why my buils keep failing 90% of the way through. I can build both arm64 and x86_64 builds separately, but not combined. Is there a way to generate this Xcode project to contain both x86 and arm64 dependencies into the same project? I have selected "Standard Architectures" in my build settings so I can confirm it is indeed configured to build a universal binary.
I have checked other posts on this website and most are for PPC/Intel days or are not relevant to my specific issue.

how to make llvm project compile faster?

I'm a llvm new learner
after cmake -S llvm -B build -G Xcode -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi"
I got a llvm project, compiling the project is so slow
How to make it compile faster?
Ninja is an option.
from the build folder, I see libLLVMWindowsManifest.a
i don't need windows platform version.
I just need X86 version
How to make the complier do less job, by avoid compiling unrelated CPU architecture?
-DLLVM_TARGETS_TO_BUILD="X86" is the flag you're looking for. But this alone won't speed up the build time significantly.
Play with CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release/Debug/RelWithDebInfo/MinSizeRel) and see which suits you better. The default for CMAKE_BUILD_TYPE is Debug, and it's very slow.
If you want to debug builds, -DLLVM_OPTIMIZED_TABLEGEN=ON will improve your build time.
And finally, in my experience Ninja builds are slightly faster.

Recursively apply -arch option to all dependencies of a Xcode project

I have a script that build a list of Xcode projects using xcodebuild command line tool. After introduction of universal builds we introduced standard arch's in our xcconfig files and build settings of Xcode projects. Now I want to add an option to build only given arch's. For this I added option -arch . This works well for projects that I build using the list. Problem happens when the system tries to build dependent projects internally and since there the arch is set to universal it fails to build since its dependencies are now either intel only of arm64 only. Is there some argument I can give to xcodebuild to apply -arch option to all its dependencies as well.

CMake INTERPROCEDURAL_OPTIMIZATION for Debug only targets

I have a project which I build both as Debug, Release, and RelWithDebInfo. Starting in CMake 3.9.6 (I think?), the property INTERPROCEDURAL_OPTIMIZATION has been introduced, which includes -flto for the project. However, I don't want to have -flto enabled when compiling for Debug, as it slows down the compile time (and the debugger is less stable in my experience when this feature is enabled).
Currently what I do to enable -flto in CMake is the following:
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_result OUTPUT ipo_err)
if (ipo_result)
message(STATUS "IPO is supported")
set_property(GLOBAL PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()
I wonder whether there's an option to include this feature only when Release is enabled.
Moreover, I'm using the Xcode generator with my project, so I wonder whether this rule (-flto for Debug configuration only) can be applied to the generated .xcodeproj as well?
Use INTERPROCEDURAL_OPTIMIZATION_<CONFIG> instead. Note that these are directory and target properties not global. So you'll have to enable it for the configurations that do use it or you may be able set it to false to deactivate it if enabled.

Qt Creator Windows 10 - "Use jom instead of nmake" not working

I am using Qt version 5.5.1 (but with the 5.6.1 GUI), I am compiling with MSVC++ Compiler 10.0, and I have checked the "Use jom instead of nmake" option in the Options -> Build & Run -> General menu. I am using the latest version of cmake, and the Options -> Build & Run - > Kits -> CMake generator is set to "CodeBlocks - NMake Makefiles". To be honest, I do not know what that last option does, it is just the default.
I am building and running through the QT creator IDE.
If I add -j to the "tool arguments" in Projects -> Build&Run -> Build Steps, then when I try to compile I get the error:
NMAKE:-1: error: U1065: invalid option 'j'
However, I have "Use jom instead of nmake" selected so it should use jom and accept this argument, shouldn't it?
Have I missed out a step?
I cannot find any instructions on how to do this, and the only tutorials I can find to compile using jom are compiling through the command line, which I do not want to do.
edit: This is a different question from How do I utilise all the cores for nmake? as this question is specifically asking why the Jom solution (suggested as an answer in that question) is not working with my set up.
edit 2: I think I may have found out why. This bug report suggests that you need to use the "CodeBlocks - NMake Makefiles JOM" option in the kits -> cmake generator options.This is only supported with QtCreator 4.2.1 and above. However, I have this and it still does not work. I now get the error:
C:\Program Files\CMake\share\cmake-3.8\Modules\CMakeTestCCompiler.cmake:51: error: The C compiler "C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe" is not able to compile a simple test program. It fails with the following output: Change Dir: C:/GIT/CorteX/build/Debug/CMakeFiles/CMakeTmp
Nmake file can be natively used by Jom, thus the cmake generator doesn't not need to be changed from the default nmake generator in the build configuration. The cmake generator is what converts your cmake to your native build system format (e.g. make, or nmake).
(i.e. Projects > Manage Kits ... > Build & Runs > Kits. choose your kit. I have my Cmake generator: set to "CodeBlocks - Nmake Makefiles, Platform: , Toolset: " ).
The only change you then need is to add a custom build step to run jom.exe and disable the default build step, as in Qtcreator JOM setup.
N.b. jom.exe must be in your PATH variable for QtCreator to find it.
jom requires that -j , where you set the number of processes, e.g. jom -j4. You can't use just -j without a count.

Resources