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

build(all): make liburingcxx external; use configure, no -D #104

Merged
merged 1 commit into from
Dec 31, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ draft/
*.rdb
*.svg
/perf/
perf.data*
/perf.*
*.data
*.perf
*.folded
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
cmake_minimum_required(VERSION 3.13)

project(co_context
VERSION 0.9.0
VERSION 0.10.0
LANGUAGES CXX)

include(cmake/Policy.cmake NO_POLICY_SCOPE)

add_subdirectory(extern/liburingcxx)

add_library(co_context STATIC)
add_library(co_context::co_context ALIAS co_context)
target_link_libraries(co_context PUBLIC liburingcxx::liburingcxx)
target_include_directories(co_context
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
Expand All @@ -19,6 +22,7 @@ include(cmake/CompileOption.cmake)
include(cmake/Platform.cmake)
include(cmake/Develop.cmake)
include(cmake/Extra.cmake)
include(cmake/Configure.cmake)
include(cmake/Install.cmake)

add_subdirectory(lib)
15 changes: 3 additions & 12 deletions cmake/CompileOption.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,17 @@ else()
endif()

if (mi_version)
target_compile_definitions(co_context PRIVATE CO_CONTEXT_USE_MIMALLOC)
set(USE_MIMALLOC ON)
set(CO_CONTEXT_USE_MIMALLOC ON)
message(NOTICE "mimalloc ${mi_version} enabled")
else()
set(USE_MIMALLOC OFF)
set(CO_CONTEXT_USE_MIMALLOC OFF)
message(WARNING "mimalloc disabled")
endif()

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(co_context PUBLIC Threads::Threads)

if (USE_MIMALLOC)
if (CO_CONTEXT_USE_MIMALLOC)
target_link_libraries(co_context PUBLIC mimalloc)
endif()

if (co_context_no_generator) # set by check/check_compile.cmake
target_compile_definitions(co_context PUBLIC CO_CONTEXT_NO_GENERATOR)
endif()

if (NOT co_context_has_kernel_rwf_t) # set by check/check_compile.cmake
target_compile_definitions(co_context PUBLIC CO_CONTEXT_OFFER_KERNEL_RWF_T)
endif()
5 changes: 5 additions & 0 deletions cmake/Configure.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
configure_file(
${PROJECT_SOURCE_DIR}/include/co_context/config/config.hpp.in
${PROJECT_SOURCE_DIR}/include/co_context/config/config.hpp
@ONLY
)
4 changes: 0 additions & 4 deletions cmake/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ install(DIRECTORY "${co_context_SOURCE_DIR}/include/co_context"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(DIRECTORY "${co_context_SOURCE_DIR}/include/uring"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT co_context_targets
FILE co_context_targets.cmake
NAMESPACE co_context::
Expand Down
13 changes: 0 additions & 13 deletions cmake/Platform.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
# ----------------------------------------------------------------------------
# Linux
# ----------------------------------------------------------------------------
# Get the linux kernel version to liburingcxx
message(STATUS "target_kernel_version = ${CMAKE_SYSTEM_VERSION}")
set(kernel_version ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+)\.([0-9]+)" kernel_version ${kernel_version})
string(REGEX MATCH "^([0-9]+)" kernel_version_major ${kernel_version})
string(REGEX REPLACE "^([0-9]+)\\." "" kernel_version_minor ${kernel_version})
message(STATUS "kernel_version_major = ${kernel_version_major}")
message(STATUS "kernel_version_minor = ${kernel_version_minor}")
target_compile_definitions(co_context
PUBLIC "$<BUILD_INTERFACE:LIBURINGCXX_KERNEL_VERSION_MAJOR=${kernel_version_major}>"
PUBLIC "$<BUILD_INTERFACE:LIBURINGCXX_KERNEL_VERSION_MINOR=${kernel_version_minor}>"
)
unset(kernel_version)

# ----------------------------------------------------------------------------
# Gcc
Expand Down
17 changes: 2 additions & 15 deletions cmake/check/check_compile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "11.3.0")
message(NOTICE "co_context::generator will be disabled for insufficient gcc version (requires gcc 11.3 or above).")
set(co_context_no_generator ON)
set(CO_CONTEXT_NO_GENERATOR ON)
endif()
endif()

Expand All @@ -20,19 +20,6 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "17.0.0")
message(NOTICE "co_context::generator will be disabled for insufficient clang version (requires clang 17 or above).")
set(co_context_no_generator ON)
set(CO_CONTEXT_NO_GENERATOR ON)
endif()
endif()

check_cxx_source_runs(
[====[
#include <linux/fs.h>
int main(int argc, char **argv)
{
__kernel_rwf_t x;
x = 0;
return x;
}
]====]
co_context_has_kernel_rwf_t
)
12 changes: 0 additions & 12 deletions cmake/templates/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ include(CMakeFindDependencyMacro)
find_dependency(Threads REQUIRED)
find_dependency(mimalloc QUIET)

# Get the linux kernel version to liburingcxx
message(STATUS "target_kernel_version = ${CMAKE_SYSTEM_VERSION}")
set(kernel_version ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+)\.([0-9]+)" kernel_version ${kernel_version})
string(REGEX MATCH "^([0-9]+)" kernel_version_major ${kernel_version})
string(REGEX REPLACE "^([0-9]+)\\." "" kernel_version_minor ${kernel_version})
message(STATUS "kernel_version_major = ${kernel_version_major}")
message(STATUS "kernel_version_minor = ${kernel_version_minor}")
add_compile_definitions(LIBURINGCXX_KERNEL_VERSION_MAJOR=${kernel_version_major})
add_compile_definitions(LIBURINGCXX_KERNEL_VERSION_MINOR=${kernel_version_minor})
unset(kernel_version)

include("${CMAKE_CURRENT_LIST_DIR}/co_context_targets.cmake")

check_required_components(co_context)
4 changes: 2 additions & 2 deletions example/iota.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef CO_CONTEXT_NO_GENERATOR
#if !CO_CONTEXT_NO_GENERATOR

#include <co_context/generator.hpp>

Expand All @@ -22,7 +22,7 @@ int main() {
return 0;
}

#else // ifndef CO_CONTEXT_NO_GENERATOR
#else // if !CO_CONTEXT_NO_GENERATOR

#include <iostream>

Expand Down
99 changes: 99 additions & 0 deletions extern/liburingcxx/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
Language: Cpp
AlignAfterOpenBracket: BlockIndent # BlockIndent
AlignArrayOfStructures: Right
AlignConsecutiveBitFields: "Consecutive"
AlignConsecutiveMacros: "Consecutive"
AlignEscapedNewlines: Left
AlignOperands: "Align"
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AlignConsecutiveShortCaseStatements: # clang-format 17
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCaseColons: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: false
BreakAfterAttributes: Leave # clang-format 16
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: false
ColumnLimit: 80
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
EmptyLineBeforeAccessModifier: Always
FixNamespaceComments: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequires: true # clang-format 14
IndentWrappedFunctionNames: false
InsertBraces: true # clang-format 15
InsertNewlineAtEOF: true # clang-format 16
IntegerLiteralSeparator: # clang-format 16
Binary: 8
Decimal: 0
Hex: 2
HexMinDigits: 8
LambdaBodyIndentation: Signature
LineEnding: LF # clang-format 16
KeepEmptyLinesAtEOF: false # clang-format 17
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PackConstructorInitializers: CurrentLine # clang-format 14
PointerAlignment: Right
QualifierAlignment: Left
ReflowComments: true
RequiresClausePosition: OwnLine # clang-format 15
RequiresExpressionIndentation: OuterScope # clang-format 16
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 5
SortIncludes: "CaseSensitive"
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: "Never"
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
UseCRLF: false
UseTab: Never
...
72 changes: 72 additions & 0 deletions extern/liburingcxx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# CMake
build/
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

# Visual Studio Code
.vscode/

# Local History for Visual Studio Code
.history/

# clangd
.cache/

# Built Visual Studio Code Extensions
*.vsix

draft/

perf.data*
*.data

# log for perf
log
tmp
*.rdb
*.svg

# public/index.html for httpd
public/
39 changes: 39 additions & 0 deletions extern/liburingcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.10.0)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(liburingcxx VERSION 0.9.0 LANGUAGES CXX)

if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
message(WARNING "io_uring is only supported by Linux, but the target OS is ${CMAKE_SYSTEM_NAME}.")
endif()

add_library(liburingcxx INTERFACE)
add_library(liburingcxx::liburingcxx ALIAS liburingcxx)

target_include_directories(
liburingcxx
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)

include(./cmake/option.cmake)
include(./cmake/configure.cmake)
include(./cmake/install.cmake)

if (LIBURINGCXX_BUILD_EXAMPLE OR LIBURINGCXX_BUILD_TEST)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
message("liburingcxx: Setting default CMAKE_BUILD_TYPE to Release.")
endif()

if(LIBURINGCXX_BUILD_TEST)
add_subdirectory(./test)
endif()

if(LIBURINGCXX_BUILD_EXAMPLE)
add_subdirectory(./example)
endif()
endif()
Loading
Loading