Skip to content

Commit

Permalink
Update nx version (#65)
Browse files Browse the repository at this point in the history
* Update nx version

* Run clang-format

* Fix spelling

* Fix spelling issues

* Fix clang format
  • Loading branch information
jfantinhardesty authored Nov 19, 2024
1 parent c1e3a14 commit f84158e
Show file tree
Hide file tree
Showing 80 changed files with 692 additions and 351 deletions.
8 changes: 5 additions & 3 deletions dependencies/nx_kit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ if(MSVC)
endif()

# Set the maximum warning level.
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
if(MSVC)
# This block covers not only Visual Studio compiler but also clang-cl, which expands /W4 to
# the -Wall flag, while -Wall itself, if passed directly, will be expanded to -Weverything.
add_compile_options(/W4 /WX /utf-8)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Wall -Wextra -Werror)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(/W4 /WX)
endif()

set(nxKitWithTests "YES" CACHE STRING "Whether to build unit tests")
Expand Down
70 changes: 70 additions & 0 deletions dependencies/nx_kit/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
:: Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/

@echo off
setlocal %= Reset errorlevel and prohibit changing env vars of the parent shell. =%

if [%1] == [/?] goto :show_usage
if [%1] == [-h] goto :show_usage
if [%1] == [--help] goto :show_usage
goto :skip_show_usage
:show_usage
echo Usage: %~n0%~x0 [--no-tests] [--debug] [^<cmake-generation-args^>...]
echo --debug Compile using Debug configuration (without optimizations) instead of Release.
goto :exit
:skip_show_usage

:: Make the build dir at the same level as the parent dir of this script, suffixed with "-build".
set BASE_DIR_WITH_BACKSLASH=%~dp0
set BASE_DIR=%BASE_DIR_WITH_BACKSLASH:~0,-1%
set BUILD_DIR=%BASE_DIR%-build

:: Try to find the vcvars64.bat script, assuming that build_nx_kit.bat runs from the
:: "open/artifacts/nx_kit" subdirectory of the nx repository.
set VCVARS_BAT=%BASE_DIR%\..\..\build_utils\msvc\call_vcvars64.bat
if exist "%VCVARS_BAT%" (
echo on
call "%VCVARS_BAT%" || goto :exit
@echo off
)

if [%1] == [--no-tests] (
shift
set NO_TESTS=1
) else (
set NO_TESTS=0
)

if [%1] == [--debug] (
shift
set BUILD_TYPE=Debug
) else (
set BUILD_TYPE=Release
)

set GENERATOR_OPTIONS=-GNinja -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe

echo on
rmdir /S /Q "%BUILD_DIR%" 2>NUL
mkdir "%BUILD_DIR%" || goto :exit
cmake "%BASE_DIR%" -B "%BUILD_DIR%" %GENERATOR_OPTIONS% %1 %2 %3 %4 %5 %6 %7 %8 %9 || goto :exit
cmake --build "%BUILD_DIR%" || goto :exit
@echo off

:: Run unit tests if needed.
if [%NO_TESTS%] == [1] echo NOTE: Unit tests were not run. & goto :skip_tests

cd "%BUILD_DIR%\unit_tests"
setlocal
PATH=%BUILD_DIR%;%PATH%
echo on
ctest --output-on-failure -C "${BUILD_TYPE}" || @goto :exit
@echo off
endlocal

:skip_tests

echo:
echo Nx kit built successfully, see the library in %BUILD_DIR%

:exit
exit /b %ERRORLEVEL% %= Needed for a proper cmd.exe exit status. =%
83 changes: 83 additions & 0 deletions dependencies/nx_kit/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

## Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/

set -e #< Exit on error.
set -u #< Prohibit undefined variables.

if [[ $# > 0 && ($1 == "/?" || $1 == "-h" || $1 == "--help") ]]; then
echo "Usage: $(basename "$0") [--no-tests] [--debug] [<cmake-generation-args>...]"
echo " --debug Compile using Debug configuration (without optimizations) instead of Release."
exit
fi

# Make the build dir at the same level as the parent dir of this script, suffixed with "-build".
declare BASE_DIR="$(readlink -f "$(dirname "$0")")" #< Absolute path to this script's dir.
declare -r BUILD_DIR="${BASE_DIR}-build"

declare NO_TESTS=0
if [[ $# > 0 && $1 == "--no-tests" ]]; then
shift
NO_TESTS=1
fi

declare BUILD_TYPE="Release"
if [[ $# > 0 && $1 == "--debug" ]]; then
shift
BUILD_TYPE=Debug
fi

declare -a GEN_OPTIONS=()
declare LIBRARY_NAME=""

case "$(uname -s)" in #< Check if running in Windows from Cygwin/MinGW.
CYGWIN*|MINGW*)
# Assume that the MSVC environment is set up correctly and Ninja is installed. Also
# specify the compiler explicitly to avoid clashes with gcc.
GEN_OPTIONS+=( -GNinja -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_C_COMPILER=cl.exe )
BASE_DIR=$(cygpath -w "${BASE_DIR}") #< Windows-native CMake requires Windows path.
LIBRARY_NAME="nx_kit.dll"
;;
*)
if command -v ninja &> /dev/null; then #< Use Ninja if it is available on PATH.
GEN_OPTIONS+=( -GNinja )
fi
LIBRARY_NAME="libnx_kit.so"
;;
esac

if [[ "${BUILD_TYPE}" == "Release" ]]; then
GEN_OPTIONS+=( -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" )
fi

(set -x #< Log each command.
rm -rf "${BUILD_DIR}/"
)

cmake "${BASE_DIR}" -B "${BUILD_DIR}" \
${GEN_OPTIONS[@]+"${GEN_OPTIONS[@]}"} `#< allow empty array for bash before 4.4 #` \
"$@"
cmake --build "${BUILD_DIR}"

if [[ ! -f "${BUILD_DIR}/${LIBRARY_NAME}" ]]; then
echo "ERROR: Failed to build nx_kit."
exit 64
fi

echo ""
echo "Built: ${BUILD_DIR}/${LIBRARY_NAME}"
echo ""

# Run unit tests if needed.
if (( ${NO_TESTS} == 1 )); then
echo "NOTE: Unit tests were not run."
else
cd "${BUILD_DIR}/unit_tests"
PATH="${BUILD_DIR}:${PATH}"
(set -x #< Log each command.
ctest --output-on-failure -C "${BUILD_TYPE}"
)
fi
echo ""

echo "Samples built successfully, see the binaries in ${BUILD_DIR}"
36 changes: 22 additions & 14 deletions dependencies/nx_kit/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Currently, the following units are included into nx_kit:
---------------------------------------------------------------------------------------------------
## Building

This kit is suitable to form a source-only artifact `nx_kit` with the only `src` folder in it -
the source code files will be compiled as part of the project that uses the artifact. For cmake
This kit is suitable to form a source-only artifact `nx_kit` with the only `src` folder in it - the
source code files will be compiled as part of the project that uses the artifact. For the CMake
users, `CMakeLists.txt` can also be deployed to the artifact to be used in `add_subdirectory()`.

All classes and functions in this kit are prefixed with `NX_KIT_API` macro which allows to control
Expand All @@ -52,18 +52,26 @@ Tests for these utils are located in the `unit_tests` folder. The test project c
on Linux using cmake/ctest, on Windows with Cygwin using cmake/ctest or CLion IDE, or on Windows
using Microsoft Visual Studio 2012+.

To build and run tests on Linux or Windows+Cygwin, with `CMake >= 3.3.2` and `g++ >= 4.8.4`:
```
# Make a folder for build results:
mkdir .../nx_kit-build
cd .../nx_kit-build
For convenience and as an example, there are scripts named `build.bat` and `build.sh`. These
scripts build and run `nx_kit` library and its unit tests for Windows and Linux (or
Windows + Cygwin / MinGW / Git Bash), respectively. They serve as wrappers around the standard
CMake build procedure, including the generation stage, building and running ctest.

# Generate Makefiles:
cmake .../nx_kit
Prerequisites:
```
- CMake >= 3.14
- Windows (7, 10 or 11): Microsoft Visual Studio >= 2012
- Linux (Ubuntu 18.04, 20.04, 22.04)
- g++ >= 7.5
- make or Ninja
```

# Compile and link:
cmake --build .
Please note that on the Windows platform, if you use one of the provided scripts, you should also
have Ninja installed as part of Microsoft Visual Studio. Additionally, if `build.bat` is
executed within the `nx` repository directory, it attempts to initialize the environment under the
assumption that the Microsoft Visual Studio 2022 Community edition is being used. If any of these
conditions (MSVC version or `nx_kit` directory placement) are not met, the build must be initiated
from an already initialized environment (e.g., the "x64 Native Tools Command Prompt for VS 2022"
for MSVC 2022, or its equivalent for the MSVC version installed on your machine).

# Run tests:
./nx_kit_ut
```
To view the possible command-line options of the scripts, run them with `-h` or `/?`.
16 changes: 8 additions & 8 deletions dependencies/nx_kit/src/json11/json11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Value : public JsonValue {

// Constructors
explicit Value(const T &value) : m_value(value) {}
explicit Value(T &&value) : m_value(std::move(value)) {}
explicit Value(T &&value) : m_value(move(value)) {}

Check warning on line 160 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 160 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 160 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 160 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 160 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 160 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

// Get type tag
Json::Type type() const override {
Expand Down Expand Up @@ -204,23 +204,23 @@ class JsonString final : public Value<Json::STRING, string> {
const string &string_value() const override { return m_value; }
public:
explicit JsonString(const string &value) : Value(value) {}
explicit JsonString(string &&value) : Value(std::move(value)) {}
explicit JsonString(string &&value) : Value(move(value)) {}

Check warning on line 207 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 207 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]
};

class JsonArray final : public Value<Json::ARRAY, Json::array> {
const Json::array &array_items() const override { return m_value; }
const Json & operator[](size_t i) const override;
public:
explicit JsonArray(const Json::array &value) : Value(value) {}
explicit JsonArray(Json::array &&value) : Value(std::move(value)) {}
explicit JsonArray(Json::array &&value) : Value(move(value)) {}

Check warning on line 215 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 215 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]
};

class JsonObject final : public Value<Json::OBJECT, Json::object> {
const Json::object &object_items() const override { return m_value; }
const Json & operator[](const string &key) const override;
public:
explicit JsonObject(const Json::object &value) : Value(value) {}
explicit JsonObject(Json::object &&value) : Value(std::move(value)) {}
explicit JsonObject(Json::object &&value) : Value(move(value)) {}

Check warning on line 223 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 223 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]
};

class JsonNull final : public Value<Json::NUL, NullStruct> {
Expand Down Expand Up @@ -262,12 +262,12 @@ Json::Json(double value) : m_ptr(make_shared<JsonDouble>(value)) {
Json::Json(int value) : m_ptr(make_shared<JsonInt>(value)) {}
Json::Json(bool value) : m_ptr(value ? statics().t : statics().f) {}
Json::Json(const string &value) : m_ptr(make_shared<JsonString>(value)) {}
Json::Json(string &&value) : m_ptr(make_shared<JsonString>(std::move(value))) {}
Json::Json(string &&value) : m_ptr(make_shared<JsonString>(move(value))) {}

Check warning on line 265 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 265 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]
Json::Json(const char * value) : m_ptr(make_shared<JsonString>(value)) {}
Json::Json(const Json::array &values) : m_ptr(make_shared<JsonArray>(values)) {}
Json::Json(Json::array &&values) : m_ptr(make_shared<JsonArray>(std::move(values))) {}
Json::Json(Json::array &&values) : m_ptr(make_shared<JsonArray>(move(values))) {}

Check warning on line 268 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 268 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]
Json::Json(const Json::object &values) : m_ptr(make_shared<JsonObject>(values)) {}
Json::Json(Json::object &&values) : m_ptr(make_shared<JsonObject>(std::move(values))) {}
Json::Json(Json::object &&values) : m_ptr(make_shared<JsonObject>(move(values))) {}

Check warning on line 270 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 270 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

/* * * * * * * * * * * * * * * * * * * *
* Accessors
Expand Down Expand Up @@ -382,7 +382,7 @@ struct JsonParser final {
* Mark this parse as failed.
*/
Json fail(string &&msg) {
return fail(std::move(msg), Json());
return fail(move(msg), Json());

Check warning on line 385 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]

Check warning on line 385 in dependencies/nx_kit/src/json11/json11.cpp

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, Release, clang)

unqualified call to 'std::move' [-Wunqualified-std-cast-call]
}

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions dependencies/nx_kit/src/nx/kit/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void assertionFailed(
{
printFunc((std::string("\n")
+ ">>> ASSERTION FAILED: "
+ srcFileRelativePath(file) + ":" + toString(line)
+ file + ":" + toString(line)
+ " (" + conditionStr + ") " + message
).c_str());

Expand Down Expand Up @@ -168,7 +168,7 @@ void printHexDump(
return;
}

s += "\n{\n";
s += "\n{";
int count = size;
const char* p = bytes;
while (count > 0)
Expand Down
8 changes: 4 additions & 4 deletions dependencies/nx_kit/src/nx/kit/ini_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ class NX_KIT_API IniConfig

protected:
#define NX_INI_FLAG(DEFAULT, PARAM, DESCRIPTION) \
const bool PARAM = regBoolParam(&PARAM, DEFAULT, #PARAM, DESCRIPTION)
const bool PARAM = regBoolParam(&(PARAM), DEFAULT, #PARAM, DESCRIPTION)

#define NX_INI_INT(DEFAULT, PARAM, DESCRIPTION) \
const int PARAM = regIntParam(&PARAM, DEFAULT, #PARAM, DESCRIPTION)
const int PARAM = regIntParam(&(PARAM), DEFAULT, #PARAM, DESCRIPTION)

#define NX_INI_STRING(DEFAULT, PARAM, DESCRIPTION) \
const char* const PARAM = regStringParam(&PARAM, DEFAULT, #PARAM, DESCRIPTION)
const char* const PARAM = regStringParam(&(PARAM), DEFAULT, #PARAM, DESCRIPTION)

#define NX_INI_FLOAT(DEFAULT, PARAM, DESCRIPTION) \
const float PARAM = regFloatParam(&PARAM, DEFAULT, #PARAM, DESCRIPTION)
const float PARAM = regFloatParam(&(PARAM), DEFAULT, #PARAM, DESCRIPTION)

protected: // Used by the above macros.
bool regBoolParam(const bool* pValue, bool defaultValue,
Expand Down
Loading

0 comments on commit f84158e

Please sign in to comment.