Skip to content

Commit

Permalink
Add option to enable compiling with -Werror
Browse files Browse the repository at this point in the history
The libultrahdr codebase itself compiles cleanly with -Werror however
third-party dependent libraries do not. Since there is no way of
specifying options for only libultrahdr-related code itself, add a new
UHDR_ENABLE_WERROR option to enable passing -Werror for just the core
libraries and dependent targets.
  • Loading branch information
georges-arm committed Sep 24, 2024
1 parent 2188c35 commit afe3bc2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -192,6 +194,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
Expand Down Expand Up @@ -231,6 +234,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()

###########################################################
Expand Down Expand Up @@ -520,6 +528,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()
Expand All @@ -545,6 +554,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()
Expand All @@ -570,6 +580,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}
Expand All @@ -584,6 +595,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}
Expand Down Expand Up @@ -632,6 +644,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})
Expand All @@ -642,6 +655,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})
Expand All @@ -654,6 +668,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()
Expand All @@ -676,6 +691,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()
Expand All @@ -697,6 +713,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)
Expand Down
3 changes: 2 additions & 1 deletion docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <ul><li> 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. </li><li> Benchmark tests are not supported on Windows and this parameter is forced to **OFF** internally while building on **WIN32** platforms. </li></ul>|
| `UHDR_BUILD_FUZZERS` | OFF | Build Fuzz Test Applications. Mostly for Devs. <ul><li> 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. </li></ul> |
| `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. <ul><li> 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. <ul><li> For x86/x86_64 architectures currently no SIMD acceleration is present. Consequently this option has no effect. </li><li> This parameter has no effect no SIMD configuration settings of dependencies. </li></ul> |
| `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. <ul><li> 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. </li></ul> |
| | | |

Expand Down

0 comments on commit afe3bc2

Please sign in to comment.