Skip to content

Commit c7aff5a

Browse files
committed
examples: use build system to check system's getopt existance.
1 parent 0d0cef7 commit c7aff5a

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ if ( ${HAVE_CHMOD} )
126126
add_compile_definitions ( HAVE_CHMOD=1 )
127127
endif()
128128

129+
check_symbol_exists ( getopt "unistd.h" HAVE_GETOPT )
130+
if ( ${HAVE_GETOPT} )
131+
add_compile_definitions ( HAVE_GETOPT=1 )
132+
endif()
129133

130134
# Check backtrace
131135

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ AC_TYPE_UINT8_T
130130

131131
# Check functions
132132
AC_CHECK_FUNCS(chmod, AC_DEFINE([HAVE_CHMOD], [1]))
133+
AC_CHECK_FUNCS(getopt, AC_DEFINE([HAVE_GETOPT], [1]))
133134
AC_CHECK_FUNCS(strnlen, AC_DEFINE([HAVE_STRNLEN], [1]))
134135
AC_CHECK_FUNCS(strndup, AC_DEFINE([HAVE_STRNDUP], [1]))
135136
AC_CHECK_FUNCS(mempcpy, AC_DEFINE([HAVE_MEMPCPY], [1]))

examples/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ include_directories (
44
${PROJECT_BINARY_DIR}/src
55
)
66

7+
#check_symbol_exists ( chmod "unistd.h" HAVE_GETOPT )
78

8-
if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" )
9+
#if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" )
10+
if ( ${HAVE_GETOPT} )
11+
set ( ADFLIB_CUSTOM_GETOPT_SRC "")
12+
message ( STATUS "Using system's getopt implementation." )
13+
else()
914
set ( ADFLIB_CUSTOM_GETOPT_SRC
1015
getopt.c
1116
getopt.h )
12-
else()
13-
set ( ADFLIB_CUSTOM_GETOPT_SRC "")
17+
message ( STATUS "Using custom getopt implementation." )
18+
#message ( STATUS "ADFLIB_CUSTOM_GETOPT_SRC: ${ADFLIB_CUSTOM_GETOPT_SRC}" )
1419
endif()
1520

16-
1721
add_executable ( adfbitmap adfbitmap.c )
1822
target_link_libraries ( adfbitmap adf )
1923
set_target_properties ( adfbitmap PROPERTIES

examples/adfformat.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
#include <stdlib.h>
2727
#include <string.h>
2828

29+
#ifndef HAVE_GETOPT
30+
#include "getopt.h" // use custom getopt
31+
#endif
2932

30-
#ifdef WIN32
31-
#include "getopt.h"
32-
#else
33+
#ifndef WIN32
3334
#include <libgen.h>
3435
#include <unistd.h>
3536
#endif

examples/adfimgcreate.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
#include <stdlib.h>
2626
#include <string.h>
2727

28-
#ifdef WIN32
29-
#include "getopt.h"
30-
#else
28+
#ifndef HAVE_GETOPT
29+
#include "getopt.h" // use custom getopt
30+
#endif
31+
32+
#ifndef WIN32
3133
//#include <libgen.h>
3234
#include <unistd.h>
3335
#endif

examples/adfsalvage.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
#include <stdio.h>
2727
#include <stdlib.h>
2828

29-
#ifdef WIN32
30-
#include "getopt.h"
31-
#else
29+
#ifndef HAVE_GETOPT
30+
#include "getopt.h" // use custom getopt
31+
#endif
32+
33+
#ifndef WIN32
3234
#include <libgen.h>
3335
#include <unistd.h>
3436
#endif

0 commit comments

Comments
 (0)