From: Eric Haszlakiewicz Date: Wed, 4 Oct 2017 02:50:29 +0000 (-0400) Subject: Issue #173, follow up to using strtoll to allow this to work on older Windows environ... X-Git-Tag: json-c-0.13-20171207~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=579f0746f0f0143c2895855d25617a9bacc361f8;p=thirdparty%2Fjson-c.git Issue #173, follow up to using strtoll to allow this to work on older Windows environments: Use cmake to generate config.h from config.h.win32, including checking for strtoll with cmake, or fall back to _strtoi64 for older MSVC's. Also, add a few missing files to the list of sources to build. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fa86443..89cf4330 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,13 +3,27 @@ cmake_minimum_required(VERSION 2.8.7) project(json-c) +include(CheckSymbolExists) + +check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL) + +set(cmake_strtoll "strtoll") +if (NOT HAVE_STRTOLL) + # Use _strtoi64 if strtoll is not available. + check_symbol_exists(_strtoi64 stdlib.h have_strtoi64) + if (have_strtoi64) + set(HAVE_STRTOLL 1) + set(cmake_strtoll "_strtoi64") + # could do the same for strtoull, if needed + endif () +endif () + + + if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100 /wd4996 /wd4244 /wd4706 /wd4702 /wd4127 /wd4701") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100 /wd4996 /wd4244 /wd4706 /wd4702 /wd4127 /wd4701") - file(COPY ./config.h.win32 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) - file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/include/config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/config.h) - file(COPY ./json_config.h.win32 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) - file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h) + set(cmake_create_config 1) elseif(MINGW) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -D_GNU_SOURCE=1") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -D_GNU_SOURCE=1") @@ -20,10 +34,7 @@ elseif(MINGW) file(COPY ./config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) file(COPY ./json_config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) else() - file(COPY ./config.h.win32 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) - file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/include/config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/config.h) - file(COPY ./json_config.h.win32 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) - file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h) + set(cmake_create_config 1) endif() elseif(UNIX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") @@ -35,6 +46,13 @@ elseif(UNIX) file(COPY ./json_config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) endif() +if (cmake_create_config) + file(REMOVE ./config.h) # make sure any stale one is gone + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/config.h) + file(COPY ./json_config.h.win32 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) + file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h) +endif () + include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) set(JSON_C_PUBLIC_HEADERS @@ -67,13 +85,15 @@ set(JSON_C_HEADERS set(JSON_C_SOURCES ./arraylist.c ./debug.c + ./json_c_version.c ./json_object.c + ./json_object_iterator.c ./json_pointer.c ./json_tokener.c ./json_util.c + ./json_visit.c ./linkhash.c ./printbuf.c - ./strerror_override.c ./random_seed.c ./strerror_override.c ) diff --git a/config.h.win32 b/config.h.win32 index 2a70a9cc..3e8b2182 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -113,6 +113,9 @@ #undef HAVE_STRNCASECMP #endif +#cmakedefine HAVE_STRTOLL +#cmakedefine strtoll @cmake_strtoll@ + /* Define to 1 if you have the header file. */ #undef HAVE_SYSLOG_H