diff --git a/.github/workflows/cmake_android.yml b/.github/workflows/cmake_android.yml index 25ab4553..50e1e7a1 100644 --- a/.github/workflows/cmake_android.yml +++ b/.github/workflows/cmake_android.yml @@ -41,7 +41,7 @@ jobs: shell: bash run: | mkdir build - cmake -G Ninja -B build -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchains/android.cmake -DUHDR_ANDROID_NDK_PATH=${{ steps.setup-ndk.outputs.ndk-path }} -DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1 -DANDROID_ABI=${{ matrix.abi }} -DANDROID_PLATFORM=android-23 -DUHDR_BUILD_JAVA=1 + cmake -G Ninja -B build -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchains/android.cmake -DUHDR_ANDROID_NDK_PATH=${{ steps.setup-ndk.outputs.ndk-path }} -DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1 -DANDROID_ABI=${{ matrix.abi }} -DANDROID_PLATFORM=android-23 -DUHDR_BUILD_JAVA=1 -DUHDR_ENABLE_WERROR=1 - name: Build run: cmake --build build diff --git a/.github/workflows/cmake_linux.yml b/.github/workflows/cmake_linux.yml index 72aef4b4..667cda73 100644 --- a/.github/workflows/cmake_linux.yml +++ b/.github/workflows/cmake_linux.yml @@ -17,7 +17,7 @@ jobs: build_type: Release cc: gcc cxx: g++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DUHDR_ENABLE_WERROR=1' # - name: "ubuntu latest clang rel ninja" @@ -25,7 +25,7 @@ jobs: build_type: Release cc: clang cxx: clang++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DUHDR_ENABLE_WERROR=1' # - name: "ubuntu latest gcc rel ninja with deps" @@ -33,7 +33,7 @@ jobs: build_type: Release cc: gcc cxx: g++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1 -DUHDR_ENABLE_WERROR=1' # - name: "ubuntu latest clang rel ninja with deps sanitize address" @@ -41,7 +41,7 @@ jobs: build_type: Release cc: clang cxx: clang++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1 -DUHDR_SANITIZE_OPTIONS=address' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1 -DUHDR_SANITIZE_OPTIONS=address -DUHDR_ENABLE_WERROR=1' # - name: "ubuntu latest clang rel ninja fuzzers sanitize address" @@ -49,7 +49,7 @@ jobs: build_type: Release cc: clang cxx: clang++ - cmake-opts: '-DUHDR_BUILD_FUZZERS=1 -DUHDR_SANITIZE_OPTIONS=address' + cmake-opts: '-DUHDR_BUILD_FUZZERS=1 -DUHDR_SANITIZE_OPTIONS=address -DUHDR_ENABLE_WERROR=1' # - name: "ubuntu latest gcc rel ninja static" @@ -57,7 +57,7 @@ jobs: build_type: Release cc: gcc cxx: g++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DBUILD_SHARED_LIBS=0' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DBUILD_SHARED_LIBS=0 -DUHDR_ENABLE_WERROR=1' # - name: "ubuntu latest clang rel ninja static" @@ -65,7 +65,7 @@ jobs: build_type: Release cc: clang cxx: clang++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DBUILD_SHARED_LIBS=0' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DBUILD_SHARED_LIBS=0 -DUHDR_ENABLE_WERROR=1' steps: - name: Checkout the repository diff --git a/.github/workflows/cmake_mac.yml b/.github/workflows/cmake_mac.yml index 0f75979e..75b9f3ec 100644 --- a/.github/workflows/cmake_mac.yml +++ b/.github/workflows/cmake_mac.yml @@ -17,7 +17,7 @@ jobs: build_type: Release cc: clang cxx: clang++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DUHDR_ENABLE_WERROR=1' # - name: "macOS-13 clang rel ninja" @@ -25,7 +25,7 @@ jobs: build_type: Release cc: clang cxx: clang++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DUHDR_ENABLE_WERROR=1' # - name: "macOS latest ARM64 clang rel ninja with deps" @@ -33,7 +33,7 @@ jobs: build_type: Release cc: clang cxx: clang++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1 -DUHDR_ENABLE_WERROR=1' # - name: "macOS latest ARM64 clang rel ninja static" @@ -41,7 +41,7 @@ jobs: build_type: Release cc: clang cxx: clang++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DBUILD_SHARED_LIBS=0' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DBUILD_SHARED_LIBS=0 -DUHDR_ENABLE_WERROR=1' # - name: "macOS-13 clang rel ninja static" @@ -49,7 +49,7 @@ jobs: build_type: Release cc: clang cxx: clang++ - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DBUILD_SHARED_LIBS=0' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DBUILD_SHARED_LIBS=0 -DUHDR_ENABLE_WERROR=1' steps: - name: Checkout the repository diff --git a/.github/workflows/cmake_win.yml b/.github/workflows/cmake_win.yml index d1f5b966..0778d3c3 100644 --- a/.github/workflows/cmake_win.yml +++ b/.github/workflows/cmake_win.yml @@ -17,7 +17,7 @@ jobs: build_type: Release cc: cl cxx: cl - cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1' + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1 -DUHDR_ENABLE_WERROR=1' steps: - name: Checkout the repository diff --git a/CMakeLists.txt b/CMakeLists.txt index 64eef329..4fb562a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,11 +102,13 @@ option_if_not_defined(UHDR_BUILD_TESTS "Build unit tests " FALSE) option_if_not_defined(UHDR_BUILD_BENCHMARK "Build benchmark tests " FALSE) option_if_not_defined(UHDR_BUILD_FUZZERS "Build fuzz test applications " FALSE) option_if_not_defined(UHDR_BUILD_DEPS "Build deps and not use pre-installed packages " FALSE) +option_if_not_defined(UHDR_BUILD_JAVA "Build JNI wrapper and Java front-end classes " FALSE) + option_if_not_defined(UHDR_ENABLE_LOGS "Build with verbose logging " FALSE) option_if_not_defined(UHDR_ENABLE_INSTALL "Enable install and uninstall targets for libuhdr package " TRUE) option_if_not_defined(UHDR_ENABLE_INTRINSICS "Build with SIMD acceleration " TRUE) option_if_not_defined(UHDR_ENABLE_GLES "Build with GPU acceleration " FALSE) -option_if_not_defined(UHDR_BUILD_JAVA "Build JNI wrapper and Java front-end classes " FALSE) +option_if_not_defined(UHDR_ENABLE_WERROR "Build with -Werror" FALSE) # pre-requisites if(UHDR_BUILD_TESTS AND EMSCRIPTEN) @@ -205,6 +207,7 @@ if(UHDR_BUILD_FUZZERS) add_compile_options(-fsanitize=fuzzer-no-link) endif() +set(UHDR_WERROR_FLAGS "") if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Disable specific warnings @@ -244,6 +247,11 @@ else() add_compile_options(-march=rv64gc) add_compile_options(-mabi=lp64d) endif() + + if(UHDR_ENABLE_WERROR) + CheckCompilerOption("-Werror" SUPPORTS_WERROR) + set(UHDR_WERROR_FLAGS "-Werror") + endif() endif() ########################################################### @@ -533,6 +541,7 @@ target_include_directories(${IMAGEIO_TARGET_NAME} PRIVATE set(UHDR_CORE_LIB_NAME core) add_library(${UHDR_CORE_LIB_NAME} STATIC ${UHDR_CORE_SRCS_LIST}) +target_compile_options(${UHDR_CORE_LIB_NAME} PRIVATE ${UHDR_WERROR_FLAGS}) if(NOT JPEG_FOUND) add_dependencies(${UHDR_CORE_LIB_NAME} ${JPEGTURBO_TARGET_NAME}) endif() @@ -558,6 +567,7 @@ target_link_libraries(${UHDR_CORE_LIB_NAME} PRIVATE ${COMMON_LIBS_LIST} ${IMAGEI if(UHDR_BUILD_EXAMPLES) add_executable(ultrahdr_app "${EXAMPLES_DIR}/ultrahdr_app.cpp") add_dependencies(ultrahdr_app ${UHDR_CORE_LIB_NAME}) + target_compile_options(ultrahdr_app PRIVATE ${UHDR_WERROR_FLAGS}) if(UHDR_BUILD_FUZZERS) target_link_options(ultrahdr_app PRIVATE -fsanitize=fuzzer-no-link) endif() @@ -586,6 +596,7 @@ endif() if(UHDR_BUILD_TESTS) add_executable(ultrahdr_unit_test ${UHDR_TEST_SRCS_LIST}) add_dependencies(ultrahdr_unit_test ${GTEST_TARGET_NAME} ${UHDR_CORE_LIB_NAME}) + target_compile_options(ultrahdr_unit_test PRIVATE ${UHDR_WERROR_FLAGS}) target_include_directories(ultrahdr_unit_test PRIVATE ${PRIVATE_INCLUDE_DIR} ${GTEST_INCLUDE_DIRS} @@ -600,6 +611,7 @@ endif() if(UHDR_BUILD_BENCHMARK) add_executable(ultrahdr_bm ${UHDR_BM_SRCS_LIST}) add_dependencies(ultrahdr_bm ${BM_TARGET_NAME} ${UHDR_CORE_LIB_NAME}) + target_compile_options(ultrahdr_bm PRIVATE ${UHDR_WERROR_FLAGS}) target_include_directories(ultrahdr_bm PRIVATE ${PRIVATE_INCLUDE_DIR} ${BENCHMARK_INCLUDE_DIR} @@ -648,6 +660,7 @@ endif() if(UHDR_BUILD_FUZZERS) add_executable(ultrahdr_enc_fuzzer ${FUZZERS_DIR}/ultrahdr_enc_fuzzer.cpp) add_dependencies(ultrahdr_enc_fuzzer ${UHDR_CORE_LIB_NAME}) + target_compile_options(ultrahdr_enc_fuzzer PRIVATE ${UHDR_WERROR_FLAGS}) target_include_directories(ultrahdr_enc_fuzzer PRIVATE ${PRIVATE_INCLUDE_DIR}) if(DEFINED ENV{LIB_FUZZING_ENGINE}) target_link_options(ultrahdr_enc_fuzzer PRIVATE $ENV{LIB_FUZZING_ENGINE}) @@ -658,6 +671,7 @@ if(UHDR_BUILD_FUZZERS) add_executable(ultrahdr_dec_fuzzer ${FUZZERS_DIR}/ultrahdr_dec_fuzzer.cpp) add_dependencies(ultrahdr_dec_fuzzer ${UHDR_CORE_LIB_NAME}) + target_compile_options(ultrahdr_dec_fuzzer PRIVATE ${UHDR_WERROR_FLAGS}) target_include_directories(ultrahdr_dec_fuzzer PRIVATE ${PRIVATE_INCLUDE_DIR}) if(DEFINED ENV{LIB_FUZZING_ENGINE}) target_link_options(ultrahdr_dec_fuzzer PRIVATE $ENV{LIB_FUZZING_ENGINE}) @@ -670,6 +684,7 @@ endif() set(UHDR_TARGET_NAME uhdr) add_library(${UHDR_TARGET_NAME}) add_dependencies(${UHDR_TARGET_NAME} ${UHDR_CORE_LIB_NAME}) +target_compile_options(${UHDR_TARGET_NAME} PRIVATE ${UHDR_WERROR_FLAGS}) if(UHDR_ENABLE_GLES) target_link_libraries(${UHDR_TARGET_NAME} PRIVATE ${EGL_LIBRARIES} ${OPENGLES3_LIBRARIES}) endif() @@ -692,6 +707,7 @@ if(BUILD_SHARED_LIBS) set(UHDR_TARGET_NAME_STATIC uhdr-static) add_library(${UHDR_TARGET_NAME_STATIC} STATIC) add_dependencies(${UHDR_TARGET_NAME_STATIC} ${UHDR_CORE_LIB_NAME}) + target_compile_options(${UHDR_TARGET_NAME_STATIC} PRIVATE ${UHDR_WERROR_FLAGS}) if(UHDR_ENABLE_GLES) target_link_libraries(${UHDR_TARGET_NAME_STATIC} PRIVATE ${EGL_LIBRARIES} ${OPENGLES3_LIBRARIES}) endif() @@ -713,6 +729,7 @@ if(UHDR_BUILD_JAVA) add_library(${UHDR_JNI_TARGET_NAME} SHARED ${UHDR_JNI_SRCS_LIST}) add_dependencies(${UHDR_JNI_TARGET_NAME} ${UHDR_TARGET_NAME}) target_include_directories(${UHDR_JNI_TARGET_NAME} PRIVATE ${UHDR_JNI_INCLUDE_PATH} ${EXPORT_INCLUDE_DIR}) + target_compile_options(${UHDR_JNI_TARGET_NAME} PRIVATE ${UHDR_WERROR_FLAGS}) target_link_libraries(${UHDR_JNI_TARGET_NAME} PRIVATE ${UHDR_TARGET_NAME}) add_jar(uhdr-java SOURCES ${UHDR_JAVA_SRCS_LIST} ${UHDR_APP_SRC} ENTRY_POINT UltraHdrApp) diff --git a/docs/building.md b/docs/building.md index b428cf32..c3a215d7 100644 --- a/docs/building.md +++ b/docs/building.md @@ -57,12 +57,13 @@ Following is a list of available options: | `UHDR_BUILD_BENCHMARK` | OFF | Build Benchmark Tests. These are for profiling libuhdr encode/decode API. Resources used by benchmark tests are shared [here](https://storage.googleapis.com/android_media/external/libultrahdr/benchmark/UltrahdrBenchmarkTestRes-1.0.zip). These are downloaded and extracted automatically during the build process for later benchmarking.
  • Since [v1.0.0](https://github.com/google/libultrahdr/releases/tag/1.0.0), considerable API changes were made and benchmark tests need to be updated accordingly. So the current profile numbers may not be accurate and/or give a complete picture.
  • Benchmark tests are not supported on Windows and this parameter is forced to **OFF** internally while building on **WIN32** platforms.
| | `UHDR_BUILD_FUZZERS` | OFF | Build Fuzz Test Applications. Mostly for Devs.
  • Fuzz applications are built by instrumenting the entire software suite. This includes dependency libraries. This is done by forcing `UHDR_BUILD_DEPS` to **ON** internally.
| | `UHDR_BUILD_DEPS` | OFF | Clone and Build project dependencies and not use pre-installed packages. | +| `UHDR_BUILD_JAVA` | OFF | Build JNI wrapper, Java front-end classes and Java sample application. | | `UHDR_ENABLE_LOGS` | OFF | Build with verbose logging. | | `UHDR_ENABLE_INSTALL` | ON | Enable install and uninstall targets for libuhdr package.
  • For system wide installation it is best if dependencies are acquired from OS package manager instead of building from source. This is to avoid conflicts with software that is using a different version of the said dependency and also links to libuhdr. So if `UHDR_BUILD_DEPS` is **ON** then `UHDR_ENABLE_INSTALL` is forced to **OFF** internally. | | `UHDR_ENABLE_INTRINSICS` | ON | Build with SIMD acceleration. Sections of libuhdr are accelerated for Arm Neon architectures and these are enabled.
    • For x86/x86_64 architectures currently no SIMD acceleration is present. Consequently this option has no effect.
    • This parameter has no effect no SIMD configuration settings of dependencies.
    | | `UHDR_ENABLE_GLES` | OFF | Build with GPU acceleration. | +| `UHDR_ENABLE_WERROR` | OFF | Enable -Werror when building. | | `UHDR_MAX_DIMENSION` | 8192 | Maximum dimension supported by the library. The library defaults to handling images upto resolution 8192x8192. For different resolution needs use this option. For example, `-DUHDR_MAX_DIMENSION=4096`. | -| `UHDR_BUILD_JAVA` | OFF | Build JNI wrapper, Java front-end classes and Java sample application. | | `UHDR_SANITIZE_OPTIONS` | OFF | Build library with sanitize options. Values set to this parameter are passed to directly to compilation option `-fsanitize`. For example, `-DUHDR_SANITIZE_OPTIONS=address,undefined` adds `-fsanitize=address,undefined` to the list of compilation options. CMake configuration errors are raised if the compiler does not support these flags. This is useful during fuzz testing.
    • As `-fsanitize` is an instrumentation option, dependencies are also built from source instead of using pre-builts. This is done by forcing `UHDR_BUILD_DEPS` to **ON** internally.
    | | | | |