diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..b49debd1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "externals/sanitizers-cmake"] + path = externals/sanitizers-cmake + url = git://github.com/arsenm/sanitizers-cmake.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 136d7287..05f51d44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ set(OPENJPEG_LIBRARY_PROPERTIES # Path to additional CMake modules set(CMAKE_MODULE_PATH ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake + ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/externals/sanitizers-cmake/cmake ${CMAKE_MODULE_PATH}) # -------------------------------------------------------------------------- @@ -245,6 +246,10 @@ check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN) unset(CMAKE_REQUIRED_DEFINITIONS) # memalign (obsolete) check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN) + +# Make sure there is Sanitizer support in CMake +find_package(Sanitizers) + #----------------------------------------------------------------------------- # Build Library if(BUILD_JPIP_SERVER) diff --git a/externals/sanitizers-cmake b/externals/sanitizers-cmake new file mode 160000 index 00000000..6947cff3 --- /dev/null +++ b/externals/sanitizers-cmake @@ -0,0 +1 @@ +Subproject commit 6947cff3a9c9305eb9c16135dd81da3feb4bf87f diff --git a/src/bin/jp2/CMakeLists.txt b/src/bin/jp2/CMakeLists.txt index 4d4bd952..18c1ece3 100644 --- a/src/bin/jp2/CMakeLists.txt +++ b/src/bin/jp2/CMakeLists.txt @@ -44,6 +44,7 @@ endif() # Loop over all executables: foreach(exe opj_decompress opj_compress opj_dump) add_executable(${exe} ${exe}.c ${common_SRCS}) + add_sanitizers(${exe}) if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12") target_compile_options(${exe} PRIVATE ${OPENJP2_COMPILE_OPTIONS}) endif() diff --git a/src/bin/jp3d/CMakeLists.txt b/src/bin/jp3d/CMakeLists.txt index 3cac1a8f..1b316164 100644 --- a/src/bin/jp3d/CMakeLists.txt +++ b/src/bin/jp3d/CMakeLists.txt @@ -28,6 +28,7 @@ endif() # Loop over all executables: foreach(exe opj_jp3d_compress opj_jp3d_decompress) add_executable(${exe} ${exe}.c ${common_SRCS}) + add_sanitizers(${exe}) target_link_libraries(${exe} openjp3d) # On unix you need to link to the math library: if(UNIX) diff --git a/src/bin/jpip/CMakeLists.txt b/src/bin/jpip/CMakeLists.txt index 8dbf5775..3ea6362c 100644 --- a/src/bin/jpip/CMakeLists.txt +++ b/src/bin/jpip/CMakeLists.txt @@ -10,6 +10,7 @@ include_directories( # Tool to embed metadata into JP2 file add_executable(opj_jpip_addxml opj_jpip_addxml.c) +add_sanitizers(opj_jpip_addxml) # Install exe install(TARGETS opj_jpip_addxml EXPORT OpenJPEGTargets @@ -23,6 +24,7 @@ if(BUILD_JPIP_SERVER) # Build executable add_executable(opj_server ${OPJ_SERVER_SRCS}) + add_sanitizers(opj_server) target_link_libraries(opj_server ${FCGI_LIBRARIES} openjpip_server) set_property( TARGET opj_server @@ -49,6 +51,7 @@ set(EXES ) foreach(exe ${EXES}) add_executable(${exe} ${exe}.c) +add_sanitizers(${exe}) target_link_libraries(${exe} openjpip) install(TARGETS ${exe} EXPORT OpenJPEGTargets diff --git a/src/bin/jpwl/CMakeLists.txt b/src/bin/jpwl/CMakeLists.txt index 5df225de..baaa27df 100644 --- a/src/bin/jpwl/CMakeLists.txt +++ b/src/bin/jpwl/CMakeLists.txt @@ -37,6 +37,7 @@ foreach(exe decompress compress) ${jpwl_exe}.c ${common_SRCS} ) + add_sanitizers(${jpwl_exe}) set_property( TARGET ${jpwl_exe} APPEND PROPERTY COMPILE_DEFINITIONS USE_JPWL diff --git a/src/bin/mj2/CMakeLists.txt b/src/bin/mj2/CMakeLists.txt index 5d3e288b..1901f494 100644 --- a/src/bin/mj2/CMakeLists.txt +++ b/src/bin/mj2/CMakeLists.txt @@ -32,6 +32,7 @@ foreach(exe ${MJ2_SRCS} ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c ) + add_sanitizers(${exe}) set_property( TARGET ${exe} APPEND PROPERTY COMPILE_DEFINITIONS USE_MJ2 diff --git a/src/bin/wx/OPJViewer/CMakeLists.txt b/src/bin/wx/OPJViewer/CMakeLists.txt index 66cf01d2..53f007c0 100644 --- a/src/bin/wx/OPJViewer/CMakeLists.txt +++ b/src/bin/wx/OPJViewer/CMakeLists.txt @@ -26,4 +26,5 @@ set(OPJV_SRCS ${OPENJPEG_SOURCE_DIR}/src/bin/jp2/index.c ) add_executable(opjviewer ${OPJV_SRCS}) +add_sanitizers(opjviewer) target_link_libraries(opjviewer ${wxWidgets_LIBRARIES} openjpeg) diff --git a/src/lib/openjp2/CMakeLists.txt b/src/lib/openjp2/CMakeLists.txt index 9f79b9c3..2910900d 100644 --- a/src/lib/openjp2/CMakeLists.txt +++ b/src/lib/openjp2/CMakeLists.txt @@ -94,11 +94,14 @@ else() if(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) # Builds both static and dynamic libs add_library(${OPENJPEG_LIBRARY_NAME} SHARED ${OPENJPEG_SRCS}) + add_sanitizers(${OPENJPEG_LIBRARY_NAME}) add_library(openjp2_static STATIC ${OPENJPEG_SRCS}) + add_sanitizers(openjp2_static) set_target_properties(openjp2_static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME}) set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME} openjp2_static) else() add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS}) + add_sanitizers(${OPENJPEG_LIBRARY_NAME}) set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME}) endif() endif() @@ -135,6 +138,7 @@ if(BUILD_LUTS_GENERATOR) # internal utility to generate t1_luts.h (part of the jp2 lib) # no need to install: add_executable(t1_generate_luts t1_generate_luts.c) + add_sanitizers(t1_generate_luts) if(UNIX) target_link_libraries(t1_generate_luts m) endif() diff --git a/src/lib/openjp3d/CMakeLists.txt b/src/lib/openjp3d/CMakeLists.txt index b0469af1..14fece57 100644 --- a/src/lib/openjp3d/CMakeLists.txt +++ b/src/lib/openjp3d/CMakeLists.txt @@ -23,6 +23,7 @@ endif() # build jp3d lib: add_library(${OPENJP3D_LIBRARY_NAME} ${OPENJP3D_SRCS}) +add_sanitizers(${OPENJP3D_LIBRARY_NAME}) if(UNIX) target_link_libraries(${OPENJP3D_LIBRARY_NAME} m) endif() diff --git a/src/lib/openjpip/CMakeLists.txt b/src/lib/openjpip/CMakeLists.txt index b3cb8ce8..e49bc7ed 100644 --- a/src/lib/openjpip/CMakeLists.txt +++ b/src/lib/openjpip/CMakeLists.txt @@ -60,6 +60,7 @@ if(WIN32) endif() endif() add_library(openjpip ${OPENJPIP_SRCS} ${LOCAL_SRCS}) +add_sanitizers(openjpip) set_target_properties(openjpip PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES}) if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12") @@ -81,6 +82,7 @@ install(TARGETS openjpip if(BUILD_JPIP_SERVER) add_library(openjpip_server STATIC ${OPENJPIP_SRCS} ${SERVER_SRCS}) + add_sanitizers(openjpip_server) target_link_libraries(openjpip_server ${FCGI_LIBRARIES} ${CURL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(openjpip_server PROPERTIES COMPILE_FLAGS "-DSERVER") diff --git a/src/lib/openjpwl/CMakeLists.txt b/src/lib/openjpwl/CMakeLists.txt index 1b33adbe..5c6208c1 100644 --- a/src/lib/openjpwl/CMakeLists.txt +++ b/src/lib/openjpwl/CMakeLists.txt @@ -46,6 +46,7 @@ if(WIN32) endif() endif() add_library(openjpwl ${JPWL_SRCS} ${OPENJPEG_SRCS}) +add_sanitizers(openjpwl) if(UNIX) target_link_libraries(openjpwl m) endif() diff --git a/src/lib/openmj2/CMakeLists.txt b/src/lib/openmj2/CMakeLists.txt index 25294b20..2054a534 100644 --- a/src/lib/openmj2/CMakeLists.txt +++ b/src/lib/openmj2/CMakeLists.txt @@ -40,6 +40,7 @@ endif() # build mj2 lib: add_library(${OPENMJ2_LIBRARY_NAME} ${OPENMJ2_SRCS}) +add_sanitizers(${OPENMJ2_LIBRARY_NAME}) # FIXME: We are using an openjpeg 1.5 copy: #target_link_libraries(${OPENMJ2_LIBRARY_NAME} openjp2) if(UNIX)