mirror of
https://github.com/google/benchmark.git
synced 2024-12-25 20:10:13 +08:00
* CMake: implement LTO for clang. Fixes #478 * LTO: add basic docs about required executables.
This commit is contained in:
parent
eae42212ce
commit
c45f01866b
@ -19,6 +19,7 @@ option(BENCHMARK_BUILD_32_BITS "Build a 32 bit version of the library." OFF)
|
||||
option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" ON)
|
||||
|
||||
# Make sure we can import out CMake functions
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
# Read the git tags to determine the project version
|
||||
@ -132,6 +133,8 @@ else()
|
||||
if (GCC_RANLIB)
|
||||
set(CMAKE_RANLIB ${GCC_RANLIB})
|
||||
endif()
|
||||
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
||||
include(llvm-toolchain)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -848,6 +848,9 @@ To enable link-time optimisation, use
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_LTO=true
|
||||
```
|
||||
|
||||
If you are using gcc, you might need to set `GCC_AR` and `GCC_RANLIB` cmake cache variables, if autodetection fails.
|
||||
If you are using clang, you may need to set `LLVMAR_EXECUTABLE`, `LLVMNM_EXECUTABLE` and `LLVMRANLIB_EXECUTABLE` cmake cache variables.
|
||||
|
||||
## Linking against the library
|
||||
When using gcc, it is necessary to link against pthread to avoid runtime exceptions.
|
||||
This is due to how gcc implements std::thread.
|
||||
|
16
cmake/Modules/FindLLVMAr.cmake
Normal file
16
cmake/Modules/FindLLVMAr.cmake
Normal file
@ -0,0 +1,16 @@
|
||||
include(FeatureSummary)
|
||||
|
||||
find_program(LLVMAR_EXECUTABLE
|
||||
NAMES llvm-ar
|
||||
DOC "The llvm-ar executable"
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(LLVMAr
|
||||
DEFAULT_MSG
|
||||
LLVMAR_EXECUTABLE)
|
||||
|
||||
SET_PACKAGE_PROPERTIES(LLVMAr PROPERTIES
|
||||
URL https://llvm.org/docs/CommandGuide/llvm-ar.html
|
||||
DESCRIPTION "create, modify, and extract from archives"
|
||||
)
|
16
cmake/Modules/FindLLVMNm.cmake
Normal file
16
cmake/Modules/FindLLVMNm.cmake
Normal file
@ -0,0 +1,16 @@
|
||||
include(FeatureSummary)
|
||||
|
||||
find_program(LLVMNM_EXECUTABLE
|
||||
NAMES llvm-nm
|
||||
DOC "The llvm-nm executable"
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(LLVMNm
|
||||
DEFAULT_MSG
|
||||
LLVMNM_EXECUTABLE)
|
||||
|
||||
SET_PACKAGE_PROPERTIES(LLVMNm PROPERTIES
|
||||
URL https://llvm.org/docs/CommandGuide/llvm-nm.html
|
||||
DESCRIPTION "list LLVM bitcode and object file’s symbol table"
|
||||
)
|
15
cmake/Modules/FindLLVMRanLib.cmake
Normal file
15
cmake/Modules/FindLLVMRanLib.cmake
Normal file
@ -0,0 +1,15 @@
|
||||
include(FeatureSummary)
|
||||
|
||||
find_program(LLVMRANLIB_EXECUTABLE
|
||||
NAMES llvm-ranlib
|
||||
DOC "The llvm-ranlib executable"
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(LLVMRanLib
|
||||
DEFAULT_MSG
|
||||
LLVMRANLIB_EXECUTABLE)
|
||||
|
||||
SET_PACKAGE_PROPERTIES(LLVMRanLib PROPERTIES
|
||||
DESCRIPTION "generate index for LLVM archive"
|
||||
)
|
8
cmake/llvm-toolchain.cmake
Normal file
8
cmake/llvm-toolchain.cmake
Normal file
@ -0,0 +1,8 @@
|
||||
find_package(LLVMAr REQUIRED)
|
||||
set(CMAKE_AR "${LLVMAR_EXECUTABLE}" CACHE FILEPATH "" FORCE)
|
||||
|
||||
find_package(LLVMNm REQUIRED)
|
||||
set(CMAKE_NM "${LLVMNM_EXECUTABLE}" CACHE FILEPATH "" FORCE)
|
||||
|
||||
find_package(LLVMRanLib REQUIRED)
|
||||
set(CMAKE_RANLIB "${LLVMRANLIB_EXECUTABLE}" CACHE FILEPATH "" FORCE)
|
Loading…
Reference in New Issue
Block a user