-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.cmake
149 lines (125 loc) · 5.89 KB
/
config.cmake
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR ARM)
get_filename_component(SDK_PATH ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
set_property(GLOBAL PROPERTY NO_SONAME TRUE)
# -----------------------------------------------
# Settings
# -----------------------------------------------
# Custom toolchain
if (NOT DEFINED TOOLCHAIN)
set(TOOLCHAIN "arm-none-eabi")
endif()
# Source files encoding
if (NOT DEFINED SOURCE_ENCODING)
set(SOURCE_ENCODING "utf-8")
endif()
# C++ variant: libcxx or uclibc++
if (NOT DEFINED CXX_TYPE)
set(CXX_TYPE "libcxx")
endif()
# -----------------------------------------------
# Toolchain
# -----------------------------------------------
if (CMAKE_SYSTEM MATCHES Windows)
set(TOOLCHAIN_EXT ".exe")
else()
set(TOOLCHAIN_EXT "")
endif()
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
set(ENV{SOURCE_DATE_EPOCH} 1172750400)
set(CMAKE_C_COMPILER ${TOOLCHAIN}-gcc${TOOLCHAIN_EXT})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN}-g++${TOOLCHAIN_EXT})
set(CMAKE_ASM_COMPILER ${TOOLCHAIN}-gcc${TOOLCHAIN_EXT})
function(target_sdk_setup target platform)
set_property(TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE OFF)
get_target_property(target_type ${target} TYPE)
if (target_type STREQUAL "EXECUTABLE")
set_property(TARGET ${target} PROPERTY SUFFIX ".elf")
endif()
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/lib/ELKA" "${PROJECT_BINARY_DIR}/lib/NSG" "${PROJECT_BINARY_DIR}/lib/SG")
if (platform STREQUAL "SG" OR platform STREQUAL "SGOLD")
message("Compiling for target SGOLD")
target_compile_definitions(${target} PUBLIC SGOLD)
target_link_directories(${target} PUBLIC ${SDK_PATH}/lib/stubs ${SDK_PATH}/lib/SG ${SDK_PATH}/lib)
set(LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/SG")
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/SG")
elseif (platform STREQUAL "NSG" OR platform STREQUAL "NEWSGOLD")
message("Compiling for target NEWSGOLD")
target_compile_definitions(${target} PUBLIC NEWSGOLD)
target_link_directories(${target} PUBLIC ${SDK_PATH}/lib/stubs ${SDK_PATH}/lib/NSG ${SDK_PATH}/lib)
set(LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/NSG")
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/NSG")
elseif (platform STREQUAL "EL" OR platform STREQUAL "ELKA")
message("Compiling for target ELKA")
target_compile_definitions(${target} PUBLIC NEWSGOLD ELKA)
target_link_directories(${target} PUBLIC ${SDK_PATH}/lib/stubs ${SDK_PATH}/lib/ELKA ${SDK_PATH}/lib/NSG ${SDK_PATH}/lib)
set(LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/ELKA")
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/ELKA")
else()
message(FATAL "Invalid platform: ${platform}")
endif()
endfunction()
function(target_sdk_set_lib_name target name version)
set_target_properties(${target} PROPERTIES NO_SONAME TRUE)
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_NAME ${name})
target_link_options(${target} PUBLIC "-Wl,--soname,lib${name}.so")
endfunction()
# -----------------------------------------------
# Include dirs
# -----------------------------------------------
if (CXX_TYPE STREQUAL "uclibc++")
include_directories(${SDK_PATH}/libuc++/include)
elseif (CXX_TYPE STREQUAL "libcxx")
include_directories(${SDK_PATH}/libc++abi/include)
include_directories(${SDK_PATH}/libc++/include)
else()
message(FATAL "Invalid CXX_TYPE: ${CXX_TYPE}")
endif()
include_directories(${SDK_PATH}/include)
include_directories(${SDK_PATH}/swilib/include)
include_directories(${SDK_PATH}/libgcc/include)
include_directories(${SDK_PATH}/dietlibc/include)
include_directories(${SDK_PATH}/libjpeg/include)
include_directories(${SDK_PATH}/libpng/include)
include_directories(${SDK_PATH}/libsigc++/include)
include_directories(${SDK_PATH}/libft/include)
include_directories(${SDK_PATH}/libft_server/include)
include_directories(${SDK_PATH}/libz/include)
# -----------------------------------------------
# Common
# -----------------------------------------------
set(SDK_COMMON_LDFLAGS "-Wl,-zmax-page-size=1 -Wl,--defsym=__dso_handle=0")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(SDK_COMMON_LDFLAGS "${SDK_COMMON_LDFLAGS} -g")
else()
set(SDK_COMMON_LDFLAGS "${SDK_COMMON_LDFLAGS} -s")
endif()
set(SDK_COMMON_CFLAGS "-msoft-float -fshort-wchar -mlittle-endian -mcpu=arm926ej-s -mthumb-interwork")
set(SDK_COMMON_CFLAGS "${SDK_COMMON_CFLAGS} -fno-builtin -nodefaultlibs -nostdlib -nostdinc")
set(SDK_COMMON_CFLAGS "${SDK_COMMON_CFLAGS} -fno-common -ffunction-sections -fdata-sections")
set(SDK_COMMON_CFLAGS "${SDK_COMMON_CFLAGS} -frandom-seed=0")
set(SDK_COMMON_CFLAGS "${SDK_COMMON_CFLAGS} -g")
if (NOT SOURCE_ENCODING STREQUAL "cp1251" AND NOT SOURCE_ENCODING STREQUAL "native")
set(SDK_COMMON_CFLAGS "${SDK_COMMON_CFLAGS} -finput-charset=${SOURCE_ENCODING} -fexec-charset=cp1251")
endif()
set(CMAKE_C_FLAGS "${SDK_COMMON_CFLAGS}")
set(CMAKE_CXX_FLAGS "${SDK_COMMON_CFLAGS} -nostdinc++ -fno-enforce-eh-specs -fno-use-cxa-get-exception-ptr -fno-non-call-exceptions -fno-exceptions -fpermissive")
set(CMAKE_ASM_FLAGS "${SDK_COMMON_CFLAGS}")
set(CMAKE_C_LINK_FLAGS "")
set(CMAKE_CXX_LINK_FLAGS "")
set(CMAKE_ASM_LINK_FLAGS "")
add_compile_definitions(__arm__ __ARM_EABI__)
# -----------------------------------------------
# Shared library
# -----------------------------------------------
set(CMAKE_SHARED_LINKER_FLAGS "${SDK_COMMON_LDFLAGS} -Wl,-shared -Wl,-Bsymbolic -Wl,-Bsymbolic-function")
set(CMAKE_MODULE_LINKER_FLAGS "${SDK_COMMON_LDFLAGS} -Wl,-shared -Wl,-Bsymbolic -Wl,-Bsymbolic-function")
# -----------------------------------------------
# Static library
# -----------------------------------------------
set(CMAKE_STATIC_LINKER_FLAGS "${SDK_COMMON_LDFLAGS} -ar rcsD")
# -----------------------------------------------
# Executable
# -----------------------------------------------
set(CMAKE_EXE_LINKER_FLAGS "${SDK_COMMON_LDFLAGS} -pie")