Skip to content

Commit

Permalink
Merge pull request #11 from sjinks/refactor-cmake
Browse files Browse the repository at this point in the history
build: refactoring
  • Loading branch information
sjinks authored Jan 19, 2024
2 parents 67daccc + 87783b5 commit d41cb25
Show file tree
Hide file tree
Showing 8 changed files with 401 additions and 79 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!CMakeLists.txt
!cmake
!src
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_VERBOSE_MAKEFILE ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

project(tfhttp VERSION 1.0.0 LANGUAGES CXX C)

add_subdirectory(src)
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ FROM ubuntu:mantic-20231128@sha256:cbc171ba52575fec0601f01abf6fdec67f8ed227658ca

ENV DEBIAN_FRONTEND=noninteractive

# Do not install libsqlite3-dev because we want to it without dynamic extension support; we need tcl to build amalgamated version
# Do not install libsqlite3-dev because we want to it without dynamic extension support. It requires tcl.
# Do not install libev-dev because we want to use a custom build.
RUN \
apt-get update && \
apt-get install -y --no-install-recommends ca-certificates cmake git clang make python3-minimal python3-whichcraft nlohmann-json3-dev libev-dev pkgconf tcl && \
apt-get install -y --no-install-recommends ca-certificates cmake file git clang make nlohmann-json3-dev pkgconf tcl && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
COPY . /app
WORKDIR /app

RUN \
cmake -B build -DCMAKE_BUILD_TYPE=MinSizeRel && \
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC_BINARY=off -DBUILD_MOSTLY_STATIC_BINARY=on -DFORCE_EXTERNAL_LIBEV=on && \
cmake --build build && \
strip --strip-unneeded build/src/tfhttp

FROM scratch
FROM cgr.dev/chainguard/glibc-dynamic:latest@sha256:6895a08124484dcab1daa40861ebe814290e0a48aab71cdd3eccc75de0c045ce
COPY --from=build /app/build/src/tfhttp /tfhttp
ENTRYPOINT ["/tfhttp"]
55 changes: 55 additions & 0 deletions cmake/Findlibada.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# - Try to find libev
# Once done this will define
# LIBADA_FOUND - System has libada
# LIBADA_INCLUDE_DIRS - The libada include directories
# LIBADA_LIBRARIES - The libraries needed to use libada
# LIBADA_STATIC_INCLUDE_DIRS - The libada static include directories
# LIBADA_STATIC_LIBRARIES - The libraries needed to use libada statically

find_path(
LIBADA_INCLUDE_DIR
NAMES ada.h
)

set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}")
find_library(LIBADA_STATIC_LIBRARY NAMES ada)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_SHARED_LIBRARY_SUFFIX}")
find_library(LIBADA_SHARED_LIBRARY NAMES ada)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${SAVED_CMAKE_FIND_LIBRARY_SUFFIXES}")
unset(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES)

if(LIBADA_SHARED_LIBRARY)
set(LIBADA_LIBRARY ${LIBADA_SHARED_LIBRARY})
elseif(LIBADA_STATIC_LIBRARY)
set(LIBADA_LIBRARY ${LIBADA_STATIC_LIBRARY})
endif()

if(LIBADA_INCLUDE_DIR)
file(STRINGS "${LIBADA_INCLUDE_DIR}/ada/ada_version.h" LIBADA_VERSION REGEX "^#define[ \t]ADA_VERSION[ \t]\"[^\"]+\"$")
string(REGEX REPLACE "\"([^\"]+)\"" "\\1" LIBADA_VERSION "${LIBADA_VERSION}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
libada
REQUIRED_VARS LIBADA_LIBRARY LIBADA_INCLUDE_DIR
VERSION_VAR LIBADA_VERSION
)

if(LIBADA_FOUND)
if(LIBADA_SHARED_LIBRARY)
set(LIBADA_LIBRARIES ${LIBADA_SHARED_LIBRARY})
else()
set(LIBADA_LIBRARIES ${LIBADA_STATIC_LIBRARY})
endif()

set(LIBADA_INCLUDE_DIRS ${LIBADA_INCLUDE_DIR})

set(LIBADA_STATIC_INCLUDE_DIRS ${LIBADA_INCLUDE_DIRS})
if(LIBADA_STATIC_LIBRARY)
set(LIBADA_STATIC_LIBRARIES ${LIBADA_STATIC_LIBRARY})
endif()
endif()

mark_as_advanced(LIBADA_INCLUDE_DIR LIBADA_SHARED_LIBRARY LIBADA_STATIC_LIBRARY)
68 changes: 68 additions & 0 deletions cmake/Findlibev.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# - Try to find libev
# Once done this will define
# LIBEV_FOUND - System has libev
# LIBEV_INCLUDE_DIRS - The libev include directories
# LIBEV_LIBRARIES - The libraries needed to use libev
# LIBEV_STATIC_INCLUDE_DIRS - The libev static include directories
# LIBEV_STATIC_LIBRARIES - The libraries needed to use libev statically

find_path(
LIBEV_INCLUDE_DIR
NAMES ev.h
)

set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}")
find_library(LIBEV_STATIC_LIBRARY NAMES ev)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_SHARED_LIBRARY_SUFFIX}")
find_library(LIBEV_SHARED_LIBRARY NAMES ev)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${SAVED_CMAKE_FIND_LIBRARY_SUFFIXES}")
unset(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES)

if(LIBEV_SHARED_LIBRARY)
set(LIBEV_LIBRARY ${LIBEV_SHARED_LIBRARY})
elseif(LIBEV_STATIC_LIBRARY)
set(LIBEV_LIBRARY ${LIBEV_STATIC_LIBRARY})
endif()

if(LIBEV_INCLUDE_DIR)
file(
STRINGS "${LIBEV_INCLUDE_DIR}/ev.h"
LIBEV_VERSION_MAJOR REGEX "^#define[ \t]+EV_VERSION_MAJOR[ \t]+[0-9]+"
)

file(
STRINGS "${LIBEV_INCLUDE_DIR}/ev.h"
LIBEV_VERSION_MINOR REGEX "^#define[ \t]+EV_VERSION_MINOR[ \t]+[0-9]+"
)

string(REGEX REPLACE "[^0-9]+" "" LIBEV_VERSION_MAJOR "${LIBEV_VERSION_MAJOR}")
string(REGEX REPLACE "[^0-9]+" "" LIBEV_VERSION_MINOR "${LIBEV_VERSION_MINOR}")
set(LIBEV_VERSION "${LIBEV_VERSION_MAJOR}.${LIBEV_VERSION_MINOR}")
unset(LIBEV_VERSION_MINOR)
unset(LIBEV_VERSION_MAJOR)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
libev
REQUIRED_VARS LIBEV_LIBRARY LIBEV_INCLUDE_DIR
VERSION_VAR LIBEV_VERSION
)

if(LIBEV_FOUND)
if(LIBEV_SHARED_LIBRARY)
set(LIBEV_LIBRARIES ${LIBEV_SHARED_LIBRARY})
else()
set(LIBEV_LIBRARIES ${LIBEV_STATIC_LIBRARY};m)
endif()

set(LIBEV_INCLUDE_DIRS ${LIBEV_INCLUDE_DIR})

set(LIBEV_STATIC_INCLUDE_DIRS ${LIBEV_INCLUDE_DIRS})
if(LIBEV_STATIC_LIBRARY)
set(LIBEV_STATIC_LIBRARIES ${LIBEV_STATIC_LIBRARY};m)
endif()
endif()

mark_as_advanced(LIBEV_INCLUDE_DIR LIBEV_SHARED_LIBRARY LIBEV_STATIC_LIBRARY)
63 changes: 63 additions & 0 deletions cmake/Findlibllhttp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# - Try to find libev
# Once done this will define
# LIBLLHTTP_FOUND - System has llhttp
# LIBLLHTTP_INCLUDE_DIRS - The llhttp include directories
# LIBLLHTTP_LIBRARIES - The libraries needed to use llhttp
# LIBLLHTTP_STATIC_INCLUDE_DIRS - The llhttp static include directories
# LIBLLHTTP_STATIC_LIBRARIES - The libraries needed to use llhttp statically

pkg_check_modules(LIBLLHTTP QUIET llhttp)
if (NOT LIBLLHTTP_FOUND)
find_path(
LIBLLHTTP_INCLUDE_DIR
NAMES llhttp.h
)

set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}")
find_library(LIBLLHTTP_STATIC_LIBRARY NAMES llhttp)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_SHARED_LIBRARY_SUFFIX}")
find_library(LIBLLHTTP_SHARED_LIBRARY NAMES llhttp)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${SAVED_CMAKE_FIND_LIBRARY_SUFFIXES}")
unset(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES)

if(LIBLLHTTP_SHARED_LIBRARY)
set(LIBLLHTTP_LIBRARY ${LIBLLHTTP_SHARED_LIBRARY})
elseif(LIBLLHTTP_STATIC_LIBRARY)
set(LIBLLHTTP_LIBRARY ${LIBLLHTTP_STATIC_LIBRARY})
endif()

if(LIBLLHTTP_INCLUDE_DIR)
file(STRINGS "${LIBLLHTTP_INCLUDE_DIR}/llhttp.h" LIBLLHTTP_VERSION_MAJOR REGEX "^#define[ \t]+LLHTTP_VERSION_MAJOR[ \t]+[0-9]+")
file(STRINGS "${LIBLLHTTP_INCLUDE_DIR}/llhttp.h" LIBLLHTTP_VERSION_MINOR REGEX "^#define[ \t]+LLHTTP_VERSION_MINOR[ \t]+[0-9]+")
string(REGEX REPLACE "[^0-9]+" "" LIBLLHTTP_VERSION_MAJOR "${LIBLLHTTP_VERSION_MAJOR}")
string(REGEX REPLACE "[^0-9]+" "" LIBLLHTTP_VERSION_MINOR "${LIBLLHTTP_VERSION_MINOR}")
set(LIBLLHTTP_VERSION "${LIBLLHTTP_VERSION_MAJOR}.${LIBLLHTTP_VERSION_MINOR}")
unset(LIBLLHTTP_VERSION_MINOR)
unset(LIBLLHTTP_VERSION_MAJOR)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
libllhttp
REQUIRED_VARS LIBLLHTTP_LIBRARY LIBLLHTTP_INCLUDE_DIR
VERSION_VAR LIBLLHTTP_VERSION
)

if(LIBLLHTTP_FOUND)
if(LIBLLHTTP_SHARED_LIBRARY)
set(LIBLLHTTP_LIBRARIES ${LIBLLHTTP_SHARED_LIBRARY})
else()
set(LIBLLHTTP_LIBRARIES ${LIBLLHTTP_STATIC_LIBRARY})
endif()

set(LIBLLHTTP_INCLUDE_DIRS ${LIBLLHTTP_INCLUDE_DIR})

set(LIBLLHTTP_STATIC_INCLUDE_DIRS ${LIBLLHTTP_INCLUDE_DIRS})
if(LIBLLHTTP_STATIC_LIBRARY)
set(LIBLLHTTP_STATIC_LIBRARIES ${LIBLLHTTP_STATIC_LIBRARY})
endif()
endif()

mark_as_advanced(LIBLLHTTP_INCLUDE_DIR LIBLLHTTP_SHARED_LIBRARY LIBLLHTTP_STATIC_LIBRARY)
endif()
58 changes: 58 additions & 0 deletions cmake/Findlibsqlite3.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# - Try to find libev
# Once done this will define
# LIBSQLITE3_FOUND - System has libsqlite3
# LIBSQLITE3_INCLUDE_DIRS - The libsqlite3 include directories
# LIBSQLITE3_LIBRARIES - The libraries needed to use libsqlite3
# LIBSQLITE3_STATIC_INCLUDE_DIRS - The libsqlite3 static include directories
# LIBSQLITE3_STATIC_LIBRARIES - The libraries needed to use libsqlite3 statically

pkg_check_modules(LIBSQLITE3 QUIET sqlite3)
if (NOT LIBSQLITE3_FOUND)
find_path(
LIBSQLITE3_INCLUDE_DIR
NAMES sqlite3.h
)

set(SAVED_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}")
find_library(LIBSQLITE3_STATIC_LIBRARY NAMES sqlite3)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_SHARED_LIBRARY_SUFFIX}")
find_library(LIBSQLITE3_SHARED_LIBRARY NAMES sqlite3)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${SAVED_CMAKE_FIND_LIBRARY_SUFFIXES}")

if(LIBSQLITE3_SHARED_LIBRARY)
set(LIBSQLITE3_LIBRARY ${LIBSQLITE3_SHARED_LIBRARY})
elseif(LIBSQLITE3_STATIC_LIBRARY)
set(LIBSQLITE3_LIBRARY ${LIBSQLITE3_STATIC_LIBRARY})
endif()

if(LIBSQLITE3_INCLUDE_DIR)
file(STRINGS ${LIBSQLITE3_INCLUDE_DIR}/sqlite3.h _ver_line REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\"" LIMIT_COUNT 1)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBSQLITE3_VERSION "${_ver_line}")
unset(_ver_line)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
libsqlite3
REQUIRED_VARS LIBSQLITE3_LIBRARY LIBSQLITE3_INCLUDE_DIR
VERSION_VAR LIBSQLITE3_VERSION
)

if(LIBSQLITE3_FOUND)
if(LIBSQLITE3_SHARED_LIBRARY)
set(LIBSQLITE3_LIBRARIES ${LIBSQLITE3_SHARED_LIBRARY})
else()
set(LIBSQLITE3_LIBRARIES ${LIBSQLITE3_STATIC_LIBRARY})
endif()

set(LIBSQLITE3_INCLUDE_DIRS ${LIBSQLITE3_INCLUDE_DIR})

set(LIBSQLITE3_STATIC_INCLUDE_DIRS ${LIBSQLITE3_INCLUDE_DIRS})
if(LIBSQLITE3_STATIC_LIBRARY)
set(LIBSQLITE3_STATIC_LIBRARIES ${LIBSQLITE3_STATIC_LIBRARY})
endif()
endif()

mark_as_advanced(LIBSQLITE3_INCLUDE_DIR LIBSQLITE3_SHARED_LIBRARY LIBSQLITE3_STATIC_LIBRARY)
endif()
Loading

0 comments on commit d41cb25

Please sign in to comment.