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

Lw/static lib #812

Merged
merged 3 commits into from
Oct 3, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ jobs:
tools/ci/run_ci.sh \
--run-clean \
--run-build \
--source-directory examples/${{ matrix.example }}
--source-directory examples/${{ matrix.example }} \
--build-directory wakaama-build-${{ matrix.example }}
LukasWoodtli marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 21 additions & 12 deletions tools/ci/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ OPT_SANITIZER=""
OPT_SCAN_BUILD=""
OPT_SONARQUBE=""
OPT_SOURCE_DIRECTORY="${REPO_ROOT_DIR}"
OPT_BUILD_DIRECTORY="build-wakaama"
OPT_TEST_COVERAGE_REPORT=""
OPT_VERBOSE=0
OPT_WRAPPER_CMD=""
Expand Down Expand Up @@ -58,6 +59,9 @@ Options:
(BINARY: defaults to ${OPT_CLANG_FORMAT})
--source-directory PATH Configure CMake using PATH instead of the
repositories root directory.
--build-directory PATH Configure CMake using PATH as the build directory.
Defaults to 'build-wakaama'. Builds from CMake
presets are placed into 'build-presets' by default.
--sanitizer TYPE Enable sanitizer
(TYPE: address leak thread undefined)
--scan-build BINARY Enable Clang code analyzer using specified
Expand Down Expand Up @@ -112,7 +116,7 @@ function run_clang_format() {
}

function run_clean() {
rm -rf build-wakaama
rm -rf "${OPT_BUILD_DIRECTORY}"
rm -rf build-presets
}

Expand Down Expand Up @@ -147,12 +151,12 @@ function run_git_blame_ignore() {

function run_build() {
# Existing directory needed by SonarQube build-wrapper
mkdir -p build-wakaama
mkdir -p "${OPT_BUILD_DIRECTORY}"

echo "Default build"
${OPT_WRAPPER_CMD} cmake -GNinja -S ${OPT_SOURCE_DIRECTORY} -B build-wakaama \
-DWAKAAMA_MODE_SERVER=ON -DWAKAAMA_PLATFORM=POSIX ${CMAKE_ARGS}
${OPT_WRAPPER_CMD} cmake --build build-wakaama
${OPT_WRAPPER_CMD} cmake -GNinja -S ${OPT_SOURCE_DIRECTORY} -B "${OPT_BUILD_DIRECTORY}" \
-DWAKAAMA_PLATFORM=POSIX ${CMAKE_ARGS}
${OPT_WRAPPER_CMD} cmake --build "${OPT_BUILD_DIRECTORY}"

# CMake presets
echo "CMake presets build"
Expand All @@ -167,15 +171,15 @@ function run_tests() {
export CTEST_OUTPUT_ON_FAILURE=ON

echo "Default test run"
cmake --build build-wakaama --target test
cmake --build "${OPT_BUILD_DIRECTORY}" --target test

echo "CMake presets test run"
for i in $(cmake --list-presets build | awk '/"/{ print $1 }' | tr -d '"');do
echo "CMake preset $i"
cmake --build --preset "$i" --target test
done

mkdir -p "${REPO_ROOT_DIR}/build-wakaama/coverage"
mkdir -p "${REPO_ROOT_DIR}/${OPT_BUILD_DIRECTORY}/coverage"

if [ -z "${OPT_TEST_COVERAGE_REPORT}" ]; then
return 0
Expand All @@ -189,15 +193,15 @@ function run_tests() {
case "${OPT_TEST_COVERAGE_REPORT}" in
xml)
gcovr_out="--xml"
gcovr_file=("${REPO_ROOT_DIR}/build-wakaama/coverage/report.xml")
gcovr_file=("${REPO_ROOT_DIR}/${OPT_BUILD_DIRECTORY}/coverage/report.xml")
;;
html)
gcovr_out="--html --html-details"
gcovr_file=("${REPO_ROOT_DIR}/build-wakaama/coverage/report.html")
gcovr_file=("${REPO_ROOT_DIR}/${OPT_BUILD_DIRECTORY}/coverage/report.html")
;;
text)
gcovr_out=""
gcovr_file=("${REPO_ROOT_DIR}/build-wakaama/coverage/report.txt")
gcovr_file=("${REPO_ROOT_DIR}/${OPT_BUILD_DIRECTORY}/coverage/report.txt")
;;
none)
gcovr "${gcovr_opts[@]}" >/dev/null
Expand Down Expand Up @@ -251,6 +255,7 @@ if ! PARSED_OPTS=$($getopt -o vah \
-l scan-build: \
-l sonarqube: \
-l source-directory: \
-l build-directory: \
-l test-coverage: \
-l verbose \
--name "${SCRIPT_NAME}" -- "$@");
Expand Down Expand Up @@ -330,6 +335,10 @@ while true; do
OPT_SOURCE_DIRECTORY=$2
shift 2
;;
--build-directory)
OPT_BUILD_DIRECTORY=$2
shift 2
;;
--test-coverage)
OPT_TEST_COVERAGE_REPORT=$2
shift 2
Expand Down Expand Up @@ -391,7 +400,7 @@ fi
if [ -n "${OPT_SONARQUBE}" ]; then
OPT_TEST_COVERAGE_REPORT="${OPT_TEST_COVERAGE_REPORT:-none}"
OPT_WRAPPER_CMD="${OPT_SONARQUBE} \
--out-dir build-wakaama/sonar-cloud-build-wrapper-output"
--out-dir ${OPT_BUILD_DIRECTORY}/sonar-cloud-build-wrapper-output"
fi

if [ -n "${OPT_TEST_COVERAGE_REPORT}" ]; then
Expand All @@ -403,7 +412,7 @@ if [ -n "${OPT_SCAN_BUILD}" ]; then
# `CUnit` which leads to a lot of noisy issues in the report.
# Also ignoring third-party `tinydtls` library.
OPT_WRAPPER_CMD="${OPT_SCAN_BUILD} \
-o build-wakaama/clang-static-analyzer \
-o ${OPT_BUILD_DIRECTORY}/clang-static-analyzer \
--exclude tests \
--exclude examples/shared/tinydtls"
fi
Expand Down
30 changes: 30 additions & 0 deletions wakaama.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ option(WAKAAMA_MODE_SERVER "Enable LWM2M Server interfaces" OFF)
option(WAKAAMA_MODE_BOOTSTRAP_SERVER "Enable LWM2M Bootstrap Server interfaces" OFF)
option(WAKAAMA_MODE_CLIENT "Enable LWM2M Client interfaces" OFF)

if(NOT WAKAAMA_MODE_SERVER
AND NOT WAKAAMA_MODE_BOOTSTRAP_SERVER
AND NOT WAKAAMA_MODE_CLIENT
)
message(WARNING "No mode selected. Defaulting to 'WAKAAMA_MODE_SERVER'")
set(WAKAAMA_MODE_SERVER ON)
endif()

# Client
option(WAKAAMA_CLIENT_INITIATED_BOOTSTRAP "Enable client initiated bootstrap support in a client" OFF)
option(WAKAAMA_CLIENT_LWM2M_V_1_0 "Restrict the client code to use LwM2M version 1.0" OFF)
Expand Down Expand Up @@ -315,6 +323,28 @@ function(target_sources_shared target)
target_include_directories(${target} PUBLIC ${WAKAAMA_EXAMPLE_SHARED_DIRECTORY})
endfunction()

# Static library that users of Wakaama can link against
LukasWoodtli marked this conversation as resolved.
Show resolved Hide resolved
#
# This library simplifies building and maintaining Wakaama. It handles defines and compiler flags, adding the right
# source files and setting include directories...
add_library(wakaama_static STATIC)
target_sources_wakaama(wakaama_static)
target_include_directories(wakaama_static PUBLIC ${WAKAAMA_TOP_LEVEL_DIRECTORY}/include/)

if(WAKAAMA_TRANSPORT STREQUAL POSIX_UDP)
target_link_libraries(wakaama_static PUBLIC wakaama_transport_posix_udp)
elseif(WAKAAMA_TRANSPORT STREQUAL TINYDTLS)
target_link_libraries(wakaama_static PUBLIC wakaama_transport_tinydtls)
endif()

if(WAKAAMA_PLATFORM STREQUAL POSIX)
target_link_libraries(wakaama_static PUBLIC wakaama_platform_posix)
endif()

if(WAKAAMA_CLI)
target_link_libraries(wakaama_static PUBLIC wakaama_command_line)
endif()

# Enforce a certain level of hygiene
add_compile_options(
-Waggregate-return
Expand Down
Loading