summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2020-10-22 14:23:47 +0200
committerFlorin Coras <florin.coras@gmail.com>2020-11-05 20:51:03 +0000
commitaf7892c08b2d4984f4c93bb8c7cc07aec36b5055 (patch)
tree2d09c5297cc8b1e38f3ec7a755054e88957ec9e0 /src
parent066cd812374460e5ca8be9a88f494fe3f5bf911e (diff)
build: link time optimization for release builds
Type: improvement Change-Id: I0e24f1d2ad5c7a11a8bd40125428f86aca867bec Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt13
-rw-r--r--src/cmake/library.cmake9
-rw-r--r--src/vppinfra/CMakeLists.txt1
3 files changed, 21 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0d971fd8ebc..6fc243ca4d2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,13 +11,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+cmake_minimum_required(VERSION 3.10)
set(CMAKE_C_COMPILER_NAMES clang-11 clang-10 clang-9 gcc-10 gcc-9 cc)
project(vpp C)
include(CheckCCompilerFlag)
+include(CheckIPOSupported)
include(cmake/misc.cmake)
include(cmake/cpu.cmake)
include(cmake/ccache.cmake)
@@ -106,6 +107,16 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
HELPSTRING "Build type - valid options are: ${BUILD_TYPES}")
##############################################################################
+# link time optimizations
+##############################################################################
+if (CMAKE_BUILD_TYPE_UC STREQUAL "RELEASE")
+ check_ipo_supported(RESULT _result)
+ if (_result)
+ option(VPP_USE_LTO "Link time optimization of release binaries" ON)
+ endif()
+endif()
+
+##############################################################################
# sanitizers
##############################################################################
diff --git a/src/cmake/library.cmake b/src/cmake/library.cmake
index 06248a57aa3..a5b6c76d2d1 100644
--- a/src/cmake/library.cmake
+++ b/src/cmake/library.cmake
@@ -13,7 +13,7 @@
macro(add_vpp_library lib)
cmake_parse_arguments(ARG
- ""
+ "LTO"
"COMPONENT"
"SOURCES;MULTIARCH_SOURCES;API_FILES;LINK_LIBRARIES;INSTALL_HEADERS;DEPENDS"
${ARGN}
@@ -38,6 +38,13 @@ macro(add_vpp_library lib)
COMPONENT ${ARG_COMPONENT}
)
+ if (ARG_LTO AND VPP_USE_LTO)
+ set_property(TARGET ${lib} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
+ target_compile_options (${lib} PRIVATE "-ffunction-sections")
+ target_compile_options (${lib} PRIVATE "-fdata-sections")
+ target_link_libraries (${lib} "-Wl,--gc-sections")
+ endif()
+
if(ARG_MULTIARCH_SOURCES)
vpp_library_set_multiarch_sources(${lib} "${ARG_DEPENDS}" ${ARG_MULTIARCH_SOURCES})
endif()
diff --git a/src/vppinfra/CMakeLists.txt b/src/vppinfra/CMakeLists.txt
index e0ae662e4ba..a670181732e 100644
--- a/src/vppinfra/CMakeLists.txt
+++ b/src/vppinfra/CMakeLists.txt
@@ -198,6 +198,7 @@ add_vpp_library(vppinfra
LINK_LIBRARIES m
INSTALL_HEADERS ${VPPINFRA_HEADERS}
COMPONENT libvppinfra
+ LTO
)
##############################################################################
>314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434