Skip to content

Commit 5f9d8af

Browse files
authored
Cmake refactoring (#1551)
* Ignore clangd .cache directory With the in-tree build, clangd likes to put its cache files inside of /.cache. Thus, put the directory to .gitignore. * Remove redundant cmake_minimum_required calls There is no need to repeat the same information in all subprojects, the call in the root CMakeLists.txt is more than enough. * Bump minimum CMake version to 3.16 This avoids deprecation warnings on newer CMake versions. 3.16 was chosen as a version easily available on Ubuntu 20.04 -- the oldest distributive we support. * Do not automatically add -stdlib=libc++ when sanitizers are requested In my experience, adding -stdlib=libc++ during compilation of a project with C++ dependencies which are not consistently using libc++ never works. In this particular case, modern enough stdlibc++ works just fine when compiled with Clang and sanitizers, while using libc++ results in obscure linker errors. * Do not fall back to -O2 if CMAKE_BUILD_TYPE == RelWithDebInfo * Use CMAKE_{C,CXX}_COMPILER_LAUNCHER for enabling ccache Additionally, if user has already specified either of these two variables, don't override their choices. As per documentation, RULE_LAUNCH_{COMPILE,LINK} are only supposed to be used in internal CMake code. More importantly, the previous approach appended ccache two times if CMAKE_CXX_COMPILER_LAUNCHER was provided in command line or via an environment variable. * Remove unused crypto/openssl/digest.h
1 parent cf50b4b commit 5f9d8af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+19
-250
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ crypto/smartcont/auto/
1111
test/regression-tests.cache/
1212
*.swp
1313
**/*build*/
14+
.cache
1415
.idea
1516
.vscode
1617
.DS_Store

CMakeLists.txt

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
22

33
project(TON VERSION 0.5 LANGUAGES C CXX)
44
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -159,6 +159,9 @@ if (TON_USE_ROCKSDB)
159159
set(FAIL_ON_WARNINGS OFF CACHE BOOL "fail on warnings")
160160
message("Add rocksdb")
161161
add_subdirectory(third-party/rocksdb EXCLUDE_FROM_ALL)
162+
# Broken CMake in rocksdb alters properties it has no business changing.
163+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
164+
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK)
162165
endif()
163166

164167
option(USE_COROUTINES "experimental support of coroutines" OFF)
@@ -188,11 +191,12 @@ include(BuildSECP256K1)
188191

189192
# Configure CCache if available
190193
find_program(CCACHE_FOUND ccache)
191-
#set(CCACHE_FOUND 0)
192194
if (CCACHE_FOUND)
193-
message(STATUS "Found ccache")
194-
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
195-
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
195+
if (NOT DEFINED CMAKE_C_COMPILER_LAUNCHER AND NOT DEFINED CMAKE_CXX_COMPILER_LAUNCHER)
196+
message(STATUS "Using ccache")
197+
set(CMAKE_C_COMPILER_LAUNCHER ccache)
198+
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
199+
endif()
196200
else()
197201
message(STATUS "Could NOT find ccache")
198202
endif()
@@ -341,6 +345,14 @@ add_cxx_compiler_flag("-Qunused-arguments")
341345
add_cxx_compiler_flag("-Wno-unused-private-field")
342346
add_cxx_compiler_flag("-Wno-redundant-move")
343347

348+
if (GCC OR CLANG)
349+
if (CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
350+
# For historical reasons, CMake falls back to -O2 optimization level when CMAKE_BUILD_TYPE is
351+
# set to RelWithDebInfo.
352+
add_compile_options(-O3)
353+
endif()
354+
endif()
355+
344356
#add_cxx_compiler_flag("-Wno-unused-function")
345357
#add_cxx_compiler_flag("-Wno-unused-variable")
346358
#add_cxx_compiler_flag("-Wno-shorten-64-to-32")
@@ -351,22 +363,13 @@ if (CLANG)
351363
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
352364
endif()
353365
if (TON_USE_ASAN)
354-
if (CLANG)
355-
add_cxx_compiler_flag("-stdlib=libc++")
356-
endif()
357366
add_cxx_compiler_flag("-fsanitize=address")
358367
add_definitions(-DTD_USE_ASAN=1)
359368
endif()
360369
if (TON_USE_TSAN)
361-
if (CLANG)
362-
add_cxx_compiler_flag("-stdlib=libc++")
363-
endif()
364370
add_cxx_compiler_flag("-fsanitize=thread")
365371
endif()
366372
if (TON_USE_UBSAN)
367-
if (CLANG)
368-
add_cxx_compiler_flag("-stdlib=libc++")
369-
endif()
370373
add_cxx_compiler_flag("-fsanitize=undefined")
371374
endif()
372375
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")

adnl/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
#BEGIN internal
42
if (NOT TON_ONLY_TONLIB)
53
set(ADNL_HEADERS

blockchain-explorer/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
option(NIX "Use \"ON\" for a static build." OFF)
42

53
set(BLOCHAIN_EXPLORER_SOURCE

catchain/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

common/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
set(COMMON_SOURCE
42
checksum.h
53
errorcode.h

create-hardfork/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

crypto/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

crypto/openssl/digest.h

-151
This file was deleted.

dht-server/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

dht/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

emulator/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
option(EMULATOR_STATIC "Build emulator as static library" OFF)
42

53
set(EMULATOR_STATIC_SOURCE

example/android/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Sets the minimum version of CMake required to build the native library.
55

6-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
6+
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
77

88
project(TON_ANDROID VERSION 0.5 LANGUAGES C CXX)
99

fec/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

http/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
set(HTTP_SOURCE
42
http.h
53
http.cpp

keyring/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
set(KEYRING_SOURCE
42
keyring.h
53
keyring.hpp

keys/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
set(KEYS_SOURCE
42
keys.cpp
53
encryptor.cpp

lite-client/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
add_library(lite-client-common STATIC lite-client-common.cpp lite-client-common.h ext-client.cpp ext-client.h
42
query-utils.hpp query-utils.cpp)
53
target_link_libraries(lite-client-common PUBLIC tdactor adnllite tl_api tl_lite_api tl-lite-utils ton_crypto)

memprof/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
set(MEMPROF_SOURCE
42
memprof/memprof.cpp
53
memprof/memprof.h

overlay/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

rldp-http-proxy/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
add_executable(rldp-http-proxy rldp-http-proxy.cpp DNSResolver.h DNSResolver.cpp)
42
target_include_directories(rldp-http-proxy PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>)
53
target_link_libraries(rldp-http-proxy PRIVATE tonhttp rldp rldp2 dht tonlib git)

rldp/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

rldp2/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

storage/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
if (NOT OPENSSL_FOUND)
42
find_package(OpenSSL REQUIRED)
53
endif()

storage/storage-daemon/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
add_executable(embed-provider-code smartcont/embed-provider-code.cpp)
42

53
add_custom_command(

tdactor/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
#SOURCE SETS
42
set(TDACTOR_SOURCE
53
td/actor/core/ActorExecutor.cpp

tdactor/benchmark/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
set(BENCHMARK_SOURCE
42
benchmark.cpp
53
third_party/mp-queue.c

tddb/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
#SOURCE SETS
42
set(TDDB_UTILS_SOURCE
53
td/db/utils/BlobView.cpp

tdfec/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
set(TDFEC_SOURCE
42
td/fec/raptorq/Rfc.cpp
53
td/fec/raptorq/Rfc.h

tdfec/benchmark/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
31
add_executable(benchmark-fec benchmark.cpp )
42
target_include_directories(benchmark-fec PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
53
target_link_libraries(benchmark-fec PRIVATE tdfec)

0 commit comments

Comments
 (0)