build: add NS3_CCACHE and NS3_FAST_LINKERS switches to disable ccache and lld/mold usage

This commit is contained in:
Gabriel Ferreira
2022-11-30 12:35:51 -03:00
parent 18225243f2
commit b59565aa9b
2 changed files with 46 additions and 39 deletions

View File

@@ -3,19 +3,6 @@
# ##############################################################################
cmake_minimum_required(VERSION 3.10..3.10)
# Use ccache if available
mark_as_advanced(CCACHE)
find_program(CCACHE ccache)
if(NOT ("${CCACHE}" STREQUAL "CCACHE-NOTFOUND"))
message(STATUS "CCache is enabled.")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
execute_process(
COMMAND
${CCACHE} --set-config
sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime
)
endif()
# ##############################################################################
# Project name #
# ##############################################################################
@@ -66,6 +53,8 @@ option(NS3_NETANIM "Build netanim" OFF)
# other options
option(NS3_ENABLE_BUILD_VERSION "Embed version info into libraries" OFF)
option(NS3_CCACHE "Use Ccache to speed up recompilation" ON)
option(NS3_FAST_LINKERS "Use Mold or LLD to speed up linking if available" ON)
option(NS3_GSL "Build with GSL support" ON)
option(NS3_GTK3 "Build with GTK3 support" ON)
option(NS3_LINK_TIME_OPTIMIZATION "Build with link-time optimization" OFF)
@@ -111,6 +100,21 @@ set(NS3_FILTER_MODULE_EXAMPLES_AND_TESTS
"List of modules that should have their examples and tests built (e.g. lte;wifi)"
)
if(${NS3_CCACHE})
# Use ccache if available
mark_as_advanced(CCACHE)
find_program(CCACHE ccache)
if(NOT ("${CCACHE}" STREQUAL "CCACHE-NOTFOUND"))
message(STATUS "CCache is enabled.")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
execute_process(
COMMAND
${CCACHE} --set-config
sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime
)
endif()
endif()
# Include macros used below
include(build-support/macros-and-definitions.cmake)

View File

@@ -240,33 +240,35 @@ if(${CLANG} AND APPLE)
set(STATIC_LINK_FLAGS)
endif()
# Search for faster linkers mold and lld, and use them if available
mark_as_advanced(MOLD LLD)
find_program(MOLD mold)
find_program(LLD ld.lld)
if(${NS3_FAST_LINKERS})
# Search for faster linkers mold and lld, and use them if available
mark_as_advanced(MOLD LLD)
find_program(MOLD mold)
find_program(LLD ld.lld)
# USING_FAST_LINKER will be defined if a fast linker is being used and its
# content will correspond to the fast linker name
# USING_FAST_LINKER will be defined if a fast linker is being used and its
# content will correspond to the fast linker name
# Mold support was added in GCC 12.1.0
if(NOT USING_FAST_LINKER
AND NOT (${MOLD} STREQUAL "MOLD-NOTFOUND")
AND LINUX
AND ${GCC}
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.1.0)
)
set(USING_FAST_LINKER MOLD)
add_link_options("-fuse-ld=mold")
endif()
# Mold support was added in GCC 12.1.0
if(NOT USING_FAST_LINKER
AND NOT (${MOLD} STREQUAL "MOLD-NOTFOUND")
AND LINUX
AND ${GCC}
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.1.0)
)
set(USING_FAST_LINKER MOLD)
add_link_options("-fuse-ld=mold")
endif()
if(NOT USING_FAST_LINKER AND NOT (${LLD} STREQUAL "LLD-NOTFOUND")
AND (${GCC} OR ${CLANG})
)
set(USING_FAST_LINKER LLD)
add_link_options("-fuse-ld=lld")
if(WIN32)
# Clear unsupported linker flags on Windows
set(LIB_AS_NEEDED_PRE)
if(NOT USING_FAST_LINKER AND NOT (${LLD} STREQUAL "LLD-NOTFOUND")
AND (${GCC} OR ${CLANG})
)
set(USING_FAST_LINKER LLD)
add_link_options("-fuse-ld=lld")
if(WIN32)
# Clear unsupported linker flags on Windows
set(LIB_AS_NEEDED_PRE)
endif()
endif()
endif()
@@ -1331,8 +1333,9 @@ macro(process_options)
"Clang-tidy is incompatible with precompiled headers. Continuing without them."
)
elseif(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
# If ccache was not found, we can continue with precompiled headers
if("${CCACHE}" STREQUAL "CCACHE-NOTFOUND")
# If ccache is not enable or was not found, we can continue with
# precompiled headers
if((NOT ${NS3_CCACHE}) OR ("${CCACHE}" STREQUAL "CCACHE-NOTFOUND"))
set(PRECOMPILE_HEADERS_ENABLED ON)
message(STATUS "Precompiled headers were enabled")
else()