Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(cmake): fix LTO for clang #68

Merged
merged 2 commits into from
Jun 19, 2023
Merged
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
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.13)

project(co_context
VERSION 0.9.0
Expand All @@ -7,12 +7,12 @@ project(co_context
include(cmake/Policy.cmake NO_POLICY_SCOPE)

add_library(co_context OBJECT)
target_include_directories(co_context PUBLIC ./include)
target_include_directories(co_context PUBLIC include)

include(cmake/Option.cmake)
include(cmake/CompileOption.cmake)
include(cmake/Platform.cmake)
include(cmake/Develop.cmake)
include(cmake/Extra.cmake)

add_subdirectory(./lib)
add_subdirectory(lib)
6 changes: 3 additions & 3 deletions cmake/CompileOption.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ if(NOT CMAKE_BUILD_TYPE)
message(NOTICE "Setting default CMAKE_BUILD_TYPE to Release")
endif()

set(CMAKE_CXX_FLAGS_RELEASE)
if(CMAKE_BUILD_TYPE MATCHES Release)
add_compile_options(-march=native)
target_compile_options(co_context PUBLIC -march=native)
endif()

# Get the linux kernel version to liburingcxx
Expand All @@ -35,6 +34,7 @@ unset(kernel_version)
include(CheckIPOSupported)
check_ipo_supported(RESULT is_support_IPO OUTPUT output_support_IPO)
if(is_support_IPO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set_target_properties(co_context PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported: ${output_support_IPO}")
Expand All @@ -61,5 +61,5 @@ find_package(Threads REQUIRED)
target_link_libraries(co_context PRIVATE Threads::Threads)

if (USE_MIMALLOC)
target_link_libraries(co_context PRIVATE mimalloc)
target_link_libraries(co_context PUBLIC mimalloc)
endif()
10 changes: 6 additions & 4 deletions cmake/Develop.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ if(ENABLE_SANITIZER AND NOT MSVC)
include(${CMAKE_CURRENT_LIST_DIR}/check/check_asan.cmake)
check_asan(HAS_ASAN)
if(HAS_ASAN)
add_compile_options(-fsanitize=undefined,address,leak
-fno-omit-frame-pointer)
target_compile_options(co_context
PUBLIC -fsanitize=undefined,address,leak
PUBLIC -fno-omit-frame-pointer)
else()
message(WARNING "sanitizer is no supported with current tool-chains")
endif()
Expand All @@ -22,8 +23,9 @@ if(ENABLE_SANITIZER AND NOT MSVC)
endif()

if(ENABLE_WARNING)
add_compile_options(-Wall
-Wextra
target_compile_options(co_context
PRIVATE -Wall
PRIVATE -Wextra
# -Wconversion
# -pedantic
# -Werror
Expand Down
9 changes: 7 additions & 2 deletions cmake/Extra.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
# ----------------------------------------------------------------------------
if(ENABLE_COVERAGE_TEST)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fprofile-arcs -ftest-coverage --coverage)
target_compile_options(co_context
PUBLIC -fprofile-arcs
PUBLIC -ftest-coverage
PUBLIC --coverage)
else()
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
target_compile_options(co_context
PUBLIC -fprofile-instr-generate
PUBLIC -fcoverage-mapping)
endif()
endif()

Expand Down
8 changes: 5 additions & 3 deletions cmake/Platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
# Clang
# ----------------------------------------------------------------------------
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsized-deallocation -std=c++20")
target_compile_options(co_context PUBLIC -fsized-deallocation)
endif()

if(WITH_LIBCXX AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-stdlib=libc++)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
target_compile_options(co_context PRIVATE -stdlib=libc++)
target_link_options(co_context
PRIVATE -stdlib=libc++
PRIVATE -lc++abi)
endif()
Loading