diff --git a/.clang-format b/.clang-format index 22ad72c..6df5d3f 100644 --- a/.clang-format +++ b/.clang-format @@ -66,101 +66,6 @@ ForEachMacros: - Q_FOREACH - BOOST_FOREACH IncludeBlocks: Regroup -IncludeCategories: - - Regex: '^"[a-zA-Z0-9_]*\.' - Priority: 1 - SortPriority: 1 - - Regex: '^"testutils/' - Priority: 2 - SortPriority: 2 - - Regex: '^"tron/' - Priority: 2 - SortPriority: 3 - - Regex: '^"fmi/' - Priority: 2 - SortPriority: 4 - - Regex: '^"verifier/' - Priority: 2 - SortPriority: 5 - - Regex: '^"cora/' - Priority: 2 - SortPriority: 6 - - Regex: '^"tiga/' - Priority: 2 - SortPriority: 7 - - Regex: '^"statmc/' - Priority: 2 - SortPriority: 8 - - Regex: '^"xmltrace/' - Priority: 2 - SortPriority: 9 - - Regex: '^"pipeline/' - Priority: 2 - SortPriority: 10 - - Regex: '^"protocol/' - Priority: 2 - SortPriority: 11 - - Regex: '^"storage/' - Priority: 2 - SortPriority: 12 - - Regex: '^"system/' - Priority: 2 - SortPriority: 13 - - Regex: '^"dbm/' - Priority: 2 - SortPriority: 14 - - Regex: '^"cdd/' - Priority: 2 - SortPriority: 15 - - Regex: '^"polyhedra/' - Priority: 2 - SortPriority: 16 - - Regex: '^"tracer/' - Priority: 2 - SortPriority: 17 - - Regex: '^"utap/' - Priority: 2 - SortPriority: 18 - - Regex: '^"io/' - Priority: 2 - SortPriority: 19 - - Regex: '^"formats/' - Priority: 2 - SortPriority: 20 - - Regex: '^"base/' - Priority: 2 - SortPriority: 21 - - Regex: '^"hash/' - Priority: 2 - SortPriority: 22 - - Regex: '^"debug/' - Priority: 2 - SortPriority: 23 - - Regex: '^$' - Priority: 4 - SortPriority: 30 - - Regex: '^> "$GITHUB_ENV" - - name: Set mingw environment variables - if: matrix.target == 'mingw' - run: | - echo "CMAKE_TOOLCHAIN_FILE=$(pwd)/toolchains/mingw.cmake" >> "$GITHUB_ENV" - echo "STATIC=ON" >> "$GITHUB_ENV" - - name: Get ubuntu dependencies - if: matrix.target == 'ubuntu' - run: | - sudo apt-get update - sudo apt-get install libboost-all-dev doctest-dev - - name: Get mingw dependencies - if: matrix.target == 'mingw' - run: | - sudo apt-get update - sudo apt-get install cmake make g++-mingw-w64-x86-64 mingw-w64-x86-64-dev mingw-w64-tools wine wine-binfmt + - uses: actions/checkout@v3 + - name: Install MinGW64 cross-compiler and wine + if: matrix.target == 'x86_64-w64-mingw32' + run: | + sudo apt-get -qqy update + sudo apt-get -qqy install cmake make g++-mingw-w64-x86-64 mingw-w64-x86-64-dev mingw-w64-tools wine wine-binfmt sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix - - name: Getlibs - run: ./getlibs.sh - - name: Build and test - run: | - export CTEST_OUTPUT_ON_FAILURE=1 - cmake -DUDBM_WITH_TESTS=ON -DUDBM_STATIC=$STATIC -DASAN=${{ matrix.sanitizers }} -DUBSAN=${{ matrix.sanitizers }} -DCMAKE_BUILD_TYPE=Release -DENABLE_DBM_NEW=${{ matrix.newdbm }} -DCMAKE_PREFIX_PATH=$(pwd)/local -B build -S . - cmake --build build - (cd build ; ctest) - build-win-native: - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - name: Get dependencies - run: | - vcpkg integrate install - vcpkg install doctest --triplet x64-windows - bash ./getlibs.sh - - name: Build and test - run: | - cmake -DCMAKE_BUILD_TYPE=Release -DUDBM_WITH_TESTS=ON "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" -DCMAKE_PREFIX_PATH=$(pwd)/local -B build -S . - cmake --build build --config Release - cd build - ctest --output-on-failure -C Release + WINEPATH=$($PWD/winepath-for ${{ matrix.target }}) + echo "WINEPATH=$WINEPATH" >> $GITHUB_ENV + echo "WINARCH=win64" >> $GITHUB_ENV + - name: Build without getlibs + run: | + BUILD="build-${{ matrix.target }}-${CMAKE_BUILD_TYPE,,}" + cmake -S . -B "$BUILD" -DUDBM_STATIC=$STATIC -DASAN=${{ matrix.sanitizers }} -DUBSAN=${{ matrix.sanitizers }} -DENABLE_DBM_NEW=${{ matrix.newdbm }} + cmake --build "$BUILD" --config $CMAKE_BUILD_TYPE + (cd "$BUILD" ; ctest -C $CMAKE_BUILD_TYPE) + - name: Getlibs + run: ./getlibs.sh ${{ matrix.target }} + - name: Build with getlibs + run: | + BUILD="build-${{ matrix.target }}-libs-${CMAKE_BUILD_TYPE,,}" + cmake -S . -B "$BUILD" -DCMAKE_PREFIX_PATH="${{ github.workspace }}/local/${{ matrix.target }}" -DUDBM_STATIC=$STATIC -DASAN=${{ matrix.sanitizers }} -DUBSAN=${{ matrix.sanitizers }} -DENABLE_DBM_NEW=${{ matrix.newdbm }} + cmake --build "$BUILD" --config $CMAKE_BUILD_TYPE + (cd "$BUILD" ; ctest -C $CMAKE_BUILD_TYPE) build-macos: runs-on: macos-latest + env: + CMAKE_TOOLCHAIN_FILE: ${{ github.workspace }}/cmake/toolchain/x86_64-darwin.cmake + CMAKE_BUILD_TYPE: Release + CTEST_OUTPUT_ON_FAILURE: 1 + CTEST_TEST_TIMEOUT: 20 + STATIC: ON strategy: fail-fast: false matrix: sanitizers: [ON, OFF] steps: - - uses: actions/checkout@v2 - - name: Get dependencies - run: brew install boost doctest && ./getlibs.sh - - name: Build and test - run: | - export CTEST_OUTPUT_ON_FAILURE=1 - cmake -DUDBM_WITH_TESTS=ON -DASAN=${{ matrix.sanitizers }} -DUBSAN=${{ matrix.sanitizers }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$(pwd)/local -B build -S . - cmake --build build - (cd build ; ctest) - build-nix: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: cachix/install-nix-action@v15 - with: - nix_path: nixpkgs=channel:nixos-unstable - - name: Build and test - run: nix build -L - build-nix-mac: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - uses: cachix/install-nix-action@v15 - with: - nix_path: nixpkgs=channel:nixos-unstable - - name: Build and test - run: nix build -L - build-nix-cross: - runs-on: ubuntu-latest + - uses: actions/checkout@v3 + - name: Build without getlibs + run: | + BUILD=build-x86_64-darwin-$CMAKE_BUILD_TYPE + cmake -S . -B "$BUILD" -DASAN=${{ matrix.sanitizers }} -DUBSAN=${{ matrix.sanitizers }} + cmake --build "$BUILD" --config $CMAKE_BUILD_TYPE + (cd "$BUILD" ; ctest -C $CMAKE_BUILD_TYPE) + - name: Get dependencies + run: CMAKE_BUILD_TYPE=Release ./getlibs.sh x86_64-darwin + - name: Build with getlibs + run: | + BUILD=build-x86_64-darwin-libs-$CMAKE_BUILD_TYPE + cmake -S . -B "$BUILD" -DCMAKE_PREFIX_PATH="${{ github.workspace }}/local/x86_64-darwin" -DASAN=${{ matrix.sanitizers }} -DUBSAN=${{ matrix.sanitizers }} + cmake --build "$BUILD" --config $CMAKE_BUILD_TYPE + (cd "$BUILD" ; ctest -C $CMAKE_BUILD_TYPE) + build-windows: + runs-on: windows-latest + env: + CMAKE_TOOLCHAIN_FILE: C:/vcpkg/scripts/buildsystems/vcpkg.cmake + CMAKE_BUILD_TYPE: Release + STATIC: ON + CTEST_OUTPUT_ON_FAILURE: 1 + CTEST_TEST_TIMEOUT: 20 steps: - - uses: actions/checkout@v2 - - uses: cachix/install-nix-action@v15 - with: - nix_path: nixpkgs=channel:nixos-unstable - - name: Build and test - run: nix build -L .\#packages.crossPackage.x86_64-linux + - uses: actions/checkout@v3 + - name: Build without getlibs + run: | + $env:BUILD='build-x86_64-windows' + cmake -S . -B $env:BUILD + cmake --build $env:BUILD --config $env:CMAKE_BUILD_TYPE + cd $env:BUILD + ctest -C $env:CMAKE_BUILD_TYPE + - name: Get dependencies + run: | + vcpkg integrate install + vcpkg install doctest --triplet x64-windows + pwsh -Command { $env:CMAKE_BUILD_TYPE=Release ; bash ./getlibs.sh x86_64-w64-mingw32 } + - name: Build with getlibs + run: | + $env:BUILD='build-x86_64-windows-libs' + cmake -S . -B $env:BUILD -DCMAKE_PREFIX_PATH="${{ github.workspace }}/local/x86_64-w64-mingw32" + cmake --build $env:BUILD --config $env:CMAKE_BUILD_TYPE + cd $env:BUILD + ctest -C $env:CMAKE_BUILD_TYPE diff --git a/CMakeLists.txt b/CMakeLists.txt index 34d077e..cfda5d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,47 +1,28 @@ cmake_minimum_required(VERSION 3.16) -project(UDBM VERSION 2.0.11 LANGUAGES CXX C) +project(UDBM VERSION 2.0.13 LANGUAGES CXX C) include(CMakePackageConfigHelpers) include(GNUInstallDirs) -option(UDBM_WITH_TESTS "UDBM Unit tests" OFF) +option(UDBM_WITH_TESTS "UDBM Unit tests" ON) option(UDBM_STATIC "Static linking" OFF) -option(SSP "Stack-Smashing Protector" OFF) -option(UBSAN "Undefined Behavior Sanitizer" OFF) -option(ASAN "Address Sanitizer" OFF) +option(FIND_FATAL "Stop upon find_package errors" OFF) cmake_policy(SET CMP0048 NEW) # project() command manages VERSION variables set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(UDBM_PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") set(UDBM_VERSION "${PACKAGE_VERSION}") set(ENABLE_STORE_MINGRAPH 1) CONFIGURE_FILE("src/config.h.cmake" "include/dbm/config.h") +include(cmake/sanitizer.cmake) include(cmake/clang-tidy.cmake) -include(cmake/doctest.cmake) - -find_package(xxHash 0.8.0 CONFIG REQUIRED) -find_package(UUtils 1.1.1 REQUIRED COMPONENTS base hash debug) - -if (SSP) - message(STATUS "Enabled Stack Smashing Protector") - add_compile_options(-fstack-protector) - add_link_options(-fstack-protector) -endif(SSP) - -if (UBSAN OR ASAN) - add_compile_options(-fno-omit-frame-pointer) - add_link_options(-fno-omit-frame-pointer) -endif() -if (UBSAN) - message(STATUS "Enabled Undefined Behavior Sanitizer") - add_compile_options(-fsanitize=undefined) - add_link_options(-fsanitize=undefined) -endif(UBSAN) -if (ASAN) - message(STATUS "Enabled Address Sanitizer") - add_compile_options(-fsanitize=address) - add_link_options(-fsanitize=address) -endif(ASAN) +if (UDBM_WITH_TESTS) + include(cmake/doctest.cmake) +endif (UDBM_WITH_TESTS) +include(cmake/UUtils.cmake) if(UDBM_STATIC) set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CXX_STANDARD_LIBRARIES}") @@ -54,12 +35,13 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_compile_options(/W4) endif() -include_directories(${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include) +if(UDBM_WITH_TESTS) + enable_testing() +endif(UDBM_WITH_TESTS) add_subdirectory("src") if(UDBM_WITH_TESTS) - enable_testing() add_subdirectory(test) endif(UDBM_WITH_TESTS) diff --git a/cmake/UUtils.cmake b/cmake/UUtils.cmake new file mode 100644 index 0000000..c9379b5 --- /dev/null +++ b/cmake/UUtils.cmake @@ -0,0 +1,33 @@ +find_package(UUtils 2.0.5 COMPONENTS base hash debug QUIET) + +if (UUtils_FOUND) + message(STATUS "Found UUtils: ${UUtils_DIR}") +else(UUtils_FOUND) + message(STATUS "Failed to find UUtils, going to compile from source.") + if (FIND_FATAL) + message(FATAL_ERROR "Failed to find UUtils with CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}") + endif(FIND_FATAL) + include(FetchContent) + set(UUtils_WITH_TESTS OFF CACHE BOOL "UUtils tests") + set(UUtils_WITH_BENCHMARKS OFF CACHE BOOL "UUtils benchmarks") + FetchContent_Declare( + UUtils + GIT_REPOSITORY https://github.com/UPPAALModelChecker/UUtils.git + GIT_TAG v2.0.5 + GIT_SHALLOW TRUE # get only the last commit version + GIT_PROGRESS TRUE # show progress of download + # FIND_PACKAGE_ARGS NAMES doctest + USES_TERMINAL_DOWNLOAD TRUE # show progress in ninja generator + USES_TERMINAL_CONFIGURE ON + USES_TERMINAL_BUILD ON + USES_TERMINAL_INSTALL ON + ) + FetchContent_GetProperties(UUtils) + if (uutils_POPULATED) + message(STATUS "Found populated UUtils: ${uutils_SOURCE_DIR}") + else (uutils_POPULATED) + FetchContent_Populate(UUtils) + add_subdirectory(${uutils_SOURCE_DIR} ${uutils_BINARY_DIR} EXCLUDE_FROM_ALL) + message(STATUS "Got UUtils: ${uutils_SOURCE_DIR}") + endif (uutils_POPULATED) +endif(UUtils_FOUND) diff --git a/cmake/clang-tidy.cmake b/cmake/clang-tidy.cmake index 5b31189..b93e6f8 100644 --- a/cmake/clang-tidy.cmake +++ b/cmake/clang-tidy.cmake @@ -1,30 +1,20 @@ find_program(CLANG_TIDY_PROGRAM clang-tidy-14 clang-tidy) if(CLANG_TIDY_PROGRAM) - # Here we add checks that we know are good, and produce a minimal amount of false positives - # One or two false positives can be dealt with using // NOLINT - - set(CLANG_TIDY_WERROR "") - if(WERROR) - set(CLANG_TIDY_WERROR "--warnings-as-errors=*") - endif(WERROR) - execute_process(COMMAND ${CLANG_TIDY_PROGRAM} --version OUTPUT_VARIABLE CLANG_TIDY_VERSION_STRING) - string(FIND ${CLANG_TIDY_VERSION_STRING} "LLVM version" startloc) - string(SUBSTRING ${CLANG_TIDY_VERSION_STRING} ${startloc} -1 withoutstart) - string(FIND ${withoutstart} "\n" endloc) - string(SUBSTRING ${withoutstart} 13 ${endloc} TIDY_VERSION) - - string(FIND ${TIDY_VERSION} "." major_end) - string(SUBSTRING ${TIDY_VERSION} 0 ${major_end} TIDY_MAJOR_VERSION) + string(REGEX MATCH "LLVM version ([0-9A-Za-z]+)\\.([0-9A-Za-z\\.]+)" TIDY_VERSION "${CLANG_TIDY_VERSION_STRING}") + set(TIDY_MAJOR_VERSION "${CMAKE_MATCH_1}") + set(TIDY_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}") # We use NOLINTBEGIN and NOLINTEND to preserve some macros # This was only introduced in version 14 if (TIDY_MAJOR_VERSION GREATER_EQUAL 14) - message(STATUS "Found clang-tidy version ${TIDY_VERSION}") - set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_PROGRAM} -checks=-*,cppcoreguidelines-macro-usage,hicpp-deprecated-headers,modernize-deprecated-headers,hicpp-use-override,hicpp-use-emplace,modernize-use-emplace,hicpp-use-auto,readability-container-size-empty,readability-implicit-bool-conversion,readability-redundant-smartptr-get,readability-qualified-auto,performance-unnecessary-value-param,modernize-make-unique,modernize-make-shared,misc-unused-using-decls,performance-move-const-arg,modernize-use-using,modernize-use-nullptr,modernize-deprecated-headers,modernize-loop-convert,misc-unused-using-decls,misc-static-assert,misc-redundant-expression,modernize-use-bool-literals,readability-delete-null-pointer,readability-redundant-member-init --warnings-as-errors=*) + # Add good checks which produce a minimal amount of false positives + # One or two false positives can be dealt with using // NOLINT + set(CLANG_TIDY_COMMAND ${CLANG_TIDY_PROGRAM} -checks=-*,cppcoreguidelines-macro-usage,hicpp-deprecated-headers,modernize-deprecated-headers,hicpp-use-override,hicpp-use-emplace,modernize-use-emplace,hicpp-use-auto,readability-container-size-empty,readability-implicit-bool-conversion,readability-redundant-smartptr-get,readability-qualified-auto,performance-unnecessary-value-param,modernize-make-unique,modernize-make-shared,misc-unused-using-decls,performance-move-const-arg,modernize-use-using,modernize-use-nullptr,modernize-deprecated-headers,modernize-loop-convert,misc-unused-using-decls,misc-static-assert,misc-redundant-expression,modernize-use-bool-literals,readability-delete-null-pointer,readability-redundant-member-init) + message(STATUS "Enabled clang-tidy ${TIDY_VERSION}: ${CLANG_TIDY_PROGRAM}") else() - message(WARNING "Found clang-tidy version ${TIDY_VERSION}, but 14 or higher is required. Disabling clang-tidy") + message(WARNING "Found clang-tidy ${TIDY_VERSION}, but >=14 is required, thus disabled.") endif() else(CLANG_TIDY_PROGRAM) - message(WARNING "Failed to find clang-tidy >=14. Some checks are not enabled") + message(WARNING "No clang-tidy found. Some checks are not enabled") endif(CLANG_TIDY_PROGRAM) diff --git a/cmake/doctest.cmake b/cmake/doctest.cmake index 8443625..24e7f0a 100644 --- a/cmake/doctest.cmake +++ b/cmake/doctest.cmake @@ -1,14 +1,45 @@ -find_package(doctest 2.4.8 QUIET) -if(doctest_FOUND) - message(STATUS "Found doctest preinstalled.") +find_package(doctest 2.4.11 QUIET) + +if (doctest_FOUND) + if (TARGET doctest::doctest_with_main) + message(STATUS "Found doctest::doctest_with_main") + add_library(doctest_with_main INTERFACE) + target_link_libraries(doctest_with_main PRIVATE doctest::doctest_with_main) + else(TARGET doctest::doctest_with_main) # workaround for old doctest + message(STATUS "Workaround for doctest::doctest_with_main") + add_library(doctest_with_main INTERFACE) + target_compile_definitions(doctest_with_main INTERFACE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) + target_link_libraries(doctest_with_main INTERFACE doctest::doctest) + endif(TARGET doctest::doctest_with_main) + message(STATUS "Found doctest: ${doctest_DIR}") else(doctest_FOUND) - message(STATUS "Failed to find doctest, going to make it from scratch.") - set(DOCTEST_WITH_TESTS OFF CACHE INTERNAL "doctest tests") - include(FetchContent) - FetchContent_Declare(doctest - GIT_REPOSITORY git@github.com:doctest/doctest.git - GIT_TAG v2.4.9 - GIT_SHALLOW ON - ) - FetchContent_MakeAvailable(doctest) + message(STATUS "Failed to find doctest, going to compile from source.") + if (FIND_FATAL) + message(FATAL_ERROR "Failed to find doctest with CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}") + endif(FIND_FATAL) + include(FetchContent) + set(DOCTEST_WITH_TESTS OFF CACHE BOOL "doctest tests and examples") + set(DOCTEST_WITH_MAIN_IN_STATIC_LIB ON CACHE BOOL "static lib (cmake target) with a default main entry point") + set(DOCTEST_NO_INSTALL ON CACHE BOOL "Skip the installation process") + set(DOCTEST_USE_STD_HEADERS OFF CACHE BOOL "Use std headers") + FetchContent_Declare( + doctest + GIT_REPOSITORY https://github.com/doctest/doctest + GIT_TAG v2.4.11 + GIT_SHALLOW TRUE # get only the last commit version + GIT_PROGRESS TRUE # show progress of download + # FIND_PACKAGE_ARGS NAMES doctest + USES_TERMINAL_DOWNLOAD TRUE # show progress in ninja generator + USES_TERMINAL_CONFIGURE ON + USES_TERMINAL_BUILD ON + USES_TERMINAL_INSTALL ON + ) + FetchContent_GetProperties(doctest) + if (doctest_POPULATED) + message(STATUS "Found populated doctest: ${doctest_SOURCE_DIR}") + else (doctest_POPULATED) + FetchContent_Populate(doctest) + add_subdirectory(${doctest_SOURCE_DIR} ${doctest_BINARY_DIR} EXCLUDE_FROM_ALL) + message(STATUS "Got doctest: ${doctest_SOURCE_DIR}") + endif (doctest_POPULATED) endif(doctest_FOUND) diff --git a/cmake/sanitizer.cmake b/cmake/sanitizer.cmake new file mode 100644 index 0000000..2ebe277 --- /dev/null +++ b/cmake/sanitizer.cmake @@ -0,0 +1,99 @@ +# Various sanitizers (runtime checks) for debugging +option(SSP "Stack Smashing Protector (GCC/Clang/ApplClang on Unix)" OFF + )# Available on Windows too +option(UBSAN "Undefined Behavior Sanitizer (GCC/Clang/AppleClang on Unix)" OFF) +option(ASAN "Address Sanitizer (GCC/Clang/AppleClang on Unix, MSVC on Windows)" + OFF) +option(TSAN "Thread Sanitizer (GCC/Clang/AppleClang on Unix)" OFF) +option(RTC_C "Runtime Checks for Conversions (MSVC on Windows)" OFF) +option(RTC_S "Runtime Checks for Stack (MSVC on Windows)" OFF) +option(RTC_U "Runtime Checks for Uninitialized (MSVC on Windows)" OFF) + +if(SSP) + add_compile_options(-fstack-protector) + add_link_options(-fstack-protector) + message(STATUS "Enable Stack Smashing Protector") +endif(SSP) + +if(ASAN + OR UBSAN + OR TSAN) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + + else() + add_compile_options(-fno-omit-frame-pointer) + add_link_options(-fno-omit-frame-pointer) + endif() +endif() + +if(UBSAN) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/fsanitize=undefined) + message( + STATUS + "Please see if MSVC supports undefined behavior sanitizer: https://learn.microsoft.com/en-us/cpp/sanitizers/asan" + ) + else() + add_compile_options(-fsanitize=undefined) + add_link_options(-fsanitize=undefined) + endif() + message(STATUS "Enabled Undefined Behavior Sanitizer") +endif(UBSAN) + +if(ASAN) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/fsanitize=address) + else() + add_compile_options(-fsanitize=address) + add_link_options(-fsanitize=address) + endif() + message(STATUS "Enabled Address Sanitizer") +endif(ASAN) + +if(TSAN) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/fsanitize=thread) + message( + STATUS + "Please see if MSVC supports thread sanitizer: https://learn.microsoft.com/en-us/cpp/sanitizers/asan" + ) + else() + add_compile_options(-fsanitize=thread) + add_link_options(-fsanitize=thread) + endif() + message(STATUS "Enabled Thread Sanitizer") +endif(TSAN) + +if(RTC_C) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/RTCc) + add_compile_definitions(_ALLOW_RTCc_IN_STL) + message(STATUS "Enabled Runtime Check Conversions") + else() + message( + WARNING + "Runtime Check Conversions is not enabled for ${CMAKE_CXX_COMPILER_ID}") + endif() +endif(RTC_C) + +if(RTC_S) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/RTCs) + message(STATUS "Enabled Runtime Check Stack") + else() + message( + WARNING "Runtime Check Stack is not enabled for ${CMAKE_CXX_COMPILER_ID}") + endif() +endif(RTC_S) + +if(RTC_U) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/RTCu) + message(STATUS "Enabled Runtime Check Uninitialized") + else() + message( + WARNING + "Runtime Check Uninitialized is not enabled for ${CMAKE_CXX_COMPILER_ID}" + ) + endif() +endif(RTC_U) diff --git a/cmake/toolchain/i686-linux.cmake b/cmake/toolchain/i686-linux.cmake new file mode 100644 index 0000000..6fabd4b --- /dev/null +++ b/cmake/toolchain/i686-linux.cmake @@ -0,0 +1,19 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Linux) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER cc) +set(CMAKE_C_FLAGS -m32) +set(CMAKE_CXX_COMPILER c++) +set(CMAKE_CXX_FLAGS -m32) +set(CMAKE_ASM_FLAGS -m32) + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH "${CMAKE_PREFIX_PATH}") + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, +# search programs in both target and host environments +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/toolchain/i686-w64-mingw32.cmake b/cmake/toolchain/i686-w64-mingw32.cmake new file mode 100644 index 0000000..1d762b8 --- /dev/null +++ b/cmake/toolchain/i686-w64-mingw32.cmake @@ -0,0 +1,19 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_CROSSCOMPILING ON) +set(CMAKE_CROSSCOMPILING_EMULATOR wine) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) + +# where is the target environment located +set(CMAKE_FIND_ROOT_PATH "${CMAKE_PREFIX_PATH}") + +# adjust the default behavior of the FIND_XXX() commands: +# search programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) + +# search headers and libraries in the target environment +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/toolchain/x86_64-darwin.cmake b/cmake/toolchain/x86_64-darwin.cmake new file mode 100644 index 0000000..e05a733 --- /dev/null +++ b/cmake/toolchain/x86_64-darwin.cmake @@ -0,0 +1,19 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Darwin) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER cc) +set(CMAKE_C_FLAGS -m64) +set(CMAKE_CXX_COMPILER c++) +set(CMAKE_CXX_FLAGS -m64) +set(CMAKE_ASM_FLAGS -m64) + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH "${CMAKE_PREFIX_PATH}") + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, +# search programs in both target and host environments +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/toolchain/x86_64-linux.cmake b/cmake/toolchain/x86_64-linux.cmake new file mode 100644 index 0000000..5e686bc --- /dev/null +++ b/cmake/toolchain/x86_64-linux.cmake @@ -0,0 +1,19 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Linux) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER cc) +set(CMAKE_C_FLAGS -m64) +set(CMAKE_CXX_COMPILER c++) +set(CMAKE_CXX_FLAGS -m64) +set(CMAKE_ASM_FLAGS -m64) + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH "${CMAKE_PREFIX_PATH}") + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, +# search programs in both target and host environments +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/toolchains/mingw.cmake b/cmake/toolchain/x86_64-w64-mingw32.cmake similarity index 100% rename from toolchains/mingw.cmake rename to cmake/toolchain/x86_64-w64-mingw32.cmake diff --git a/cmake/xxhash.cmake b/cmake/xxhash.cmake new file mode 100644 index 0000000..f577755 --- /dev/null +++ b/cmake/xxhash.cmake @@ -0,0 +1,69 @@ +#find_package(xxHash 0.8.0 CONFIG QUIET) +set(XXHASH_VERSION_MINIMUM 0.8.0) +find_file(XXHASH_PATH xxhash.h) +if (XXHASH_PATH) + cmake_path(GET XXHASH_PATH PARENT_PATH xxHash_DIR) + file(READ "${XXHASH_PATH}" XXHASH_H) + string(REGEX MATCH "#define XXH_VERSION_MAJOR([ \t])*([0-9])*" _ ${XXHASH_H}) + set(XXHASH_VERSION_MAJOR ${CMAKE_MATCH_2}) + string(REGEX MATCH "#define XXH_VERSION_MINOR([ \t])*([0-9])*" _ ${XXHASH_H}) + set(XXHASH_VERSION_MINOR ${CMAKE_MATCH_2}) + string(REGEX MATCH "#define XXH_VERSION_RELEASE([ \t])*([0-9])*" _ ${XXHASH_H}) + set(XXHASH_VERSION_PATCH ${CMAKE_MATCH_2}) + set(XXHASH_VERSION "${XXHASH_VERSION_MAJOR}.${XXHASH_VERSION_MINOR}.${XXHASH_VERSION_PATCH}") + if (XXHASH_VERSION VERSION_GREATER_EQUAL ${XXHASH_VERSION_MINIMUM}) + set(xxHash_FOUND TRUE) + cmake_path(GET XXHASH_PATH PARENT_PATH XXHASH_INCLUDE_DIR) + add_library(xxHash INTERFACE) + target_compile_definitions(xxHash INTERFACE XXH_INLINE_ALL) + target_include_directories(xxHash + INTERFACE + $ + $ + ) + else() + message(STATUS "Found xxHash-${XXHASH_VERSION} is too old, need at lease ${XXHASH_VERSION_MINIMUM}") + endif() +endif(XXHASH_PATH) + +if (xxHash_FOUND) + message(STATUS "Found xxHash-${XXHASH_VERSION}: ${XXHASH_PATH}") +else(xxHash_FOUND) + message(STATUS "Failed to find xxHash, going to compile from source.") + if (FIND_FATAL) + message(FATAL_ERROR "Failed to find xxHash with CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}") + endif(FIND_FATAL) + include(ExternalProject) + set(XXHASH_BUILD_ENABLE_INLINE_API ON CACHE BOOL "adds xxhash.c for the -DXXH_INLINE_ALL api. Default ON") + set(XXHASH_BUILD_XXHSUM OFF CACHE BOOL "build the command line binary. Default ON") + set(BUILD_SHARED_LIBS OFF CACHE BOOL "build dynamic library. Default ON") + # set(DISPATCH OFF CACHE BOOL "enable dispatch mode. Default OFF") + FetchContent_Declare( + xxHash + GIT_REPOSITORY https://github.com/Cyan4973/xxHash + GIT_TAG v0.8.2 + GIT_SHALLOW TRUE # get only the last commit version + GIT_PROGRESS TRUE # show progress of download + SOURCE_SUBDIR cmake_unofficial # CMakeLists.txt is not in the main folder + FIND_PACKAGE_ARGS NAMES xxHash COMPONENTS xxhash # for future when xxhash supports cmake + USES_TERMINAL_DOWNLOAD TRUE # show progress in ninja generator + USES_TERMINAL_CONFIGURE ON + USES_TERMINAL_BUILD ON + USES_TERMINAL_INSTALL ON + ) + FetchContent_GetProperties(xxHash) + if (xxhash_POPULATED) + message(STATUS "Found populated xxHash: ${xxhash_SOURCE_DIR}") + else (xxhash_POPULATED) + FetchContent_Populate(xxHash) + add_subdirectory(${xxhash_SOURCE_DIR}/cmake_unofficial ${xxhash_BINARY_DIR} EXCLUDE_FROM_ALL) + add_library(xxHash INTERFACE) + target_compile_definitions(xxHash INTERFACE XXH_INLINE_ALL) + target_include_directories(xxHash + INTERFACE + $ + $ + ) + message(STATUS "Got xxHash: ${xxhash_SOURCE_DIR}") + endif (xxhash_POPULATED) +endif(xxHash_FOUND) diff --git a/compile.sh b/compile.sh new file mode 100755 index 0000000..8c8f4cc --- /dev/null +++ b/compile.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +set -eo pipefail + +PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +if [ $# -eq 0 ]; then + targets="x86_64-linux-libs-release x86_64-w64-mingw32-libs-release" +else + targets="$@" +fi + +for target in $targets ; do + unset BUILD_EXTRA + unset CMAKE_BUILD_TYPE + case $target in + linux64*|x86_64-linux*) + PLATFORM=x86_64-linux + ;; + linux32*|i686-linux*) + PLATFORM=i686-linux + ;; + win64*|x86_64-w64-mingw32*) + PLATFORM=x86_64-w64-mingw32 + ;; + win32*|i686-w64-mingw32*) + PLATFORM=i686-w64-mingw32 + ;; + macos*|x86_64-darwin*) + PLATFORM=x86_64-darwin + ;; + *) + echo "Unrecognized target platform: $target" + exit 1 + esac + export CMAKE_TOOLCHAIN_FILE="$PROJECT_DIR/cmake/toolchain/$PLATFORM.cmake" + BUILD_DIR="build-$PLATFORM" + + case $target in + *-lib*) + CMAKE_BUILD_TYPE=Release ./getlibs.sh $PLATFORM + BUILD_EXTRA="$BUILD_EXTRA -DFIND_FATAL=ON" + export CMAKE_PREFIX_PATH="$PROJECT_DIR/local/$PLATFORM" + ;; + esac + + case $target in + *-ubsan-*) + BUILD_EXTRA="$BUILD_EXTRA -DUBSAN=ON" + BUILD_DIR="${BUILD_DIR}-ubsan" + ;; + esac + case $target in + *-lsan-*) + BUILD_EXTRA="$BUILD_EXTRA -DLSAN=ON" + BUILD_DIR="${BUILD_DIR}-lsan" + ;; + esac + case $target in + *-asan-*) + BUILD_EXTRA="$BUILD_EXTRA -DASAN=ON" + BUILD_DIR="${BUILD_DIR}-asan" + ;; + esac + case $target in + *-debug) + export CMAKE_BUILD_TYPE=Debug + BUILD_DIR="${BUILD_DIR}-debug" + ;; + *-release) + export CMAKE_BUILD_TYPE=Release + BUILD_DIR="${BUILD_DIR}-release" + ;; + *) + export CMAKE_BUILD_TYPE=Release + BUILD_DIR="${BUILD_DIR}-release" + echo "Unrecognized build type: $target, assuming $CMAKE_BUILD_TYPE" + esac + echo "Building $target${BUILD_EXTRA:+ with$BUILD_EXTRA} into $BUILD_DIR" + echo " CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE" + echo " CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH" + echo " CMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE" + cmake -S "$PROJECT_DIR" -B "$BUILD_DIR" $BUILD_EXTRA + cmake --build "$BUILD_DIR" --config $CMAKE_BUILD_TYPE + (cd "$BUILD_DIR" ; ctest -C $CMAKE_BUILD_TYPE --output-on-failure) +done diff --git a/getlibs.sh b/getlibs.sh index 35ec1c1..7c8b4f1 100755 --- a/getlibs.sh +++ b/getlibs.sh @@ -1,52 +1,91 @@ #!/usr/bin/env bash -set -euxo pipefail +set -eo pipefail -SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -PREFIX="$SOURCE_DIR/local" -SOURCES="$SOURCE_DIR/local/sources" -mkdir -p "$SOURCES" +if [ $# -eq 0 ]; then + echo "Script $0 fetches, compiles and installs dependent libraries." + machine=$(uname --machine) + kernel=$(uname --kernel-name) + targets=${machine,,}-${kernel,,} + echo "Expects targets as arguments, for example: $targets" + exit 1 +else + targets="$@" +fi -CMAKE_PREFIX_PATH="$PREFIX" +SOURCES="$PROJECT_DIR/local/sources" +mkdir -p "$SOURCES" -CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH -DCMAKE_INSTALL_PREFIX=$PREFIX" -if [ -z ${CMAKE_TOOLCHAIN_FILE+x} ]; then - echo "Not using a custom toolchain"; -else - echo "Using toolchain $CMAKE_TOOLCHAIN_FILE"; - CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE"; +if [ -z "${CMAKE_BUILD_TYPE+x}" ]; then + export CMAKE_BUILD_TYPE=Release +elif [ "$CMAKE_BUILD_TYPE" != Release ]; then + echo "WARNING: building libs with CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE" fi -# doctest for unit testing -cd "$SOURCES" -curl -L https://github.com/doctest/doctest/archive/refs/tags/v2.4.8.tar.gz -o doctest-2.4.8.tar.gz -tar -xf doctest-2.4.8.tar.gz -SOURCE_DIR="$SOURCES/doctest-2.4.8" -BUILD_DIR="$SOURCE_DIR/build" -mkdir -p "$BUILD_DIR" -cmake $CMAKE_ARGS -DDOCTEST_WITH_TESTS=OFF -B "$BUILD_DIR" "$SOURCE_DIR" -cmake --build "$BUILD_DIR" --config Release -cmake --install "$BUILD_DIR" --config Release +for target in $targets ; do + PREFIX="$PROJECT_DIR/local/$target" + export CMAKE_TOOLCHAIN_FILE="$PROJECT_DIR/cmake/toolchain/$target.cmake" + export CMAKE_PREFIX_PATH="$PREFIX" + export CMAKE_INSTALL_PREFIX="$PREFIX" -# xxHash for fast high quality hashing -cd "$SOURCES" -curl -L https://github.com/Cyan4973/xxHash/archive/refs/tags/v0.8.0.tar.gz -o xxHash-0.8.0.tar.gz -tar -xf xxHash-0.8.0.tar.gz -SOURCE_DIR="$SOURCES/xxHash-0.8.0" -BUILD_DIR="$SOURCE_DIR/build" -mkdir -p "$BUILD_DIR" -cmake $CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -B "$BUILD_DIR" "$SOURCE_DIR/cmake_unofficial" -cmake --build "$BUILD_DIR" --config Release -cmake --install "$BUILD_DIR" --config Release + # doctest for unit testing + NAME=doctest + VERSION=2.4.11 + LIBRARY="${NAME}-${VERSION}" + if [ -r "$PREFIX/include/doctest/doctest.h" ] ; then + echo "$LIBRARY is already installed in $PREFIX" + else + ARCHIVE="${LIBRARY}.tar.gz" + SHA256=632ed2c05a7f53fa961381497bf8069093f0d6628c5f26286161fbd32a560186 + SOURCE="${SOURCES}/${LIBRARY}" + BUILD="${PREFIX}/build-${LIBRARY}" + pushd "$SOURCES" + [ -r "$ARCHIVE" ] || curl -sL "https://github.com/doctest/doctest/archive/refs/tags/v${VERSION}.tar.gz" -o "$ARCHIVE" + if [ -n "$(command -v sha256sum)" ]; then echo "$SHA256 $ARCHIVE" | sha256sum --check ; fi + [ -d "$SOURCE" ] || tar -xf "$ARCHIVE" + popd + echo "Building $LIBRARY in $BUILD" + echo " CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE" + echo " CMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE" + echo " CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH" + echo " CMAKE_INSTALL_PREFIX=$CMAKE_INSTALL_PREFIX" + echo " CMAKE_GENERATOR=$CMAKE_GENERATOR" + cmake -S "$SOURCE" -B "$BUILD" -DDOCTEST_WITH_TESTS=OFF \ + -DDOCTEST_WITH_MAIN_IN_STATIC_LIB=ON -DDOCTEST_USE_STD_HEADERS=OFF + cmake --build "$BUILD" --config $CMAKE_BUILD_TYPE + cmake --install "$BUILD" --config $CMAKE_BUILD_TYPE --prefix "$CMAKE_INSTALL_PREFIX" + rm -Rf "$BUILD" + rm -Rf "$SOURCE" + fi -# UUtils various low level Uppaal utilities -#git clone https://github.com/UPPAALModelChecker/UUtils "$SOURCE_DIR/libs/sources/UUtils"; -cd "$SOURCES" -curl -L https://github.com/UPPAALModelChecker/UUtils/archive/refs/tags/v1.1.1.tar.gz -o UUtils-1.1.1.tar.gz -tar -xf UUtils-1.1.1.tar.gz -SOURCE_DIR="$SOURCES/UUtils-1.1.1" -BUILD_DIR="$SOURCE_DIR/build" -mkdir -p "$BUILD_DIR" -cmake $CMAKE_ARGS -B "$BUILD_DIR" "$SOURCE_DIR" -cmake --build "$BUILD_DIR" --config Release -cmake --install "$BUILD_DIR" --config Release + # UUtils various low level Uppaal utilities + NAME=UUtils + VERSION=2.0.5 + LIBRARY="${NAME}-${VERSION}" + if [ -r "$PREFIX/include/base/Enumerator.h" ]; then + echo "$LIBRARY is already installed in $PREFIX" + else + ARCHIVE="${LIBRARY}.tar.gz" + SHA256=e213f936af73344de071a7794233a328028045c08df58ac9c637a0e6a2ad7b3f + SOURCE="${SOURCES}/${LIBRARY}" + BUILD="${PREFIX}/build-${LIBRARY}" + pushd "$SOURCES" + #git clone -b dev-branch --single-branch --depth 1 https://github.com/UPPAALModelChecker/UUtils.git "$LIBRARY" + [ -r "$ARCHIVE" ] || curl -sL "https://github.com/UPPAALModelChecker/UUtils/archive/refs/tags/v${VERSION}.tar.gz" -o "$ARCHIVE" + if [ -n "$(command -v sha256sum)" ]; then echo "$SHA256 $ARCHIVE" | sha256sum --check ; fi + [ -d "$SOURCE" ] || tar -xf "$ARCHIVE" + popd + echo "Building $LIBRARY in $BUILD" + echo " CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE" + echo " CMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE" + echo " CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH" + echo " CMAKE_INSTALL_PREFIX=$CMAKE_INSTALL_PREFIX" + echo " CMAKE_GENERATOR=$CMAKE_GENERATOR" + cmake -S "$SOURCE" -B "$BUILD" -DUUtils_WITH_TESTS=OFF -DUUtils_WITH_BENCHMARKS=OFF + cmake --build "$BUILD" --config $CMAKE_BUILD_TYPE + cmake --install "$BUILD" --config $CMAKE_BUILD_TYPE --prefix="$CMAKE_INSTALL_PREFIX" + rm -Rf "$BUILD" + rm -Rf "$SOURCE" + fi +done diff --git a/include/dbm/constraints.h b/include/dbm/constraints.h index 652b708..fe7bfdf 100644 --- a/include/dbm/constraints.h +++ b/include/dbm/constraints.h @@ -18,11 +18,11 @@ #ifndef INCLUDE_DBM_CONSTRAINTS_H #define INCLUDE_DBM_CONSTRAINTS_H +#include + #include #include -#include - #ifdef __cplusplus extern "C" { #endif // C++ diff --git a/include/dbm/dbm.h b/include/dbm/dbm.h index 493056a..99402d9 100644 --- a/include/dbm/dbm.h +++ b/include/dbm/dbm.h @@ -19,9 +19,10 @@ #define INCLUDE_DBM_DBM_H #include "dbm/constraints.h" -#include "base/intutils.h" -#include "base/relation.h" -#include "hash/compute.h" + +#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/include/dbm/mingraph.h b/include/dbm/mingraph.h index 15f2426..eb5b66b 100644 --- a/include/dbm/mingraph.h +++ b/include/dbm/mingraph.h @@ -18,8 +18,9 @@ #define INCLUDE_DBM_MINGRAPH_H #include "dbm/dbm.h" -#include "base/c_allocator.h" -#include "base/intutils.h" + +#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 95478ac..711f7cf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,19 +1,18 @@ -add_library(UDBM DBMAllocator.cpp dbm.c fed_dbm.cpp mingraph.c mingraph_read.c partition.cpp print.cpp gen.c +add_library(UDBM STATIC DBMAllocator.cpp dbm.c fed_dbm.cpp mingraph.c mingraph_read.c partition.cpp print.cpp gen.c mingraph_cache.cpp mingraph_relation.c pfed.cpp fed.cpp infimum.cpp mingraph_equal.c mingraph_write.c priced.cpp valuation.cpp) set_property(TARGET UDBM PROPERTY C_VISIBILITY_PRESET hidden) set_property(TARGET UDBM PROPERTY VISIBILITY_INLINES_HIDDEN ON) -target_link_libraries(UDBM UUtils::base UUtils::udebug UUtils::hash) +if (NOT CMAKE_SYSTEM_NAME STREQUAL Windows) # unknown argument: '-fno-keep-inline-dllexport' + set_target_properties(UDBM PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") +endif() +target_link_libraries(UDBM PRIVATE UUtils::base UUtils::udebug UUtils::hash) target_include_directories(UDBM - PRIVATE - # where the library itself will look for its internal headers - ${CMAKE_CURRENT_BINARY_DIR}/../include - ${CMAKE_CURRENT_SOURCE_DIR}/../include PUBLIC # where top-level project will look for the library's public headers - $ - $ + $ # dbm/config.h + $ # where external projects will look for the library's public headers $ ) diff --git a/src/dbm.c b/src/dbm.c index 03f2d95..9b27a1e 100644 --- a/src/dbm.c +++ b/src/dbm.c @@ -19,14 +19,13 @@ #define VECTORIZE_FLOYD #endif -#include "dbm/dbm.h" - #include "dbm.h" - +#include "dbm/dbm.h" #include "dbm/print.h" -#include "base/bitstring.h" -#include "base/doubles.h" -#include "debug/macros.h" + +#include +#include +#include #include diff --git a/src/fed.cpp b/src/fed.cpp index c4bb13f..7d7d5a1 100644 --- a/src/fed.cpp +++ b/src/fed.cpp @@ -18,8 +18,9 @@ #include "dbm/config.h" #include "dbm/mingraph.h" #include "dbm/print.h" -#include "base/bitstring.h" -#include "base/doubles.h" + +#include +#include #include // find_if #include diff --git a/src/fed_dbm.cpp b/src/fed_dbm.cpp index d1148a4..013c985 100644 --- a/src/fed_dbm.cpp +++ b/src/fed_dbm.cpp @@ -13,10 +13,10 @@ #include "DBMAllocator.h" #include "dbm.h" - #include "dbm/config.h" -#include "base/bitstring.h" -#include "base/doubles.h" + +#include +#include #include #include diff --git a/src/gen.c b/src/gen.c index a065882..f3134b8 100644 --- a/src/gen.c +++ b/src/gen.c @@ -15,12 +15,12 @@ *********************************************************************/ #include "dbm/gen.h" - #include "dbm/dbm.h" #include "dbm/print.h" -#include "base/bitstring.h" -#include "base/doubles.h" -#include "debug/macros.h" + +#include +#include +#include #include diff --git a/src/infimum.cpp b/src/infimum.cpp index e5ea9b6..b95eb55 100644 --- a/src/infimum.cpp +++ b/src/infimum.cpp @@ -4,8 +4,9 @@ #include "dbm/dbm_raw.hpp" #include "dbm/mingraph.h" -#include "base/bitstring.h" -#include "debug/macros.h" + +#include +#include #include #include diff --git a/src/infimum.h b/src/infimum.h index 126e720..7d4c67b 100644 --- a/src/infimum.h +++ b/src/infimum.h @@ -15,4 +15,4 @@ int32_t pdbm_infimum(const raw_t* dbm, uint32_t dim, uint32_t offsetCost, const int32_t* rates); void pdbm_infimum(const raw_t* dbm, uint32_t dim, uint32_t offsetCost, const int32_t* rates, int32_t* valuation); -#endif +#endif /* DBM_INFIMUM_H */ diff --git a/src/mingraph.c b/src/mingraph.c index 8d8fd34..b864179 100644 --- a/src/mingraph.c +++ b/src/mingraph.c @@ -18,8 +18,8 @@ #include "mingraph_coding.h" -#include "base/bitstring.h" -#include "debug/macros.h" +#include +#include /** * @file diff --git a/src/mingraph_cache.cpp b/src/mingraph_cache.cpp index dbbaddc..9d1ebbf 100644 --- a/src/mingraph_cache.cpp +++ b/src/mingraph_cache.cpp @@ -15,15 +15,14 @@ #include "mingraph_cache.h" -#include "base/intutils.h" -#include "base/stats.h" -#include "debug/macros.h" - -#include - +#include +#include #ifndef NDEBUG -#include "base/bitstring.h" +#include #endif +#include + +#include /* Default size for the cache, can redefined to anything > 0 */ /* Choose your favorite prime among http://primes.utm.edu/lists/small/1000.txt. */ @@ -100,4 +99,4 @@ void mingraph_putCachedResult(const raw_t* dbm, cindex_t dim, const uint32_t* bi assert(base_countBitsN(&entry->data[dim2], bits2intsize(dim2)) == entry->cnt); } -#endif +#endif /* ENABLE_MINGRAPH_CACHE */ diff --git a/src/mingraph_cache.h b/src/mingraph_cache.h index 45ee692..760594d 100644 --- a/src/mingraph_cache.h +++ b/src/mingraph_cache.h @@ -44,4 +44,4 @@ void mingraph_putCachedResult(const raw_t* dbm, cindex_t dim, const uint32_t* bi #endif #endif /* DBM_MINGRAPH_CACHE_H */ -#endif +#endif /* ENABLE_MINGRAPH_CACHE */ diff --git a/src/mingraph_coding.h b/src/mingraph_coding.h index 1dcc7f2..91b735d 100644 --- a/src/mingraph_coding.h +++ b/src/mingraph_coding.h @@ -16,7 +16,8 @@ #include "dbm/config.h" #include "dbm/constraints.h" // bit_t -#include "base/bitstring.h" // bit_t + +#include // bit_t #include diff --git a/src/mingraph_equal.c b/src/mingraph_equal.c index 46bd778..28489fd 100644 --- a/src/mingraph_equal.c +++ b/src/mingraph_equal.c @@ -12,10 +12,10 @@ *********************************************************************/ #include "mingraph_coding.h" - #include "dbm/mingraph.h" -#include "base/bitstring.h" -#include "debug/macros.h" + +#include +#include #include #include diff --git a/src/mingraph_read.c b/src/mingraph_read.c index 78fbd5e..b3259c0 100644 --- a/src/mingraph_read.c +++ b/src/mingraph_read.c @@ -14,8 +14,9 @@ #include "mingraph_coding.h" #include "dbm/mingraph.h" -#include "base/bitstring.h" -#include "debug/macros.h" + +#include +#include #include #include diff --git a/src/mingraph_relation.c b/src/mingraph_relation.c index b15e70e..c13acc0 100644 --- a/src/mingraph_relation.c +++ b/src/mingraph_relation.c @@ -14,8 +14,9 @@ #include "mingraph_coding.h" #include "dbm/mingraph.h" -#include "base/bitstring.h" -#include "debug/macros.h" + +#include +#include #include #include diff --git a/src/mingraph_write.c b/src/mingraph_write.c index f77ed87..b33f434 100644 --- a/src/mingraph_write.c +++ b/src/mingraph_write.c @@ -18,8 +18,9 @@ #endif #include "dbm/mingraph.h" -#include "base/bitstring.h" -#include "debug/macros.h" + +#include +#include /** * @file diff --git a/src/priced.cpp b/src/priced.cpp index 7daf045..00b590e 100644 --- a/src/priced.cpp +++ b/src/priced.cpp @@ -15,8 +15,10 @@ #include "dbm/dbm_raw.hpp" #include "dbm/print.h" -#include "debug/macros.h" +#include + +#include // transform #include #include #include diff --git a/src/print.cpp b/src/print.cpp index b503201..581c2a2 100644 --- a/src/print.cpp +++ b/src/print.cpp @@ -15,19 +15,11 @@ #include "dbm/dbm.h" #include "dbm/fed.h" -#include "io/FileStreamBuffer.h" -#include "base/bitstring.h" -/** For easy conversion FILE* to ostream */ -class file_ostream -{ - io::FileStreamBuffer buffer; - std::ostream os; +#include +#include -public: - file_ostream(FILE* file): buffer{file}, os{&buffer} {} - operator std::ostream&() { return os; } -}; +using base::file_ostream; static const char* _print_prefix = ""; static bool _ruby_format = false; @@ -109,10 +101,8 @@ std::ostream& dbm_cppPrint(std::ostream& os, dbm::reader dbm) } void dbm_print(FILE* file, const raw_t* dbm, cindex_t dim) { - if (dbm != nullptr) { - auto fos = file_ostream{file}; - dbm_cppPrint(fos, {dbm, dim}); - } + if (dbm != nullptr) + dbm_cppPrint(file_ostream{file}, {dbm, dim}); } /* Shortcuts to print the difference highlight @@ -216,9 +206,9 @@ void dbm_printCloseDiff(FILE* file, const raw_t* dbm, cindex_t dim) /* check for infinity values * before printing. */ -std::ostream& dbm_cppPrintRaw(std::ostream& out, raw_t c) +std::ostream& dbm_cppPrintRaw(std::ostream& os, raw_t c) { - return dbm_cppPrintBound(out << (dbm_rawIsWeak(c) ? "<=" : "<"), dbm_raw2bound(c)); + return dbm_cppPrintBound(os << (dbm_rawIsWeak(c) ? "<=" : "<"), dbm_raw2bound(c)); } void dbm_printRaw(FILE* file, raw_t c) { dbm_cppPrintRaw(file_ostream{file}, c); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cff7d96..7dc05ec 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,24 +1,19 @@ # dbm tests... -set(libs UDBM UUtils::udebug UUtils::base UUtils::hash) - -include(../cmake/doctest.cmake) - -add_library(doctest_main OBJECT doctest_main.cpp) -target_link_libraries(doctest_main PRIVATE doctest::doctest) +set(libs UDBM UUtils::base) file(GLOB test_c_sources "test_*.c" "test_allocation.cpp") foreach(source ${test_c_sources}) get_filename_component(test_target ${source} NAME_WE) add_executable(${test_target} ${source}) - target_link_libraries(${test_target} ${libs}) + target_link_libraries(${test_target} PRIVATE ${libs}) endforeach() file(GLOB test_cpp_sources test_fed.cpp test_fed_dbm.cpp test_fp_intersection.cpp test_valuation.cpp test_constraint.cpp) foreach(source ${test_cpp_sources}) get_filename_component(test_target ${source} NAME_WE) add_executable(${test_target} ${source}) - target_link_libraries(${test_target} ${libs} doctest_main) + target_link_libraries(${test_target} ${libs} doctest_with_main) endforeach() # comments contain expected time of Linux debug build, YMMV, whereas timeouts diff --git a/test/doctest_main.cpp b/test/doctest_main.cpp deleted file mode 100644 index 0a3f254..0000000 --- a/test/doctest_main.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#include diff --git a/test/test_constraint.cpp b/test/test_constraint.cpp index 657bdde..8266232 100644 --- a/test/test_constraint.cpp +++ b/test/test_constraint.cpp @@ -1,11 +1,11 @@ #include "dbm/constraints.h" +#include + #include #include #include -#include - TEST_CASE("Constraint operators") { const auto vec = std::vector{{2, 1, 2}, {1, 2, -2}, {1, 0, 1}, {0, 1, -2}}; diff --git a/test/test_dbm.c b/test/test_dbm.c index 6eb03e3..5d9bf9d 100644 --- a/test/test_dbm.c +++ b/test/test_dbm.c @@ -22,8 +22,9 @@ #include "dbm/dbm.h" #include "dbm/gen.h" #include "dbm/print.h" -#include "base/bitstring.h" -#include "debug/macros.h" + +#include +#include #include #include diff --git a/test/test_ext.c b/test/test_ext.c index 1a2b291..dc68387 100644 --- a/test/test_ext.c +++ b/test/test_ext.c @@ -20,8 +20,9 @@ #include "dbm/dbm.h" #include "dbm/gen.h" #include "dbm/print.h" -#include "base/bitstring.h" -#include "debug/macros.h" + +#include +#include #include #include diff --git a/test/test_extrapolation.c b/test/test_extrapolation.c index 9bd235f..fea462d 100644 --- a/test/test_extrapolation.c +++ b/test/test_extrapolation.c @@ -24,7 +24,8 @@ #include "dbm/dbm.h" #include "dbm/gen.h" #include "dbm/print.h" -#include "debug/macros.h" + +#include #include #include diff --git a/test/test_fed.cpp b/test/test_fed.cpp index b4a97be..0158a5c 100644 --- a/test/test_fed.cpp +++ b/test/test_fed.cpp @@ -18,15 +18,16 @@ #include "dbm/fed.h" #include "dbm/gen.h" #include "dbm/print.h" -#include "debug/utils.h" + +#include + +#include #include // sort #include #include #include -#include - using namespace std; using namespace dbm; diff --git a/test/test_fp_intersection.cpp b/test/test_fp_intersection.cpp index 33eea24..166fd44 100644 --- a/test/test_fp_intersection.cpp +++ b/test/test_fp_intersection.cpp @@ -2,13 +2,13 @@ #include "dbm/print.h" #include "base/doubles.h" +#include + #include #include #include #include -#include - void printConstraint(const raw_t raw, const double i, const double j) { std::cout << i << (dbm_rawIsStrict(raw) ? "<" : "<=") << j << "+" << dbm_raw2bound(raw) << std::endl; diff --git a/test/test_mingraph.c b/test/test_mingraph.c index 6308d6b..9597935 100644 --- a/test/test_mingraph.c +++ b/test/test_mingraph.c @@ -23,8 +23,9 @@ #include "dbm/gen.h" #include "dbm/mingraph.h" #include "dbm/print.h" -#include "base/bitstring.h" -#include "debug/macros.h" + +#include +#include #include #include diff --git a/test/test_valuation.cpp b/test/test_valuation.cpp index dc0b2e3..0d2f6be 100644 --- a/test/test_valuation.cpp +++ b/test/test_valuation.cpp @@ -12,10 +12,10 @@ #include "dbm/valuation.h" -#include - #include +#include + using namespace std; using namespace dbm; diff --git a/winepath-for b/winepath-for new file mode 100755 index 0000000..5a0fac5 --- /dev/null +++ b/winepath-for @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +set -e + +if [ $# -eq 0 ]; then + echo "Script $0 prints WINEPATH to include MINGW and GCC runtime environments," + echo "so that libwinpthread-1.dll, libgcc_s_seh-1.dll etc are available everywhere." + echo "Takes the toolchain as an argument. For example:" + echo " x86_64-w64-mingw32 - for 64bit Windows binaries" + echo " i686-w64-mingw32 - for 32bit Windows binaries" + exit 1 +else + toolchain="$1" +fi + +CXX="${toolchain}-g++" + +if [ -z "$(command -v $CXX)" ]; then + echo "Failed to find a cross-compiler $CXX" + case $toolchain in + x86_64-w64-mingw32) + echo "Please install mingw-w64-x86-64-dev" + ;; + i686-w64-mingw32) + echo "Please install mingw-w64-i686-dev" + ;; + esac + exit 1 +fi + +if [ -z "$(command -v winepath)" ]; then + echo "Failed to find a winepath" + echo "Please install wine with winepath" + exit 1 +fi + +GCC_S_FILE=$($CXX --print-file-name libgcc_s.a) +GCC_S_FILE=$(realpath "$GCC_S_FILE") +GCC_RUNTIME_PATH=$(dirname "$GCC_S_FILE") +GCC_RUNTIME_WINEPATH=$(winepath --windows "$GCC_RUNTIME_PATH") + +WINPTHREAD_FILE=$($CXX --print-file-name libwinpthread-1.dll) +WINPTHREAD_FILE=$(realpath "$WINPTHREAD_FILE") +MINGW_RUNTIME_PATH=$(dirname "$WINPTHREAD_FILE") +MINGW_RUNTIME_WINEPATH=$(winepath --windows "$MINGW_RUNTIME_PATH") + +echo "${GCC_RUNTIME_WINEPATH};${MINGW_RUNTIME_WINEPATH}"