Skip to content

Commit 167d5b5

Browse files
committed
core: enable iconv(3) in cmake
Enable optional iconv in fluent-bit Enabled by -D FLB_ICONV=Yes (default No) Requires libiconv-library (can be embedded to libc) Signed-off-by: Jukka Pihl <[email protected]>
1 parent c5ce877 commit 167d5b5

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

CMakeLists.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ option(FLB_SYSTEM_STRPTIME "Use strptime in system libc" Yes)
6868
option(FLB_STATIC_CONF "Build binary using static configuration")
6969
option(FLB_STREAM_PROCESSOR "Enable Stream Processor" Yes)
7070
option(FLB_CORO_STACK_SIZE "Set coroutine stack size")
71+
option(FLB_ICONV "Enable iconv string decoding" No)
7172

7273
# Metrics: Experimental Feature, disabled by default on 0.12 series
7374
# but enabled in the upcoming 0.13 release. Note that development
@@ -153,6 +154,7 @@ if(FLB_ALL)
153154
# Global
154155
set(FLB_DEBUG 1)
155156
set(FLB_TLS 1)
157+
set(FLB_ICONV 1)
156158

157159
# Input plugins
158160
set(FLB_IN_CPU 1)
@@ -182,6 +184,7 @@ if(FLB_ALL)
182184
set(FLB_OUT_STDOUT 1)
183185
set(FLB_OUT_LIB 1)
184186
set(FLB_OUT_FLOWCOUNTER 1)
187+
185188
endif()
186189

187190
if(FLB_DEV)
@@ -577,6 +580,67 @@ if(FLB_INOTIFY)
577580
endif()
578581
endif()
579582

583+
# iconv
584+
if(FLB_ICONV)
585+
586+
if(CMAKE_VERSION VERSION_LESS 3.11.0)
587+
message("cmake older than 3.11.0 .. no FindIconv module... testing here")
588+
if(NOT DEFINED Iconv_IS_BUILT_IN)
589+
if(DEFINED Iconv_INCLUDE_DIR AND NOT DEFINED Iconv_LIBRARY)
590+
check_c_source_compiles(
591+
"
592+
#include <stddef.h>
593+
#include <iconv.h>
594+
int main() {
595+
char *a, *b;
596+
size_t i, j;
597+
iconv_t ic;
598+
ic = iconv_open(\"to\", \"from\");
599+
iconv(ic, &a, &i, &b, &j);
600+
iconv_close(ic);
601+
}
602+
" Iconv_IS_BUILT_IN)
603+
endif()
604+
endif()
605+
if(NOT Iconv_IS_BUILT_IN)
606+
if(DEFINED Iconv_INCLUDE_DIR AND NOT DEFINED Iconv_LIBRARIES)
607+
set(CMAKE_REQUIRED_LIBRARIES "iconv")
608+
check_c_source_compiles(
609+
"
610+
#include <stddef.h>
611+
#include <iconv.h>
612+
int main() {
613+
char *a, *b;
614+
size_t i, j;
615+
iconv_t ic;
616+
ic = iconv_open(\"to\", \"from\");
617+
iconv(ic, &a, &i, &b, &j);
618+
iconv_close(ic);
619+
}
620+
" Iconv_FOUND)
621+
if(Iconv_FOUND)
622+
set(Iconv_LIBRARIES "iconv")
623+
endif()
624+
endif()
625+
endif()
626+
627+
else()
628+
include(FindIconv)
629+
endif()
630+
631+
if(Iconv_IS_BUILT_IN)
632+
message("Iconv_IS_BUILT_IN builtin is defined")
633+
FLB_DEFINITION(FLB_HAVE_ICONV)
634+
elseif(Iconv_LIBRARIES)
635+
message("Iconv_LIBRARIES defined '${Iconv_LIBRARIES}'")
636+
FLB_DEFINITION(FLB_HAVE_ICONV)
637+
else()
638+
message("FLB_ICONV defined iconv not given")
639+
set(FLB_ICONV NO)
640+
endif()
641+
642+
endif()
643+
580644
configure_file(
581645
"${PROJECT_SOURCE_DIR}/include/fluent-bit/flb_info.h.in"
582646
"${PROJECT_SOURCE_DIR}/include/fluent-bit/flb_info.h"

src/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ if(FLB_TLS)
7878
)
7979
endif()
8080

81+
# iconv
82+
if(FLB_ICONV)
83+
set(src
84+
${src}
85+
"flb_iconv.c"
86+
)
87+
if(NOT Iconv_IS_BUILT_IN)
88+
set(extra_libs
89+
${extra_libs}
90+
${Iconv_LIBRARIES}
91+
)
92+
endif()
93+
endif()
94+
8195
if(FLB_PROXY_GO)
8296
set(src
8397
${src}

0 commit comments

Comments
 (0)