Skip to content

cmake experiment #220

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
89 changes: 89 additions & 0 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
pull_request:
branches: [ main ]

env:
# Path to the CMake build directory.
build: '${{ github.workspace }}/build'
config: 'Debug'

jobs:
cancel-old-build:

Expand All @@ -14,6 +19,90 @@ jobs:
with:
access_token: ${{ github.token }}

msvc-analyze:
name: MSVC Analyze
runs-on: windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Configure CMake
run: cmake -B ${{ env.build }} -DCMAKE_BUILD_TYPE=${{ env.config }}

# Build is not required unless generated source files are used
# - name: Build CMake
# run: cmake --build ${{ env.build }} --config ${{ env.config }}

- name: Run MSVC Code Analysis
uses: microsoft/msvc-code-analysis-action@v0.1.1
# Provide a unique ID to access the sarif output path
id: run-analysis
with:
cmakeBuildDirectory: ${{ env.build }}
buildConfiguration: ${{ env.config }}
# Ruleset file that will determine what checks will be run
ruleset: NativeRecommendedRules.ruleset
# Paths to ignore analysis of CMake targets and includes
# ignoredPaths: ${{ github.workspace }}/dependencies;${{ github.workspace }}/test

# Upload SARIF file to GitHub Code Scanning Alerts
- name: Upload SARIF to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.run-analysis.outputs.sarif }}

# Upload SARIF file as an Artifact to download and view
- name: Upload SARIF as an Artifact
uses: actions/upload-artifact@v2
with:
name: sarif-file
path: ${{ steps.run-analysis.outputs.sarif }}

codeql-analyze:
name: CodeQL Analyze
runs-on: 'ubuntu-latest'
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: cpp
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# Command-line programs to run using the OS shell.
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:cpp"

build-linux:

runs-on: ubuntu-latest
Expand Down
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)

# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

project ("longtail")

enable_language(C)
enable_language(ASM)
enable_language(CXX)

#add_compile_definitions(ZSTD_DISABLE_ASM)

# Include sub-projects.
add_subdirectory("lib")

add_subdirectory("src")

add_subdirectory("static_lib")

#add_subdirectory("shared_lib")

add_subdirectory ("cmd")

add_subdirectory("test")

enable_testing()

add_test(NAME test COMMAND test_base WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test)
125 changes: 125 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"version": 3,
"configurePresets": [
{
"name": "windows-gcc-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc.exe",
"CMAKE_CXX_COMPILER": "g++.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-release",
"displayName": "x64 Release",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "x64-gcc-debug",
"displayName": "x64 GCC Debug",
"inherits": "windows-gcc-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-gcc-release",
"displayName": "x64 GCC Release",
"inherits": "x64-gcc-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux-debug",
"displayName": "Linux Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
},
{
"name": "macos-debug",
"displayName": "macOS Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
}
],
"testPresets": [
{
"name": "testPresets",
"displayName": "Custom test preset",
"description": "Custom test preset description",
"configurePreset": "x64-debug"
}
]
}
14 changes: 14 additions & 0 deletions cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# CMakeList.txt : CMake project for longtail, include source and define
# project specific logic here.
#

# Add source to this project's executable.
add_executable (longtail "main.c" "ext/kgflags.h")

if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET longtail PROPERTY CXX_STANDARD 20)
endif()

# TODO: Add tests and install targets if needed.
target_link_libraries(longtail PRIVATE static_lib)

50 changes: 25 additions & 25 deletions cmd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "../lib/meowhash/longtail_meowhash.h"
#include "../lib/ratelimitedprogress/longtail_ratelimitedprogress.h"
#include "../lib/shareblockstore/longtail_shareblockstore.h"
#include "../lib/brotli/longtail_brotli.h"
//#include "../lib/brotli/longtail_brotli.h"
#include "../lib/lz4/longtail_lz4.h"
#include "../lib/zstd/longtail_zstd.h"
#include "../lib/longtail_platform.h"
Expand Down Expand Up @@ -172,30 +172,30 @@ uint32_t ParseCompressionType(const char* compression_algorithm) {
{
return 0;
}
if (strcmp("brotli", compression_algorithm) == 0)
{
return Longtail_GetBrotliGenericDefaultQuality();
}
if (strcmp("brotli_min", compression_algorithm) == 0)
{
return Longtail_GetBrotliGenericMinQuality();
}
if (strcmp("brotli_max", compression_algorithm) == 0)
{
return Longtail_GetBrotliGenericMaxQuality();
}
if (strcmp("brotli_text", compression_algorithm) == 0)
{
return Longtail_GetBrotliTextDefaultQuality();
}
if (strcmp("brotli_text_min", compression_algorithm) == 0)
{
return Longtail_GetBrotliTextMinQuality();
}
if (strcmp("brotli_text_max", compression_algorithm) == 0)
{
return Longtail_GetBrotliTextMaxQuality();
}
// if (strcmp("brotli", compression_algorithm) == 0)
// {
// return Longtail_GetBrotliGenericDefaultQuality();
// }
// if (strcmp("brotli_min", compression_algorithm) == 0)
// {
// return Longtail_GetBrotliGenericMinQuality();
// }
// if (strcmp("brotli_max", compression_algorithm) == 0)
// {
// return Longtail_GetBrotliGenericMaxQuality();
// }
// if (strcmp("brotli_text", compression_algorithm) == 0)
// {
// return Longtail_GetBrotliTextDefaultQuality();
// }
// if (strcmp("brotli_text_min", compression_algorithm) == 0)
// {
// return Longtail_GetBrotliTextMinQuality();
// }
// if (strcmp("brotli_text_max", compression_algorithm) == 0)
// {
// return Longtail_GetBrotliTextMaxQuality();
// }
if (strcmp("lz4", compression_algorithm) == 0)
{
return Longtail_GetLZ4DefaultQuality();
Expand Down
24 changes: 24 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
add_library(platform STATIC "longtail_platform.c" "longtail_platform.h")

add_subdirectory ("archiveblockstore")
add_subdirectory ("atomiccancel")
add_subdirectory ("bikeshed")
add_subdirectory ("blake2")
add_subdirectory ("blake3")
add_subdirectory ("blockstorestorage")
add_subdirectory ("brotli")
add_subdirectory ("cacheblockstore")
add_subdirectory ("compressblockstore")
add_subdirectory ("compressionregistry")
add_subdirectory ("filestorage")
add_subdirectory ("fsblockstore")
add_subdirectory ("hashregistry")
add_subdirectory ("hpcdcchunker")
add_subdirectory ("lrublockstore")
add_subdirectory ("lz4")
add_subdirectory ("memstorage")
add_subdirectory ("memtracer")
add_subdirectory ("meowhash")
add_subdirectory ("ratelimitedprogress")
add_subdirectory ("shareblockstore")
add_subdirectory ("zstd")
1 change: 1 addition & 0 deletions lib/archiveblockstore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(archiveblockstore OBJECT "longtail_archiveblockstore.c" "longtail_archiveblockstore.h")
1 change: 1 addition & 0 deletions lib/atomiccancel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(atomiccancel OBJECT "longtail_atomiccancel.c" "longtail_atomiccancel.h")
1 change: 1 addition & 0 deletions lib/bikeshed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(bikeshed OBJECT "longtail_bikeshed.c" "longtail_bikeshed.h" "ext/bikeshed.h")
19 changes: 19 additions & 0 deletions lib/blake2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
add_library(blake2 OBJECT
"longtail_blake2.c"
"longtail_blake2.h"
"ext/blake2-config.h"
"ext/blake2-impl.h"
"ext/blake2.h"
"ext/blake2s-load-sse2.h"
"ext/blake2s-load-sse41.h"
"ext/blake2s-round.h"
"ext/blake2s.c"
)

if(MSVC)
target_compile_options(blake2 INTERFACE /arch:SSE2)
target_compile_options(blake2 PUBLIC -DHAVE_SSE2)
else()
target_compile_options(blake2 PUBLIC -msse2)
endif(MSVC)

Loading