Properly detect iconv features to compile
This commit is contained in:
+4
-1
@@ -13,14 +13,16 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -fsanitize=address")
|
|||||||
#
|
#
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
||||||
find_package(Cryptopp REQUIRED)
|
find_package(Cryptopp REQUIRED)
|
||||||
|
find_package(Iconv REQUIRED)
|
||||||
include(FindEXPAT)
|
include(FindEXPAT)
|
||||||
find_package(EXPAT REQUIRED)
|
find_package(EXPAT REQUIRED)
|
||||||
|
|
||||||
include_directories("src/")
|
include_directories("src/")
|
||||||
|
include_directories(${EXPAT_INCLUDE_DIRS})
|
||||||
|
include_directories(${ICONV_INCLUDE_DIR})
|
||||||
# the SYSTEM flag tells the compiler that we don't care about warnings
|
# the SYSTEM flag tells the compiler that we don't care about warnings
|
||||||
# coming from these headers.
|
# coming from these headers.
|
||||||
include_directories(SYSTEM ${CRYPTO++_INCLUDE_DIR})
|
include_directories(SYSTEM ${CRYPTO++_INCLUDE_DIR})
|
||||||
include_directories(SYSTEM ${EXPAT_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
#
|
#
|
||||||
## utils
|
## utils
|
||||||
@@ -28,6 +30,7 @@ include_directories(SYSTEM ${EXPAT_INCLUDE_DIRS})
|
|||||||
file(GLOB source_utils
|
file(GLOB source_utils
|
||||||
src/utils/*.[hc]pp)
|
src/utils/*.[hc]pp)
|
||||||
add_library(utils STATIC ${source_utils})
|
add_library(utils STATIC ${source_utils})
|
||||||
|
target_link_libraries(utils ${ICONV_LIBRARIES})
|
||||||
|
|
||||||
#
|
#
|
||||||
## network
|
## network
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# - Try to find Iconv
|
||||||
|
# Once done this will define
|
||||||
|
#
|
||||||
|
# ICONV_FOUND - system has Iconv
|
||||||
|
# ICONV_INCLUDE_DIR - the Iconv include directory
|
||||||
|
# ICONV_LIBRARIES - Link these to use Iconv
|
||||||
|
# ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const
|
||||||
|
#
|
||||||
|
include(CheckCXXSourceCompiles)
|
||||||
|
|
||||||
|
IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
|
||||||
|
# Already in cache, be silent
|
||||||
|
SET(ICONV_FIND_QUIETLY TRUE)
|
||||||
|
ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
|
||||||
|
|
||||||
|
FIND_PATH(ICONV_INCLUDE_DIR iconv.h)
|
||||||
|
|
||||||
|
FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c)
|
||||||
|
|
||||||
|
IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
|
||||||
|
SET(ICONV_FOUND TRUE)
|
||||||
|
ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
|
||||||
|
|
||||||
|
set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
|
||||||
|
IF(ICONV_FOUND)
|
||||||
|
check_cxx_source_compiles("
|
||||||
|
#include <iconv.h>
|
||||||
|
int main(){
|
||||||
|
iconv_t conv = 0;
|
||||||
|
const char* in = 0;
|
||||||
|
size_t ilen = 0;
|
||||||
|
char* out = 0;
|
||||||
|
size_t olen = 0;
|
||||||
|
iconv(conv, &in, &ilen, &out, &olen);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
" ICONV_SECOND_ARGUMENT_IS_CONST )
|
||||||
|
ENDIF(ICONV_FOUND)
|
||||||
|
set(CMAKE_REQUIRED_INCLUDES)
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES)
|
||||||
|
|
||||||
|
IF(ICONV_FOUND)
|
||||||
|
IF(NOT ICONV_FIND_QUIETLY)
|
||||||
|
MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
|
||||||
|
ENDIF(NOT ICONV_FIND_QUIETLY)
|
||||||
|
ELSE(ICONV_FOUND)
|
||||||
|
IF(Iconv_FIND_REQUIRED)
|
||||||
|
MESSAGE(FATAL_ERROR "Could not find Iconv")
|
||||||
|
ENDIF(Iconv_FIND_REQUIRED)
|
||||||
|
ENDIF(ICONV_FOUND)
|
||||||
|
|
||||||
|
MARK_AS_ADVANCED(
|
||||||
|
ICONV_INCLUDE_DIR
|
||||||
|
ICONV_LIBRARIES
|
||||||
|
ICONV_SECOND_ARGUMENT_IS_CONST
|
||||||
|
)
|
||||||
@@ -75,10 +75,15 @@ namespace utils
|
|||||||
// Make sure cd is always closed when we leave this function
|
// Make sure cd is always closed when we leave this function
|
||||||
ScopeGuard sg([&]{ iconv_close(cd); });
|
ScopeGuard sg([&]{ iconv_close(cd); });
|
||||||
|
|
||||||
// iconv will not attempt to modify this buffer, but it still requires
|
|
||||||
// a char**.
|
|
||||||
size_t inbytesleft = str.size();
|
size_t inbytesleft = str.size();
|
||||||
|
|
||||||
|
// iconv will not attempt to modify this buffer, but some plateform
|
||||||
|
// require a char** anyway
|
||||||
|
#ifdef ICONV_SECOND_ARGUMENT_IS_CONST
|
||||||
|
const char* inbuf_ptr = str.c_str();
|
||||||
|
#else
|
||||||
char* inbuf_ptr = const_cast<char*>(str.c_str());
|
char* inbuf_ptr = const_cast<char*>(str.c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
size_t outbytesleft = str.size() * 4;
|
size_t outbytesleft = str.size() * 4;
|
||||||
char* outbuf = new char[outbytesleft];
|
char* outbuf = new char[outbytesleft];
|
||||||
|
|||||||
Reference in New Issue
Block a user