Convert build scripts to CMake (#13427)

This commit is contained in:
Ashcon Partovi
2024-09-10 17:01:40 -07:00
committed by GitHub
parent 8d7d58606b
commit 354df17d16
223 changed files with 4453 additions and 44770 deletions

View File

@@ -0,0 +1,137 @@
# TODO: Commit to oven-sh/tinycc
cmake_minimum_required(VERSION 3.10)
project(tinycc VERSION 0.9.28 LANGUAGES C)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
add_compile_options(-Wall)
if(NOT CMAKE_C_COMPILER_ID MATCHES "tcc")
add_compile_options(
-fno-strict-aliasing
-Wdeclaration-after-statement
-Wpointer-sign
-Wsign-compare
-Wunused-result
-Wformat-truncation
)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
add_compile_options(
-fheinous-gnu-extensions
-Wno-string-plus-int
-Wno-deprecated-declarations
)
endif()
add_compile_definitions(
CONFIG_TCC_PREDEFS
ONE_SOURCE=0
TCC_LIBTCC1="\\0"
)
if(APPLE)
add_compile_definitions(
TCC_TARGET_MACHO
CONFIG_CODESIGN
CONFIG_NEW_MACHO
CONFIG_USR_INCLUDE=\"${CMAKE_OSX_SYSROOT}\"
)
endif()
if(WIN32)
add_compile_definitions(
CONFIG_WIN32
CONFIG_TCCDIR=\"${CMAKE_CURRENT_SOURCE_DIR}/win32\"
)
endif()
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/VERSION TCC_VERSION)
add_compile_definitions(TCC_VERSION=\"${TCC_VERSION}\")
execute_process(
COMMAND git rev-parse --short HEAD
OUTPUT_VARIABLE TCC_GITHASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(TCC_GITHASH)
add_compile_definitions(TCC_GITHASH=\"${TCC_GITHASH}\")
endif()
set(TCC_SOURCES
libtcc.c
tccpp.c
tccgen.c
tccdbg.c
tccelf.c
tccasm.c
tccrun.c
)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64|ARM64")
list(APPEND TCC_SOURCES
arm64-gen.c
arm64-link.c
arm64-asm.c
)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|x64|amd64|AMD64")
list(APPEND TCC_SOURCES
x86_64-gen.c
x86_64-link.c
i386-asm.c
)
else()
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
if(APPLE)
list(APPEND TCC_SOURCES tccmacho.c)
endif()
if(WIN32)
list(APPEND TCC_SOURCES tccpe.c)
endif()
add_executable(c2str.exe conftest.c)
target_compile_options(c2str.exe PRIVATE -DC2STR)
add_custom_command(
TARGET
c2str.exe POST_BUILD
COMMAND
c2str.exe include/tccdefs.h tccdefs_.h
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
)
add_library(tcc STATIC ${TCC_SOURCES})
add_custom_command(
TARGET
tcc PRE_BUILD
COMMAND
${CMAKE_COMMAND} -E touch config.h
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
)
add_dependencies(tcc c2str.exe)
target_include_directories(tcc PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
)

View File

@@ -0,0 +1,12 @@
--- tcc.h
+++ tcc.h
@@ -23,7 +23,9 @@
#define _GNU_SOURCE
#define _DARWIN_C_SOURCE
+#if __has_include("config.h")
#include "config.h"
+#endif
#include <stdarg.h>
#include <stdlib.h>

View File

@@ -0,0 +1,26 @@
--- deflate.h
+++ deflate.h
@@ -326,23 +326,7 @@ extern const uint8_t ZLIB_INTERNAL _dist_code[];
flush = (s->sym_next == s->sym_end); \
}
-#ifdef _MSC_VER
-
-/* MSC doesn't have __builtin_expect. Just ignore likely/unlikely and
- hope the compiler optimizes for the best.
-*/
-#define likely(x) (x)
-#define unlikely(x) (x)
-
-int __inline __builtin_ctzl(unsigned long mask)
-{
- unsigned long index ;
-
- return _BitScanForward(&index, mask) == 0 ? 32 : ((int)index) ;
-}
-#else
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
-#endif
#endif /* DEFLATE_H */