Build ICU in x.py and fix CMake build
This commit is contained in:
parent
45c2930d22
commit
2c6380e8db
2 changed files with 61 additions and 27 deletions
|
@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.20)
|
|||
|
||||
project(Bolt C CXX)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
|
||||
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
|
||||
|
||||
option(BOLT_ENABLE_LLVM "Enable using LLVM as a back-end" ON)
|
||||
option(BOLT_ENABLE_CLANG "Enable integration with the Clang compiler" ON)
|
||||
|
@ -14,8 +14,12 @@ endif()
|
|||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
find_package(ICU REQUIRED uc)
|
||||
|
||||
if (BOLT_ENABLE_LLVM)
|
||||
add_subdirectory(deps/llvm/llvm EXCLUDE_FROM_ALL)
|
||||
find_package(LLVM REQUIRED CONFIG)
|
||||
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
|
||||
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
|
||||
# find_package(LLVM 18 REQUIRED all-targets)
|
||||
# if (BOLT_ENABLE_CLANG)
|
||||
# find_package(Clang 18 REQUIRED)
|
||||
|
@ -26,11 +30,11 @@ add_subdirectory(deps/zen EXCLUDE_FROM_ALL)
|
|||
add_subdirectory(deps/fmt EXCLUDE_FROM_ALL)
|
||||
|
||||
# FIXME temporary solution
|
||||
set(ICU_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build/icu/install")
|
||||
set(ICU_CFLAGS "-DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit -DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1 -DU_HIDE_OBSOLETE_UTF_OLD_H=1")
|
||||
set(ICU_INCLUDE_DIRS "${ICU_DIR}/include")
|
||||
set(ICU_LIBRARY_DIRS "${ICU_DIR}/lib")
|
||||
set(ICU_LIBRARIES icuuc)
|
||||
#set(ICU_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build/icu/install")
|
||||
#set(ICU_CFLAGS "-DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit -DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1 -DU_HIDE_OBSOLETE_UTF_OLD_H=1")
|
||||
#set(ICU_INCLUDE_DIRS "${ICU_DIR}/include")
|
||||
#set(ICU_LIBRARY_DIRS "${ICU_DIR}/lib")
|
||||
#set(ICU_LIBRARIES icuuc)
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(BOLT_DEBUG ON)
|
||||
|
@ -78,6 +82,7 @@ target_link_libraries(
|
|||
icuuc
|
||||
${CLANG_LIBRARIES}
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND BOLT_DEBUG)
|
||||
target_compile_options(
|
||||
BoltCore
|
||||
|
@ -86,15 +91,34 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND BOLT_DEBUG)
|
|||
)
|
||||
endif()
|
||||
|
||||
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
|
||||
llvm_map_components_to_libnames(llvm_libs support core native)
|
||||
message("Libs: ${llvm_libs}")
|
||||
|
||||
add_library(
|
||||
BoltLLVM
|
||||
src/LLVMCodeGen.cc
|
||||
)
|
||||
target_include_directories(
|
||||
BoltLLVM
|
||||
PUBLIC
|
||||
${LLVM_INCLUDE_DIRS}
|
||||
)
|
||||
target_link_libraries(
|
||||
BoltLLVM
|
||||
PUBLIC
|
||||
BoltCore
|
||||
LLVM
|
||||
${llvm_libs}
|
||||
)
|
||||
target_compile_definitions(
|
||||
BoltLLVM
|
||||
PUBLIC
|
||||
${LLVM_DEFINITIONS_LIST}
|
||||
)
|
||||
target_link_directories(
|
||||
BoltLLVM
|
||||
PUBLIC
|
||||
${LLVM_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
add_executable(
|
||||
|
|
48
x.py
48
x.py
|
@ -15,6 +15,13 @@ ICU_VERSION = '76.1'
|
|||
|
||||
here = Path(__file__).parent.resolve()
|
||||
|
||||
NONE = 0
|
||||
CLANG = 1
|
||||
GCC = 2
|
||||
MSVC = 3
|
||||
|
||||
force = None
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('--no-ninja', action='store_true', help='Do not use Ninja if present')
|
||||
|
@ -27,6 +34,11 @@ parser.add_argument('--no-system-llvm', action='store_true', help='Use a local v
|
|||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.clang:
|
||||
force = CLANG
|
||||
elif args.gcc:
|
||||
force = GCC
|
||||
|
||||
cache_dir = here / '.cache' / 'bolt-build'
|
||||
download_dir = cache_dir / 'downloads'
|
||||
source_dir = cache_dir / 'source'
|
||||
|
@ -198,17 +210,18 @@ def ninja(targets: list[str], cwd: Path | None = None) -> None:
|
|||
argv.extend([ '-C', str(cwd) ])
|
||||
spawn(argv)
|
||||
|
||||
def build_bolt(llvm_root: Path) -> None:
|
||||
def build_bolt(llvm_root: Path, icu_root: Path) -> None:
|
||||
|
||||
if newer(bolt_source_dir / 'CMakeLists.txt', bolt_build_dir):
|
||||
|
||||
print(icu_root)
|
||||
defines: dict[str, CMakeValue] = {
|
||||
'CMAKE_EXPORT_COMPILE_COMMANDS': True,
|
||||
'CMAKE_BUILD_TYPE': 'Debug',
|
||||
'BOLT_ENABLE_TESTS': True,
|
||||
'ZEN_ENABLE_TESTS': False,
|
||||
'LLVM_ROOT': str(llvm_install_dir),
|
||||
'ICU_ROOT': str(icu_install_dir),
|
||||
'LLVM_ROOT': str(llvm_root),
|
||||
'ICU_ROOT': str(icu_root),
|
||||
#'LLVM_CONFIG': str(llvm_config_path),
|
||||
#'LLVM_TARGETS_TO_BUILD': 'X86',
|
||||
}
|
||||
|
@ -241,29 +254,28 @@ def build_icu(version: str) -> None:
|
|||
env = dict(os.environ)
|
||||
env['CC'] = str(c_path)
|
||||
env['CXX'] = str(cxx_path)
|
||||
env['CPPFLAGS'] = '-DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit -DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1 -DU_HIDE_OBSOLETE_UTF_OLD_H=1'
|
||||
env['CXXFLAGS'] = '-std=c++17'
|
||||
#env['CPPFLAGS'] = '-DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit -DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1 -DU_HIDE_OBSOLETE_UTF_OLD_H=1'
|
||||
env['CPPFLAGS'] = '-DU_NO_DEFAULT_INCLUDE_UTF_HEADERS=1 -DU_HIDE_OBSOLETE_UTF_OLD_H=1'
|
||||
configured_path = icu_source_dir / '.configured'
|
||||
if not configured_path.exists():
|
||||
shell(f'{icu_source_dir}/source/runConfigureICU Linux', cwd=icu_build_dir, env=env)
|
||||
spawn([ f'{icu_source_dir}/source/runConfigureICU', 'Linux', '--enable-static', '--prefix', str(icu_install_dir) ], cwd=icu_build_dir, env=env)
|
||||
touch(configured_path)
|
||||
built_path = icu_source_dir / '.built'
|
||||
if not built_path.exists():
|
||||
shell(f'make -j{os.cpu_count()}', cwd=icu_build_dir, env=env)
|
||||
touch(built_path)
|
||||
installed_path = icu_source_dir / '.installed'
|
||||
if not installed_path.exists():
|
||||
shell(f'make install -j{os.cpu_count()}', cwd=icu_build_dir, env=env)
|
||||
touch(installed_path)
|
||||
|
||||
enable_ninja = not args.no_ninja
|
||||
|
||||
NONE = 0
|
||||
CLANG = 1
|
||||
GCC = 2
|
||||
MSVC = 3
|
||||
|
||||
force = NONE
|
||||
|
||||
ninja_path = enable_ninja and shutil.which('ninja')
|
||||
|
||||
def detect_compilers() -> tuple[Path, Path] | None:
|
||||
if os.name == 'posix':
|
||||
cxx_path = os.environ.get('CXX')
|
||||
c_path = os.environ.get('CC')
|
||||
if c_path is not None and cxx_path is not None:
|
||||
return Path(c_path).absolute(), Path(cxx_path).absolute()
|
||||
for suffix in [ '', '-19', '-18' ]:
|
||||
clang_c_path = shutil.which(f'clang{suffix}')
|
||||
clang_cxx_path = shutil.which(f'clang++{suffix}')
|
||||
|
@ -313,9 +325,7 @@ if llvm_config_path is None or args.no_system_llvm:
|
|||
|
||||
llvm_root = Path(stdout([ str(llvm_config_path), '--cmakedir' ]))
|
||||
|
||||
print(llvm_root)
|
||||
|
||||
build_icu(version=ICU_VERSION)
|
||||
|
||||
build_bolt(llvm_root=llvm_root)
|
||||
build_bolt(llvm_root=llvm_root, icu_root=icu_install_dir)
|
||||
|
||||
|
|
Loading…
Reference in a new issue