From 4f4de7070e2a9c769b41c5cdc38a0b19eb4cfa07 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 18 Mar 2014 15:59:08 +0000 Subject: [PATCH] [1.5] Create a new cmake option to choose between convienient copy of getopt and system installed one Udapte issue 301 --- CMakeLists.txt | 2 ++ applications/codec/CMakeLists.txt | 6 +++++- applications/common/opj_getopt.c | 4 ++++ applications/common/opj_getopt.h | 18 +++++++++++++++++- opj_config.h.cmake.in | 1 + tests/CMakeLists.txt | 13 +++++++------ 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aaa4b22b..253e46ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,6 +233,8 @@ IF(BUILD_JPIP) ENDIF(BUILD_JPIP) OPTION(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF) OPTION(BUILD_JAVA "Build the openjpeg jar (Java)" OFF) +OPTION(USE_SYSTEM_GETOPT "Prefer system installed getopt()" OFF) +MARK_AS_ADVANCED(USE_SYSTEM_GETOPT) MARK_AS_ADVANCED(BUILD_VIEWER) MARK_AS_ADVANCED(BUILD_JAVA) diff --git a/applications/codec/CMakeLists.txt b/applications/codec/CMakeLists.txt index 2a195155..c0a4dd72 100644 --- a/applications/codec/CMakeLists.txt +++ b/applications/codec/CMakeLists.txt @@ -5,8 +5,12 @@ SET(common_SRCS convert.c index.c ${OPENJPEG_SOURCE_DIR}/applications/common/color.c - ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c ) +if(NOT USE_SYSTEM_GETOPT) + list(APPEND common_SRCS + ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c + ) +endif() # Headers file are located here: INCLUDE_DIRECTORIES( diff --git a/applications/common/opj_getopt.c b/applications/common/opj_getopt.c index 6fcead46..2c45c46a 100644 --- a/applications/common/opj_getopt.c +++ b/applications/common/opj_getopt.c @@ -38,6 +38,10 @@ static char sccsid[] = "@(#)opj_getopt.c 8.3 (Berkeley) 4/27/95"; #include #include "opj_getopt.h" +#ifdef USE_SYSTEM_GETOPT +#error +#endif + int opj_opterr = 1, /* if error message should be printed */ opj_optind = 1, /* index into parent argv vector */ opj_optopt, /* character checked for validity */ diff --git a/applications/common/opj_getopt.h b/applications/common/opj_getopt.h index e1f41a56..1fa3558d 100644 --- a/applications/common/opj_getopt.h +++ b/applications/common/opj_getopt.h @@ -1,5 +1,7 @@ /* last review : october 29th, 2002 */ +#include "opj_config.h" + #ifndef _GETOPT_H_ #define _GETOPT_H_ @@ -9,12 +11,25 @@ typedef struct opj_option int has_arg; int *flag; int val; -}opj_option_t; +} opj_option_t; #define NO_ARG 0 #define REQ_ARG 1 #define OPT_ARG 2 +#ifdef USE_SYSTEM_GETOPT +#include + +#define opj_opterr opterr +#define opj_optind optind +#define opj_optopt optopt +#define opj_optreset optreset +#define opj_optarg optarg + +#define opj_getopt getopt +#define opj_getopt_long getopt_long + +#else extern int opj_opterr; extern int opj_optind; extern int opj_optopt; @@ -26,4 +41,5 @@ extern int opj_getopt_long(int argc, char * const argv[], const char *optstring, const opj_option_t *longopts, int totlen); extern void reset_options_reading(void); +#endif /* USE_SYSTEM_GETOPT */ #endif /* _GETOPT_H_ */ diff --git a/opj_config.h.cmake.in b/opj_config.h.cmake.in index 999d366c..1b21e068 100644 --- a/opj_config.h.cmake.in +++ b/opj_config.h.cmake.in @@ -19,6 +19,7 @@ #cmakedefine HAVE_LIBLCMS2 #cmakedefine HAVE_LCMS1_H #cmakedefine HAVE_LCMS2_H +#cmakedefine USE_SYSTEM_GETOPT /* Byte order. */ /* All compilers that support Mac OS X define either __BIG_ENDIAN__ or diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ff3057eb..fa7747e5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,14 +11,15 @@ INCLUDE_DIRECTORIES( # First thing define the common source: SET(comparePGXimages_SRCS comparePGXimages.c ${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c - ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c ) +SET(compare_dump_files_SRCS compare_dump_files.c) +SET(compareRAWimages_SRCS compareRAWimages.c) -SET(compare_dump_files_SRCS compare_dump_files.c - ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c) - -SET(compareRAWimages_SRCS compareRAWimages.c - ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c) +if(NOT USE_SYSTEM_GETOPT) + list(APPEND comparePGXimages_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c) + list(APPEND compare_dump_files_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c) + list(APPEND compareRAWimages_SRCS ${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c) +endif() ADD_EXECUTABLE(comparePGXimages ${comparePGXimages_SRCS}) TARGET_LINK_LIBRARIES(comparePGXimages