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

File tree

46 files changed

+19
-250
lines changed

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 17 additions & 14 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 151 deletions
This file was deleted.

dht-server/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
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()

0 commit comments

Comments
 (0)