1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-26 13:10:46 +03:00

Create config.h

This commit is contained in:
Rui Ueyama 2022-10-22 14:30:12 +08:00
parent 7db72a871c
commit 0d7a5a7284
5 changed files with 15 additions and 15 deletions

View File

@ -57,8 +57,6 @@ endif()
add_executable(mold) add_executable(mold)
target_compile_features(mold PRIVATE cxx_std_20) target_compile_features(mold PRIVATE cxx_std_20)
target_compile_definitions(mold PRIVATE
"LIBDIR=\"${CMAKE_INSTALL_FULL_LIBDIR}\"")
target_link_libraries(mold PRIVATE ${CMAKE_DL_LIBS}) target_link_libraries(mold PRIVATE ${CMAKE_DL_LIBS})
if(NOT "${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC") if(NOT "${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
@ -223,9 +221,6 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv64|armv6)")
target_link_libraries(mold PRIVATE atomic) target_link_libraries(mold PRIVATE atomic)
endif() endif()
set_property(SOURCE main.cc APPEND PROPERTY
COMPILE_DEFINITIONS "MOLD_VERSION=\"${CMAKE_PROJECT_VERSION}\"")
# Create a .cc file containing the current git hash for `mold --version`. # Create a .cc file containing the current git hash for `mold --version`.
add_custom_target(git_hash add_custom_target(git_hash
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
@ -238,6 +233,10 @@ add_custom_target(git_hash
add_dependencies(mold git_hash) add_dependencies(mold git_hash)
# Create config.h file
configure_file(config.h.in config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# Almost all functions are template in mold which take a target type # Almost all functions are template in mold which take a target type
# (e.g. X86_64) as its type parameter. Since we suport more than 10 # (e.g. X86_64) as its type parameter. Since we suport more than 10
# targets, compiling a single source file for all the targets is very # targets, compiling a single source file for all the targets is very
@ -331,10 +330,11 @@ target_sources(mold PRIVATE
) )
# Add frequently included header files for pre-compiling. # Add frequently included header files for pre-compiling.
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0") # for target_precompile_headers # target_precompile_headers is supported by CMake 3.16.0 or newer.
target_precompile_headers(mold PRIVATE if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/elf/mold.h>" target_precompile_headers(mold PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/macho/mold.h>") "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/elf/mold.h>"
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/macho/mold.h>")
endif() endif()
include(CTest) include(CTest)

2
config.h.in Normal file
View File

@ -0,0 +1,2 @@
#define MOLD_VERSION "@mold_VERSION@"
#define MOLD_LIBDIR "@CMAKE_INSTALL_FULL_LIBDIR@"

View File

@ -1,6 +1,7 @@
#if !defined(_WIN32) && !defined(__APPLE__) #if !defined(_WIN32) && !defined(__APPLE__)
#include "mold.h" #include "mold.h"
#include "config.h"
#include <filesystem> #include <filesystem>
#include <signal.h> #include <signal.h>
@ -66,13 +67,11 @@ static std::string find_dso(Context<E> &ctx, std::filesystem::path self) {
if (std::filesystem::is_regular_file(path, ec) && !ec) if (std::filesystem::is_regular_file(path, ec) && !ec)
return path; return path;
#ifdef LIBDIR // If not found, search $(MOLD_LIBDIR)/mold, which is /usr/local/lib/mold
// If not found, search $(LIBDIR)/mold, which is /usr/local/lib/mold
// by default. // by default.
path = LIBDIR "/mold/mold-wrapper.so"; path = MOLD_LIBDIR "/mold/mold-wrapper.so";
if (std::filesystem::is_regular_file(path, ec) && !ec) if (std::filesystem::is_regular_file(path, ec) && !ec)
return path; return path;
#endif
// Look for ../lib/mold/mold-wrapper.so // Look for ../lib/mold/mold-wrapper.so
path = self.parent_path() / "../lib/mold/mold-wrapper.so"; path = self.parent_path() / "../lib/mold/mold-wrapper.so";

View File

@ -1,4 +1,5 @@
#include "mold.h" #include "mold.h"
#include "config.h"
#include <cstring> #include <cstring>
#include <filesystem> #include <filesystem>

View File

@ -1,5 +1,3 @@
cmake_minimum_required(VERSION 3.9)
# Get a git hash value. We do not want to use git command here # Get a git hash value. We do not want to use git command here
# because we don't want to make git a build-time dependency. # because we don't want to make git a build-time dependency.
if(EXISTS "${SOURCE_DIR}/.git/HEAD") if(EXISTS "${SOURCE_DIR}/.git/HEAD")