Skip to content

Commit b5890ea

Browse files
committed
reorganising lib structure
1 parent 862a265 commit b5890ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+800
-258
lines changed

CMakeLists.txt

+5-46
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,13 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmfind")
66
include(boilerplate)
77

88
add_library(cpputils INTERFACE)
9-
target_include_directories(cpputils INTERFACE .)
9+
target_include_directories(cpputils INTERFACE include)
1010

11-
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
12-
find_package(doctest REQUIRED)
13-
14-
file(GLOB UnittestSrc tests/*.cpp)
15-
if (WIN32)
16-
# skippoing this test on windows.
17-
list(REMOVE_ITEM UnittestSrc ${CMAKE_SOURCE_DIR}/tests/test-fhandle.cpp)
18-
endif()
19-
20-
# disable work-in-progress
21-
list(REMOVE_ITEM UnittestSrc ${CMAKE_SOURCE_DIR}/tests/test-makeasn1.cpp)
22-
23-
add_executable(unittests ${UnittestSrc})
24-
target_link_libraries(unittests cpputils doctest::doctest)
25-
target_compile_definitions(unittests PRIVATE USE_DOCTEST)
26-
27-
include(CTest)
28-
include(doctest)
29-
doctest_discover_tests(unittests)
11+
include(CTest)
12+
if(BUILD_TESTING)
13+
add_subdirectory(tests)
3014
endif()
3115

3216
if (OPT_BENCH)
33-
find_package(fmt REQUIRED)
34-
find_package(Boost REQUIRED COMPONENTS system)
35-
add_executable(fmt_string-boost fmtbench/fmt_string-boost.cpp)
36-
target_link_libraries(fmt_string-boost cpputils Boost::headers)
37-
38-
add_executable(fmt_string-fmt fmtbench/fmt_string-fmt.cpp)
39-
target_link_libraries(fmt_string-fmt cpputils fmt::fmt)
40-
add_executable(fmt_string-fmt2 fmtbench/fmt_string-fmt2.cpp)
41-
target_link_libraries(fmt_string-fmt2 cpputils fmt::fmt)
42-
add_executable(fmt_string-formatter fmtbench/fmt_string-formatter.cpp)
43-
target_link_libraries(fmt_string-formatter cpputils)
44-
add_executable(fmt_string-printf fmtbench/fmt_string-printf.cpp)
45-
#add_executable(fmt_string-std fmtbench/fmt_string-std.cpp)
46-
47-
48-
add_executable(fmt_print-boost fmtbench/fmt_print-boost.cpp)
49-
target_link_libraries(fmt_print-boost cpputils Boost::headers)
50-
51-
add_executable(fmt_print-fmt fmtbench/fmt_print-fmt.cpp)
52-
target_link_libraries(fmt_print-fmt cpputils fmt::fmt)
53-
add_executable(fmt_print-fmt2 fmtbench/fmt_print-fmt2.cpp)
54-
target_link_libraries(fmt_print-fmt2 cpputils fmt::fmt)
55-
add_executable(fmt_print-formatter fmtbench/fmt_print-formatter.cpp)
56-
target_link_libraries(fmt_print-formatter cpputils)
57-
add_executable(fmt_print-printf fmtbench/fmt_print-printf.cpp)
58-
#add_executable(fmt_print-std fmtbench/fmt_print-std.cpp)
17+
add_subdirectory(fmtbench)
5918
endif()

Findcpputils.cmake

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# NOTE: you can avoid downloading cpputils, by symlinking to a downloaded version here:
2+
if (TARGET cpputils)
3+
return()
4+
endif()
5+
find_path(CPPUTILS_DIR NAMES string-lineenum.h PATHS symlinks/cpputils)
6+
if(CPPUTILS_DIR STREQUAL "CPPUTILS_DIR-NOTFOUND")
7+
include(FetchContent)
8+
FetchContent_Populate(cpputils
9+
GIT_REPOSITORY https://github.com/nlitsme/cpputils)
10+
set(CPPUTILS_DIR ${cpputils_SOURCE_DIR})
11+
else()
12+
set(cpputils_BINARY_DIR ${CMAKE_BINARY_DIR}/cpputils-build)
13+
endif()
14+
15+
add_subdirectory(${CPPUTILS_DIR} ${cpputils_BINARY_DIR})
16+
17+
include(FindPackageHandleStandardArgs)
18+
find_package_handle_standard_args(cpputils REQUIRED_VARS CPPUTILS_DIR)
19+

Jenkinsfile

+5-89
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,15 @@
11
pipeline {
2-
agent none
2+
agent { label "windows" }
33
stages {
4-
stage("buildall") {
5-
matrix {
6-
agent {
7-
label "${label}"
8-
}
9-
axes {
10-
axis { name "label"; values "linux", "macos", "windows", "freebsd" }
11-
axis { name "compiler"; values "gcc", "clang_llvm", "clang_stdc", "default" }
12-
}
13-
excludes {
14-
exclude {
15-
axis { name "label"; values "windows" }
16-
axis { name "compiler"; values "gcc", "llvm" }
17-
}
18-
exclude {
19-
axis { name "label"; values "macos", 'linux' }
20-
axis { name "compiler"; values "default" }
21-
}
22-
}
23-
24-
stages {
25-
stage("clean") { steps { sh '''git clean -dfx''' } }
26-
stage("windows-build") {
27-
when { environment name: 'label', value: 'windows' }
28-
steps {
4+
stage("clean") { steps { sh '''git clean -dfx''' } }
5+
stage("windows-build") {
6+
steps {
297
sh '''#!/bin/bash
308
set -e
319
. /c/local/msvcenv.sh
32-
make vc
33-
./build/Debug/unittests.exe
10+
make vc BOOST_ROOT=c:/local/boost_1_74_0 idasdk=c:/local/idasdk75
3411
'''
35-
}
36-
}
37-
stage("unix-build") {
38-
when { not { environment name: 'label', value: 'windows' } }
39-
steps {
40-
sh '''#!/bin/bash
41-
set -e
42-
case "$label" in
43-
freebsd)
44-
MAKE=gmake
45-
CLANGSUFFIX=90
46-
GCCSUFFIX=10
47-
;;
48-
49-
macos)
50-
MAKE=make
51-
CLANGSUFFIX=
52-
GCCSUFFIX=-10
53-
;;
54-
55-
linux)
56-
MAKE=make
57-
CLANGSUFFIX=-10
58-
GCCSUFFIX=-10
59-
;;
60-
esac
61-
62-
case "$compiler" in
63-
clang*)
64-
MAKEARGS=(CXX=clang++$CLANGSUFFIX CC=clang$CLANGSUFFIX)
65-
;;
66-
gcc*)
67-
MAKEARGS=(CXX=g++$GCCSUFFIX CC=gcc$GCCSUFFIX)
68-
;;
69-
esac
70-
71-
case "$compiler" in
72-
clang_stdc)
73-
PREFIXARGS+=(CFLAGS=-stdlib=libstdc++)
74-
PREFIXARGS+=(LDFLAGS=-stdlib=libstdc++)
75-
;;
76-
clang_llvm)
77-
PREFIXARGS+=(CFLAGS=-stdlib=libc++)
78-
PREFIXARGS+=(LDFLAGS=-stdlib=libc++)
79-
;;
80-
esac
81-
MAKEARGS+=(cmake)
82-
eval "${PREFIXARGS[@]}" "$MAKE" "${MAKEARGS[@]}"
83-
84-
85-
./build/unittests
86-
'''
87-
}
88-
}
89-
}
9012
}
9113
}
92-
stage("toplevel-end")
93-
{
94-
steps { echo ".... the end ....." }
95-
}
9614
}
9715
}
98-
99-

Makefile

+62-24
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,71 @@
1-
CMAKEARGS+=$(if $(D),-DCMAKE_BUILD_TYPE=Debug,-DCMAKE_BUILD_TYPE=Release)
2-
CMAKEARGS+=$(if $(COV),-DOPT_COV=1)
3-
CMAKEARGS+=$(if $(PROF),-DOPT_PROF=1)
4-
CMAKEARGS+=$(if $(LIBCXX),-DOPT_LIBCXX=1)
5-
CMAKEARGS+=$(if $(STLDEBUG),-DOPT_STL_DEBUGGING=1)
6-
CMAKEARGS+=$(if $(SANITIZE),-DOPT_SANITIZE=1)
7-
CMAKEARGS+=$(if $(ANALYZE),-DOPT_ANALYZE=1)
8-
CMAKEARGS+=$(if $(BENCH),-DOPT_BENCH=1)
9-
10-
cmake:
11-
cmake -B build . $(CMAKEARGS)
12-
cmake --build build $(if $(V),--verbose)
1+
# targets:
2+
# all - build all binaries using cmake
3+
# ninja - build all binaries using google-ninja
4+
# vc - build all binaries using cmake + msvc
5+
# clean - remove the build directory
136

7+
# Transform Makefile arguments to CMake args
8+
CMAKEARGS_LOCAL+=$(if $(GENERATOR),-G"$(GENERATOR)")
9+
CMAKEARGS_LOCAL+=$(if $(D),-DCMAKE_BUILD_TYPE=Debug,-DCMAKE_BUILD_TYPE=Release)
10+
CMAKEARGS_LOCAL+=$(if $(LOG),-DOPT_LOGGING=ON)
11+
CMAKEARGS_LOCAL+=$(if $(and $(LOG), $(D)),-DOPT_LOGGING_UDP=ON)
12+
CMAKEARGS_LOCAL+=$(if $(COV),-DOPT_COV=1)
13+
CMAKEARGS_LOCAL+=$(if $(SYM),-DOPT_SYMBOLS=1)
14+
CMAKEARGS_LOCAL+=$(if $(PROF),-DOPT_PROF=1)
15+
CMAKEARGS_LOCAL+=$(if $(LIBCXX),-DOPT_LIBCXX=1)
16+
CMAKEARGS_LOCAL+=$(if $(STLDEBUG),-DOPT_STL_DEBUGGING=1)
17+
CMAKEARGS_LOCAL+=$(if $(SANITIZE),-DOPT_ASAN=1) # backward compatibility
18+
CMAKEARGS_LOCAL+=$(if $(ASAN),-DOPT_ASAN=1)
19+
CMAKEARGS_LOCAL+=$(if $(TSAN),-DOPT_TSAN=1)
20+
CMAKEARGS_LOCAL+=$(if $(CLANGTIDY),-DOPT_CLANG_TIDY=1)
21+
CMAKEARGS_LOCAL+=$(if $(ANALYZE),-DOPT_ANALYZE=1)
22+
CMAKEARGS_LOCAL+=$(if $(TEST),-DBUILD_TESTING=1)
23+
CMAKEARGS_LOCAL+=$(if $(TOOLS),-DBUILD_TOOLS=1)
24+
CMAKEARGS_LOCAL+=$(if $(COMPCMD),-DOPT_COMPILE_COMMANDS=1)
25+
CMAKEARGS_LOCAL+=$(if $(BENCH),-DOPT_BENCH=1)
26+
27+
# add user provided CMAKEARGS
28+
CMAKEARGS_LOCAL+=$(CMAKEARGS)
29+
30+
CMAKE=cmake
31+
CTEST=ctest
32+
33+
.DEFAULT_GOAL:=all
34+
.PHONY: all
35+
all: build
36+
37+
38+
# uses os default generator (if not GENERATOR is provided)
39+
.PHONY: generate
40+
generate:
41+
$(CMAKE) -B build $(CMAKEARGS_LOCAL)
42+
43+
JOBSFLAG=$(filter -j%,$(MAKEFLAGS))
44+
# only build without regenerating build system files (prevents overwrite of previous provided ARGS for generate)
45+
.PHONY: build
46+
build: generate
47+
$(CMAKE) --build build $(JOBSFLAG) $(if $(V),--verbose) --config $(if $(D),Debug,Release)
48+
49+
# runs all tests
1450
ctest: TEST=1
15-
ctest: cmake
16-
cd build && ctest --verbose
51+
ctest: all
52+
$(CTEST) --verbose --test-dir build -C $(if $(D),Debug,Release) $(TESTARGS)
1753

18-
VC_CMAKE=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe
19-
vc:
20-
"$(VC_CMAKE)" -G"Visual Studio 16 2019" -B build . $(CMAKEARGS)
21-
"$(VC_CMAKE)" --build build $(if $(V),--verbose)
54+
llvm: export CC=clang
55+
llvm: export CXX=clang++
56+
llvm: all
2257

23-
llvm:
24-
CC=clang CXX=clang++ cmake -B build . $(CMAKEARGS)
25-
cmake --build build $(if $(V),--verbose)
2658

2759
SCANBUILD=$(firstword $(wildcard /usr/bin/scan-build*))
28-
llvmscan:
29-
CC=clang CXX=clang++ cmake -B build . $(CMAKEARGS)
30-
$(SCANBUILD) cmake --build build $(if $(V),--verbose)
60+
scan: CMAKE:=$(SCANBUILD) -o $$(pwd)/build/scanbuild $(CMAKE)
61+
scan: ctest
62+
63+
64+
CMAKE_BIN:=${PROGRAMFILES}\CMake\bin
65+
vc: CMAKE:="$(CMAKE_BIN)/cmake.exe"
66+
vc: GENERATOR=Visual Studio 16 2019
67+
vc: CMAKEARGS+=$(VC_CMAKEARGS)
68+
vc: all
3169

3270

3371
clean:

0 commit comments

Comments
 (0)