Set default CMAKE_BUILD_TYPE to Release and implement CMAKE_BUILD_TYPE FastBuild
* Sets the default `CMAKE_BUILD_TYPE` to `Release`
* Implements a custom build type `FastBuild`
* If the `CMAKE_BUILD_TYPE` is set to `FastBuild`, for LLVM the `CMAKE_BUILD_TYPE` is set to `Relase`
Closes https://github.com/google/iree/pull/474
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/iree/pull/474 from marbre:cmake_build_type be143f166341acc4306d36a8e249ca64d2ac1298
PiperOrigin-RevId: 289866898
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0f0cfae..1ecbe88 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,6 +66,23 @@
string(JOIN " " CMAKE_CXX_FLAGS ${IREE_DEFAULT_COPTS})
+set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE)
+set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE)
+set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE)
+set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE)
+mark_as_advanced(
+ CMAKE_CXX_FLAGS_FASTBUILD
+ CMAKE_C_FLAGS_FASTBUILD
+ CMAKE_EXE_LINKER_FLAGS_FASTBUILD
+ CMAKE_SHARED_LINKER_FLAGS_FASTBUILD
+)
+
+set(DEFAULT_CMAKE_BUILD_TYPE "Release")
+if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ message(STATUS "No build type selected, default to ${DEFAULT_CMAKE_BUILD_TYPE}")
+ set(CMAKE_BUILD_TYPE "${DEFAULT_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE)
+endif()
+
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
#-------------------------------------------------------------------------------
@@ -94,7 +111,18 @@
add_subdirectory(third_party/vulkan_headers EXCLUDE_FROM_ALL)
if(${IREE_ENABLE_LLVM})
+ # If CMAKE_BUILD_TYPE is FastBuild, set to Debug for llvm
+ set(_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
+ string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
+ if(NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
+ set(CMAKE_BUILD_TYPE "Debug")
+ endif()
+
add_subdirectory(third_party/llvm-project/llvm EXCLUDE_FROM_ALL)
+
+ # Reset CMAKE_BUILD_TYPE to its previous setting
+ set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE)
+
include(external_tablegen_library)
endif()
diff --git a/build_tools/scripts/cmake_build.sh b/build_tools/scripts/cmake_build.sh
index 006990a..e33a961 100755
--- a/build_tools/scripts/cmake_build.sh
+++ b/build_tools/scripts/cmake_build.sh
@@ -26,6 +26,6 @@
cd ${ROOT_DIR?}
rm -rf build/
mkdir build && cd build
-"$CMAKE_BIN" -DIREE_BUILD_COMPILER=ON -DIREE_BUILD_TESTS=ON -DIREE_BUILD_SAMPLES=OFF -DIREE_BUILD_DEBUGGER=OFF ..
+"$CMAKE_BIN" -DCMAKE_BUILD_TYPE=FastBuild -DIREE_BUILD_COMPILER=ON -DIREE_BUILD_TESTS=ON -DIREE_BUILD_SAMPLES=OFF -DIREE_BUILD_DEBUGGER=OFF ..
"$CMAKE_BIN" --build .
rm -rf build/