builder: Setup the cache file for serene binary

This commit is contained in:
Sameer Rahmani 2023-03-08 20:54:30 +00:00
parent a98065c2f9
commit 639d340f46
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
4 changed files with 70 additions and 14 deletions

View File

@ -99,6 +99,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
-Wdouble-promotion
-Wformat=2)
add_link_options(-fuse-ld=lld)
# if ((SERENE_USE_LIBCXX) AND (NOT (SERENE_TOOLCHAIN_PATH)))
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -v")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")

View File

@ -45,6 +45,8 @@ set(CMAKE_CXX_COMPILER "${SERENE_LLVM_BIN}/clang++" CACHE PATH "")
# a mistake
set(BDWgc_DIR "${SERENE_PKG_DIR}/bdwgc.${BDWGC_VERSION}")
set(MUSL_DIR "${SERENE_PKG_DIR}/musl.${MUSL_VERSION}/" CACHE PATH "")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "")
set(SERENE_CCACHE_DIR "$ENV{HOME}/.ccache" CACHE STRING "")
set(CMAKE_BUILD_TYPE "Debug")

View File

@ -49,8 +49,7 @@ set_target_properties(serene PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
# Warn on unused libs
LINK_WHAT_YOU_USE TRUE
# LTO support
INTERPROCEDURAL_OPTIMIZATION TRUE)
)
if (CPP_20_SUPPORT)
target_compile_features(serene PRIVATE cxx_std_20)
@ -64,9 +63,21 @@ target_include_directories(serene
${CMAKE_CURRENT_SOURCE_DIR}/include
)
# We don't want the generated files from table gen
# to be treated as local since the contain warnings
target_include_directories(serene SYSTEM PRIVATE ${PROJECT_BINARY_DIR}/include)
target_include_directories(serene SYSTEM PRIVATE
${PROJECT_BINARY_DIR}/include
# ${SERENE_LLVM_DIR}/include/x86_64-unknown-linux-gnu/c++/v1
# ${SERENE_LLVM_DIR}/include/c++/v1
#${MUSL_DIR}/include
)
target_link_directories(serene
PRIVATE
# ${SERENE_LLVM_DIR}/lib
# ${MUSL_DIR}/lib
)
# Autogenerate the `config.h` file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/serene/config.h.in include/serene/config.h)
@ -74,9 +85,17 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/serene/config.h.in include/se
target_compile_options(serene
PRIVATE
-stdlib=libc++
# LLVM has it's own RTTI
-fno-rtti
-fno-builtin-strlen
# Don't link against system's default libc++ or libstdc++
# -nostdinc++
# -nostdlib++
# Do not link any default library, We want to be explicit
# -nodefaultlibs
# -nostdinc
# Dedicate a section to each function, so the linker
# can do a better job on dead code elimination
@ -106,14 +125,13 @@ target_compile_options(serene
target_link_options(serene
PRIVATE
-fuse-ld=lld
-Wl,-gc-sections
-stdlib=libc++
-lc++abi
-Wl,--gc-sections
$<$<CONFIG:RELEASE>:-s>
$<$<CONFIG:DEBUG>:-fsanitize=address>
$<$<CONFIG:DEBUG>:-static-libsan>
# Do not link against shared libraries
--static
)
@ -126,15 +144,18 @@ if(SERENE_ENABLE_TIDY)
set_target_properties(serene PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY_PATH})
endif()
# TODO: Setup the THINLTO on release
if(SERENE_ENABLE_THINLTO)
include(CheckIPOSupported)
# Optional IPO. Do not use IPO if it's not supported by compiler.
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set_property(TARGET serene PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported: ${output}")
message(WARNING "Make sure to use lld")
endif()
endif()
# target_link_libraries(serene
# PRIVATE
# )
include(GNUInstallDirs)

View File

@ -16,4 +16,36 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
int main() { return 0; }
#include <iomanip>
#include <memory>
#include <iostream>
struct Vec3
{
int x, y, z;
// following constructor is no longer needed since C++20
Vec3(int x = 0, int y = 0, int z = 0) noexcept : x(x), y(y), z(z) { }
friend std::ostream& operator<<(std::ostream& os, const Vec3& v)
{
return os << "{ x=" << v.x << ", y=" << v.y << ", z=" << v.z << " }";
}
};
int main()
{
// Use the default constructor.
std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
// Use the constructor that matches these arguments
std::unique_ptr<Vec3> v2 = std::make_unique<Vec3>(0,1,2);
// Create a unique_ptr to an array of 5 elements
std::unique_ptr<Vec3[]> v3 = std::make_unique<Vec3[]>(5);
std::cout << "make_unique<Vec3>(): " << *v1 << '\n'
<< "make_unique<Vec3>(0,1,2): " << *v2 << '\n'
<< "make_unique<Vec3[]>(5): ";
for (int i = 0; i < 5; i++)
std::cout << std::setw(i ? 30 : 0) << v3[static_cast<size_t>(i)] << '\n';
}