Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ option(TON_USE_ASAN "Use \"ON\" to enable AddressSanitizer." OFF)
option(TON_USE_TSAN "Use \"ON\" to enable ThreadSanitizer." OFF)
option(TON_USE_UBSAN "Use \"ON\" to enable UndefinedBehaviorSanitizer." OFF)
option(TON_USE_COVERAGE "Use \"ON\" to enable code coverage with gcov." OFF)
set(TON_ARCH "native" CACHE STRING "Architecture, will be passed to -march=")
option(TON_USE_CI_BASELINE_CPU "Use baseline CPU for artifacts produced in CI" OFF)
set(TON_ARCH "native" CACHE STRING "Architecture that will be passed to -march=. The setting is ignored if TON_USE_CI_BASELINE_CPU is set.")

option(TON_PRINT_BACKTRACE_ON_CRASH "Attempt to print a backtrace when a fatal signal is caught" ON)
option(TON_INSERT_GDB_HOOKS "Insert GDB hooks" OFF)
Expand All @@ -79,14 +80,25 @@ if (TON_USE_LLD)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
endif()

#BEGIN M1 support
EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )

if ((ARCHITECTURE MATCHES "arm64") AND (CMAKE_SYSTEM_NAME STREQUAL "Darwin") AND
(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)) # only clang 13+ supports cpu=apple-m1
set(TON_ARCH "apple-m1")
if (NOT MSVC)
if (TON_USE_CI_BASELINE_CPU)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
add_compile_options(-march=x86-64-v3) # AVX2; broadly supported from 2015
elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
add_compile_options(-mcpu=apple-m1)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)$")
add_compile_options(-march=armv8-a) # 64-bit AArch; broadly supported from 2014
else()
message(FATAL_ERROR "TON_USE_CI_BASELINE_CPU is not supported on ${CMAKE_SYSTEM_PROCESSOR}")
endif()
else()
add_compile_options(-march=${TON_ARCH})
endif()
else()
if (TON_USE_CI_BASELINE_CPU OR NOT TON_ARCH STREQUAL "native")
message(FATAL_ERROR "TON_ARCH is not supported with MSVC")
endif()
endif()
#END M1 support

if (CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "20")
add_compile_options(--warning-suppression-mappings=${CMAKE_SOURCE_DIR}/suppression_mappings.txt)
Expand Down Expand Up @@ -221,16 +233,6 @@ else()
endif()


if (TON_ARCH AND NOT MSVC)
CHECK_CXX_COMPILER_FLAG( "-march=${TON_ARCH}" COMPILER_OPT_ARCH_SUPPORTED )
if (TON_ARCH STREQUAL "apple-m1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=${TON_ARCH}")
elseif(COMPILER_OPT_ARCH_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${TON_ARCH}")
elseif(NOT TON_ARCH STREQUAL "native")
message(FATAL_ERROR "Compiler doesn't support arch ${TON_ARCH}")
endif()
endif()
if (THREADS_HAVE_PTHREAD_ARG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
Expand Down
1 change: 1 addition & 0 deletions assembly/native/build-macos-portable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ cmake -GNinja .. \
-DCMAKE_CXX_FLAGS="-stdlib=libc++" \
-DCMAKE_SYSROOT=$(xcrun --show-sdk-path) \
-DCMAKE_BUILD_TYPE=Release \
-DTON_USE_CI_BASELINE_CPU=1 \
-DOPENSSL_FOUND=1 \
-DOPENSSL_INCLUDE_DIR=$opensslPath/include \
-DOPENSSL_CRYPTO_LIBRARY=$opensslPath/libcrypto.a \
Expand Down
1 change: 1 addition & 0 deletions assembly/native/build-macos-shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ brew unlink openssl@3 && brew link --overwrite openssl@3
cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. \
-DCMAKE_CXX_FLAGS="-stdlib=libc++" \
-DCMAKE_SYSROOT=$(xcrun --show-sdk-path) \
-DTON_USE_CI_BASELINE_CPU=1 \
-DLZ4_FOUND=1 \
-DLZ4_LIBRARIES=$lz4Path/lib/liblz4.a \
-DLZ4_INCLUDE_DIRS=$lz4Path/lib \
Expand Down
1 change: 1 addition & 0 deletions assembly/native/build-ubuntu-appimages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fi

cmake -GNinja .. \
-DCMAKE_BUILD_TYPE=Release \
-DTON_USE_CI_BASELINE_CPU=1 \
-DPORTABLE=1 \
-DOPENSSL_ROOT_DIR=$opensslPath \
-DOPENSSL_INCLUDE_DIR=$opensslPath/include \
Expand Down
1 change: 1 addition & 0 deletions assembly/native/build-ubuntu-portable-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fi
cmake -GNinja .. \
-DPORTABLE=1 \
-DCMAKE_BUILD_TYPE=Release \
-DTON_USE_CI_BASELINE_CPU=1 \
-DOPENSSL_FOUND=1 \
-DOPENSSL_INCLUDE_DIR=$opensslPath/include \
-DOPENSSL_CRYPTO_LIBRARY=$opensslPath/libcrypto.a \
Expand Down
1 change: 1 addition & 0 deletions assembly/native/build-ubuntu-portable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fi
cmake -GNinja .. \
-DPORTABLE=1 \
-DCMAKE_BUILD_TYPE=Release \
-DTON_USE_CI_BASELINE_CPU=1 \
-DOPENSSL_FOUND=1 \
-DOPENSSL_INCLUDE_DIR=$opensslPath/include \
-DOPENSSL_CRYPTO_LIBRARY=$opensslPath/libcrypto.a \
Expand Down
1 change: 1 addition & 0 deletions assembly/native/build-ubuntu-shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fi

cmake -GNinja -DTON_USE_JEMALLOC=ON .. \
-DCMAKE_BUILD_TYPE=Release \
-DTON_USE_CI_BASELINE_CPU=1 \
-DOPENSSL_ROOT_DIR=$opensslPath \
-DOPENSSL_INCLUDE_DIR=$opensslPath/include \
-DOPENSSL_CRYPTO_LIBRARY=$opensslPath/libcrypto.so \
Expand Down
Loading