From 5a3c3e5a4aa6574e6dd18f574193375ab5dce68f Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Sat, 16 May 2020 23:32:15 +0200 Subject: [PATCH 1/4] cmake/FindCPPCHECK.cmake: enforce the REQUIRED flag passed to find_package --- cmake/FindCPPCHECK.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/FindCPPCHECK.cmake b/cmake/FindCPPCHECK.cmake index c7b79925aa..ff29c912a1 100644 --- a/cmake/FindCPPCHECK.cmake +++ b/cmake/FindCPPCHECK.cmake @@ -1,2 +1,8 @@ find_program(CPPCHECK_EXECUTABLE cppcheck ) mark_as_advanced( CPPCHECK_EXECUTABLE ) + +if (NOT CPPCHECK_EXECUTABLE) + if (CPPCHECK_FIND_REQUIRED) + message(FATAL_ERROR "ERROR: Could not find cppcheck") + endif () +endif () From 49e9b90545c15b570fe3a61402f8d370c3f81638 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Sun, 17 May 2020 00:07:05 +0200 Subject: [PATCH 2/4] test_sparse_array: don't put main() in a namespace, fix a linking error The main() function is expected to be a global function, the code won't link as a standalone executable if main() is put into a namespace. This fixes the following linking error: ----------------------------------------------------------------------- [ 32%] Linking CXX executable ../../../bin/test_sparse_array /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x20): undefined reference to `main' ----------------------------------------------------------------------- --- src/lib/jp2/util/test_sparse_array.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib/jp2/util/test_sparse_array.cpp b/src/lib/jp2/util/test_sparse_array.cpp index c5457f6800..ebb07c61db 100644 --- a/src/lib/jp2/util/test_sparse_array.cpp +++ b/src/lib/jp2/util/test_sparse_array.cpp @@ -52,8 +52,6 @@ #include "grok_includes.h" -namespace grk { - int main() { uint32_t i, j, w, h; @@ -217,5 +215,3 @@ int main() return 0; } - -} From 293b3052f5a1cd0a5989f09e8cb0a82a397edbcc Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Sun, 17 May 2020 00:15:15 +0200 Subject: [PATCH 3/4] jp2: split executable modules from library code Split executable modules from the library object, in particular this is to prevent the exit() symbol to become part of the library, as this may raise some flags in linting tools like "lintian" from Debian, e.g.: X: libgrokj2k1: shlib-calls-exit usr/lib/x86_64-linux-gnu/libgrokj2k.so.7.1.0 Still keep executable sources grouped in a new GROK_EXECUTABLES_SRCS variable to be able to run cppcheck on all of them. --- src/lib/jp2/CMakeLists.txt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib/jp2/CMakeLists.txt b/src/lib/jp2/CMakeLists.txt index 4f1c46c2eb..ab99933955 100644 --- a/src/lib/jp2/CMakeLists.txt +++ b/src/lib/jp2/CMakeLists.txt @@ -47,10 +47,15 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/mct ${CMAKE_CURRENT_SOURCE_DIR}/t2 ) -# Defines the source code for the library -set(GROK_SRCS + +# Defines the source code for executables +set(GROK_EXECUTABLES_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/util/test_sparse_array.cpp ${CMAKE_CURRENT_SOURCE_DIR}/util/bench_dwt.cpp +) + +# Defines the source code for the library +set(GROK_LIBRARY_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/util/BufferedStream.cpp ${CMAKE_CURRENT_SOURCE_DIR}/util/BufferedStream.h ${CMAKE_CURRENT_SOURCE_DIR}/util/IBufferedStream.h @@ -196,17 +201,17 @@ if(WIN32) else() add_definitions(-DGRK_STATIC) endif() - add_library(${GROK_LIBRARY_NAME} ${GROK_SRCS}) + add_library(${GROK_LIBRARY_NAME} ${GROK_LIBRARY_SRCS}) set(INSTALL_LIBS ${GROK_LIBRARY_NAME}) else() if(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) # Builds both static and dynamic libs, and install static version - add_library(${GROK_LIBRARY_NAME} SHARED ${GROK_SRCS}) - add_library(${GROK_LIBRARY_NAME}_static STATIC ${GROK_SRCS}) + add_library(${GROK_LIBRARY_NAME} SHARED ${GROK_LIBRARY_SRCS}) + add_library(${GROK_LIBRARY_NAME}_static STATIC ${GROK_LIBRARY_SRCS}) set_target_properties(${GROK_LIBRARY_NAME}_static PROPERTIES OUTPUT_NAME ${GROK_LIBRARY_NAME}) set(INSTALL_LIBS ${GROK_LIBRARY_NAME} ${GROK_LIBRARY_NAME}_static) else() - add_library(${GROK_LIBRARY_NAME} ${GROK_SRCS}) + add_library(${GROK_LIBRARY_NAME} ${GROK_LIBRARY_SRCS}) set(INSTALL_LIBS ${GROK_LIBRARY_NAME}) endif() endif() @@ -257,7 +262,7 @@ endif() # warning regex to catch them. if(GROK_CPPCHECK) find_package(CPPCHECK REQUIRED) - foreach(f ${GROK_SRCS}) + foreach(f ${GROK_EXECUTABLES_SRCS} ${GROK_LIBRARY_SRCS}) # cppcheck complains about too many configuration, pretend to be WIN32: add_custom_command(TARGET ${GROK_LIBRARY_NAME} COMMAND ${CPPCHECK_EXECUTABLE} -DWIN32 ${f}) From 34a0d280bd3aab2ccb9bbd1a09e3ebb63b08c100 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Sun, 17 May 2020 00:23:26 +0200 Subject: [PATCH 4/4] jp2: add t1_generate_luts.cpp to GROK_EXECUTABLES_SRCS to run cppcheck on it --- src/lib/jp2/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/jp2/CMakeLists.txt b/src/lib/jp2/CMakeLists.txt index ab99933955..34f84eed1a 100644 --- a/src/lib/jp2/CMakeLists.txt +++ b/src/lib/jp2/CMakeLists.txt @@ -52,6 +52,7 @@ include_directories( set(GROK_EXECUTABLES_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/util/test_sparse_array.cpp ${CMAKE_CURRENT_SOURCE_DIR}/util/bench_dwt.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/t1/t1_part1/t1_generate_luts.cpp ) # Defines the source code for the library