Skip to content

Commit

Permalink
GH-40602: [C++] Move mold linker flags to variables (#40603)
Browse files Browse the repository at this point in the history
### Rationale for this change

Move the mold linker flags to the CMake `CMAKE_*_LINKER_FLAGS` variables. This is the more correct place to add them as they will only be used during linking, it would invalidate any [s]ccache less frequently if changing linkers and I think it is more clear/correct.

### What changes are included in this PR?

Moving the mold linker flags from the `CMAKE_*_FLAGS` to `CMAKE_*_LINKER_FLAGS`.

### Are these changes tested?

Existing tests and validation would cover these changes and the result is essentially the same as before.

### Are there any user-facing changes?

No
* GitHub Issue: #40602

Lead-authored-by: Marcus D. Hanwell <marcus@voltrondata.com>
Co-authored-by: Marcus D. Hanwell <mhanwell@gmail.com>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
cryos and kou authored Mar 19, 2024
1 parent 6d5cfb2 commit bb9f229
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cpp/cmake_modules/SetupCxxFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -629,23 +629,27 @@ if(NOT WIN32 AND NOT APPLE)
if(ARROW_USE_MOLD)
find_program(LD_MOLD ld.mold)
if(LD_MOLD)
unset(MOLD_LINKER_FLAGS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.1.0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=mold")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=mold")
set(MOLD_LINKER_FLAGS "-fuse-ld=mold")
message(STATUS "Using optional mold linker")
else()
message(STATUS "Need GCC 12.1.0 or later to use mold linker: ${CMAKE_CXX_COMPILER_VERSION}"
)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --ld-path=${LD_MOLD}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --ld-path=${LD_MOLD}")
set(MOLD_LINKER_FLAGS "--ld-path=${LD_MOLD}")
message(STATUS "Using optional mold linker")
else()
message(STATUS "Using the default linker because compiler doesn't support mold: ${CMAKE_CXX_COMPILER_ID}"
)
endif()
if(MOLD_LINKER_FLAGS)
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${MOLD_LINKER_FLAGS}")
string(APPEND CMAKE_MODULE_LINKER_FLAGS " ${MOLD_LINKER_FLAGS}")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " ${MOLD_LINKER_FLAGS}")
endif()
else()
message(STATUS "Using the default linker because mold isn't found")
endif()
Expand Down

0 comments on commit bb9f229

Please sign in to comment.