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:
parent
7db72a871c
commit
0d7a5a7284
@ -57,8 +57,6 @@ endif()
|
||||
|
||||
add_executable(mold)
|
||||
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})
|
||||
|
||||
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)
|
||||
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`.
|
||||
add_custom_target(git_hash
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
@ -238,6 +233,10 @@ add_custom_target(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
|
||||
# (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
|
||||
@ -331,10 +330,11 @@ target_sources(mold PRIVATE
|
||||
)
|
||||
|
||||
# Add frequently included header files for pre-compiling.
|
||||
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0") # for target_precompile_headers
|
||||
target_precompile_headers(mold PRIVATE
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/elf/mold.h>"
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/macho/mold.h>")
|
||||
# target_precompile_headers is supported by CMake 3.16.0 or newer.
|
||||
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
|
||||
target_precompile_headers(mold PRIVATE
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/elf/mold.h>"
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/macho/mold.h>")
|
||||
endif()
|
||||
|
||||
include(CTest)
|
||||
|
2
config.h.in
Normal file
2
config.h.in
Normal file
@ -0,0 +1,2 @@
|
||||
#define MOLD_VERSION "@mold_VERSION@"
|
||||
#define MOLD_LIBDIR "@CMAKE_INSTALL_FULL_LIBDIR@"
|
@ -1,6 +1,7 @@
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
|
||||
#include "mold.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <filesystem>
|
||||
#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)
|
||||
return path;
|
||||
|
||||
#ifdef LIBDIR
|
||||
// If not found, search $(LIBDIR)/mold, which is /usr/local/lib/mold
|
||||
// If not found, search $(MOLD_LIBDIR)/mold, which is /usr/local/lib/mold
|
||||
// by default.
|
||||
path = LIBDIR "/mold/mold-wrapper.so";
|
||||
path = MOLD_LIBDIR "/mold/mold-wrapper.so";
|
||||
if (std::filesystem::is_regular_file(path, ec) && !ec)
|
||||
return path;
|
||||
#endif
|
||||
|
||||
// Look for ../lib/mold/mold-wrapper.so
|
||||
path = self.parent_path() / "../lib/mold/mold-wrapper.so";
|
||||
|
1
main.cc
1
main.cc
@ -1,4 +1,5 @@
|
||||
#include "mold.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
|
@ -1,5 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.9)
|
||||
|
||||
# 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.
|
||||
if(EXISTS "${SOURCE_DIR}/.git/HEAD")
|
||||
|
Loading…
Reference in New Issue
Block a user