-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
80 lines (70 loc) · 2.17 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
cmake_minimum_required(VERSION 3.16)
project(sloader)
enable_testing()
set(CMAKE_CXX_STANDARD 20)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
set(CUSTOM_LIBC_PATH CACHE PATH "")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(third-party)
set(WITH_GFLAGS
OFF
CACHE INTERNAL "" FORCE)
set(WITH_UNWIND OFF)
set(BUILD_SHARED_LIBS OFF)
add_definitions(-DC10_USE_GLOG=1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/raw_write)
add_library(tls_secure tls_secure.cc)
if(CUSTOM_LIBC_PATH)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=crtbegin.o
OUTPUT_VARIABLE CRT_BEGIN
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=crtend.o
OUTPUT_VARIABLE CRT_END
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libstdc++.a
OUTPUT_VARIABLE LIBSTDCXX
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_executable(sloader sloader.cc dyn_loader.cc libc_mapping.cc sloader_dl.cc
utils.cc sloader_static.map)
target_link_libraries(
sloader
${CUSTOM_LIBC_PATH}/lib/crt1.o
${CUSTOM_LIBC_PATH}/lib/crti.o
${CRT_BEGIN}
${LIBSTDCXX}
${CUSTOM_LIBC_PATH}/lib/libpthread.a
-Wl,--start-group
${CUSTOM_LIBC_PATH}/lib/libc.a
-lgcc
-lgcc_eh
-Wl,--end-group
${CRT_END}
${CUSTOM_LIBC_PATH}/lib/crtn.o
tls_secure)
target_compile_options(sloader PUBLIC -Wall -Werror)
target_link_options(
sloader
BEFORE
PUBLIC
-nostdlib
-nostartfiles
-static
-Wl,-verbose
-T
${CMAKE_CURRENT_SOURCE_DIR}/sloader_static.map)
else()
add_executable(sloader sloader.cc dyn_loader.cc libc_mapping.cc sloader_dl.cc
utils.cc sloader_static.map)
target_link_libraries(sloader tls_secure)
target_compile_options(sloader PUBLIC -Wall -Werror)
target_link_options(sloader PUBLIC -static -Wl,-verbose -T
${CMAKE_CURRENT_SOURCE_DIR}/sloader_static.map)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake
${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(tests)