@@ -48,7 +48,8 @@ option(BUILD_SHARED_LIBS "Default to building shared libraries" ON)
# Enable or disable features. By default, all features are turned off.
option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed" OFF)
option(ENABLE_THREADING "Enable partial threading support." OFF)
option(HAS_GNU_WARNING_LONG "Define if .gnu.warning accepts long strings." OFF)
option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors" OFF)
option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function" OFF)
if (UNIX OR MINGW OR CYGWIN)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
@@ -70,6 +71,7 @@ check_include_file(strings.h HAVE_STRINGS_H)
check_include_file(string.h HAVE_STRING_H)
check_include_file(syslog.h HAVE_SYSLOG_H)
check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
check_include_file(unistd.h HAVE_UNISTD_H)
@@ -147,12 +149,21 @@ if (MSVC)
endif()
endif()
check_type_size(int SIZEOF_INT)
check_type_size(int64_t SIZEOF_INT64_T)
check_type_size(long SIZEOF_LONG)
check_type_size("long long" SIZEOF_LONG_LONG)
check_type_size("size_t" SIZEOF_SIZE_T)
check_c_source_compiles(
[=[
extern void json_object_get();
__asm__(".section .gnu.json_object_get\\n\\t.ascii \\"Please link against libjson-c instead of libjson\\"\\n\\t.text");
int main(int c, char *v) { return 0;}
]=]
HAS_GNU_WARNING_LONG)
check_c_source_compiles(
"int main() { int i, x = 0; i = __sync_add_and_fetch(&x,1); return x; }"
HAVE_ATOMIC_BUILTINS)
@@ -180,8 +191,15 @@ message(STATUS "Written ${PROJECT_BINARY_DIR}/json_config.h")
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
# There's a catch here.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
if ("${DISABLE_WERROR}" STREQUAL "OFF")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-qual")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=deprecated-declarations")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wwrite-strings")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")
add_definitions(-D_GNU_SOURCE)
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
@@ -195,6 +213,30 @@ elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4701")
endif()
if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"))
check_c_source_compiles(
[=[
/* uClibc toolchains without threading barf when _REENTRANT is defined */
#define _REENTRANT 1
#include <sys/types.h>
int main ()
{
return 0;
}
]=]
REENTRANT_WORKS
)
if (REENTRANT_WORKS)
add_compile_options("-D_REENTRANT")
endif()
if (DISABLE_BSYMBOLIC STREQUAL "OFF")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKED_FLAGS} -Wl,-Bsymbolic-functions")
# XXX need cmake>=3.13 for this:
#add_link_options("-Wl,-Bsymbolic-functions")
endif()
endif()
if ($ENV{VALGRIND})
# Build so that valgrind doesn't complain about linkhash.c
add_definitions(-DVALGRIND=1)