2016-11-11 09:52:10 +03:00
|
|
|
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
|
2015-07-15 11:01:46 +03:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
2017-02-17 17:48:50 +03:00
|
|
|
subdirs(tests fuzzing)
|
2017-01-16 16:36:11 +03:00
|
|
|
|
2016-11-05 19:16:57 +03:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2016-11-05 17:18:03 +03:00
|
|
|
project(cJSON C)
|
|
|
|
|
2016-11-06 10:58:22 +03:00
|
|
|
set(PROJECT_VERSION_MAJOR 1)
|
2017-02-17 03:42:02 +03:00
|
|
|
set(PROJECT_VERSION_MINOR 3)
|
|
|
|
set(PROJECT_VERSION_PATCH 0)
|
2016-11-04 16:31:56 +03:00
|
|
|
set(CJSON_VERSION_SO 1)
|
2016-11-04 21:30:31 +03:00
|
|
|
set(CJSON_UTILS_VERSION_SO 1)
|
2016-11-06 10:58:22 +03:00
|
|
|
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
2015-07-15 11:01:46 +03:00
|
|
|
|
2017-02-07 16:51:29 +03:00
|
|
|
|
|
|
|
set(custom_compiler_flags)
|
|
|
|
|
|
|
|
include(CheckCCompilerFlag)
|
2016-11-26 08:57:12 +03:00
|
|
|
option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags for Clang and GCC" ON)
|
2016-11-15 16:21:57 +03:00
|
|
|
if (ENABLE_CUSTOM_COMPILER_FLAGS)
|
2017-02-07 16:51:29 +03:00
|
|
|
list(APPEND custom_compiler_flags
|
|
|
|
-std=c89
|
|
|
|
-pedantic
|
|
|
|
-Wall
|
|
|
|
-Wextra
|
|
|
|
-Werror
|
|
|
|
-Wstrict-prototypes
|
|
|
|
-Wwrite-strings
|
|
|
|
-Wshadow
|
|
|
|
-Winit-self
|
|
|
|
-Wcast-align
|
|
|
|
-Wformat=2
|
|
|
|
-Wmissing-prototypes
|
|
|
|
-Wstrict-overflow=2
|
|
|
|
-Wcast-qual
|
|
|
|
-Wundef
|
|
|
|
-Wswitch-default
|
|
|
|
-Wconversion
|
2017-02-07 22:20:56 +03:00
|
|
|
-Wc++-compat
|
2017-02-07 16:51:29 +03:00
|
|
|
-fstack-protector-strong
|
2017-03-01 10:36:34 +03:00
|
|
|
-Wcomma
|
2017-02-07 16:51:29 +03:00
|
|
|
)
|
2016-11-05 17:24:24 +03:00
|
|
|
endif()
|
2016-11-04 20:51:31 +03:00
|
|
|
|
2017-02-07 17:07:54 +03:00
|
|
|
option(ENABLE_SANITIZERS "Enables AddressSanitizer and UndefinedBehaviorSanitizer." OFF)
|
|
|
|
if (ENABLE_SANITIZERS)
|
|
|
|
list(APPEND custom_compiler_flags
|
|
|
|
-fno-omit-frame-pointer
|
|
|
|
-fsanitize=address
|
|
|
|
-fsanitize=undefined
|
|
|
|
-fsanitize=float-divide-by-zero
|
|
|
|
-fsanitize=float-cast-overflow
|
|
|
|
-fsanitize-address-use-after-scope
|
|
|
|
-fsanitize=integer
|
|
|
|
-01
|
|
|
|
-fno-sanitize-recover
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2017-02-07 16:51:29 +03:00
|
|
|
# apply custom compiler flags
|
|
|
|
foreach(compiler_flag ${custom_compiler_flags})
|
2017-02-07 22:20:56 +03:00
|
|
|
#remove problematic characters
|
|
|
|
string(REGEX REPLACE "[^a-zA-Z0-9]" "" current_variable ${compiler_flag})
|
|
|
|
|
|
|
|
CHECK_C_COMPILER_FLAG(${compiler_flag} "FLAG_SUPPORTED_${current_variable}")
|
|
|
|
if (FLAG_SUPPORTED_${current_variable})
|
2017-02-07 16:51:29 +03:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${compiler_flag}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2016-10-18 03:12:12 +03:00
|
|
|
#variables for pkg-config
|
2016-11-05 18:52:40 +03:00
|
|
|
set(prefix "${CMAKE_INSTALL_PREFIX}")
|
2016-11-06 10:54:43 +03:00
|
|
|
set(libdir "${CMAKE_INSTALL_LIBDIR}")
|
2016-11-06 10:58:22 +03:00
|
|
|
set(version "${PROJECT_VERSION}")
|
2016-11-06 10:54:43 +03:00
|
|
|
set(includedir "${CMAKE_INSTALL_INCLUDEDIR}")
|
2016-10-18 03:12:12 +03:00
|
|
|
|
2016-11-05 12:41:24 +03:00
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
2016-11-06 20:13:38 +03:00
|
|
|
option(ENABLE_TARGET_EXPORT "Enable exporting of CMake targets. Disable when it causes problems!" ON)
|
2016-11-05 12:41:24 +03:00
|
|
|
|
2016-11-04 20:38:30 +03:00
|
|
|
#cJSON
|
2016-11-04 20:46:41 +03:00
|
|
|
set(CJSON_LIB cjson)
|
2016-11-04 20:38:30 +03:00
|
|
|
|
2015-07-15 11:01:46 +03:00
|
|
|
file(GLOB HEADERS cJSON.h)
|
|
|
|
set(SOURCES cJSON.c)
|
|
|
|
|
2016-11-05 18:52:40 +03:00
|
|
|
add_library("${CJSON_LIB}" "${HEADERS}" "${SOURCES}")
|
2015-08-20 06:03:08 +03:00
|
|
|
if (NOT WIN32)
|
2016-11-05 18:52:40 +03:00
|
|
|
target_link_libraries("${CJSON_LIB}" m)
|
2015-08-20 06:03:08 +03:00
|
|
|
endif()
|
2015-07-15 11:01:46 +03:00
|
|
|
|
2016-11-05 18:42:35 +03:00
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libcjson.pc.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY)
|
2016-10-18 03:12:12 +03:00
|
|
|
|
2016-11-05 19:16:57 +03:00
|
|
|
install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
|
|
|
|
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
2016-11-06 11:35:53 +03:00
|
|
|
install(TARGETS "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_LIB}")
|
2016-11-06 20:13:38 +03:00
|
|
|
if(ENABLE_TARGET_EXPORT)
|
2016-11-15 16:21:30 +03:00
|
|
|
# export library information for CMake projects
|
|
|
|
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
|
2016-11-06 20:13:38 +03:00
|
|
|
endif()
|
2015-07-28 00:33:17 +03:00
|
|
|
|
2016-11-05 18:52:40 +03:00
|
|
|
set_target_properties("${CJSON_LIB}"
|
2016-11-04 20:50:51 +03:00
|
|
|
PROPERTIES
|
2016-11-05 18:52:40 +03:00
|
|
|
SOVERSION "${CJSON_VERSION_SO}"
|
2016-11-06 10:58:22 +03:00
|
|
|
VERSION "${PROJECT_VERSION}")
|
2016-11-04 20:50:51 +03:00
|
|
|
|
2016-11-04 20:38:30 +03:00
|
|
|
#cJSON_Utils
|
2016-11-05 18:20:55 +03:00
|
|
|
option(ENABLE_CJSON_UTILS "Enable building the cJSON_Utils library." OFF)
|
|
|
|
if(ENABLE_CJSON_UTILS)
|
|
|
|
set(CJSON_UTILS_LIB cjson_utils)
|
2015-07-28 00:33:17 +03:00
|
|
|
|
2016-11-05 18:20:55 +03:00
|
|
|
file(GLOB HEADERS_UTILS cJSON_Utils.h)
|
|
|
|
set(SOURCES_UTILS cJSON_Utils.c)
|
2015-07-28 00:33:17 +03:00
|
|
|
|
2016-11-05 18:52:40 +03:00
|
|
|
add_library("${CJSON_UTILS_LIB}" "${HEADERS_UTILS}" "${SOURCES_UTILS}")
|
|
|
|
target_link_libraries("${CJSON_UTILS_LIB}" "${CJSON_LIB}")
|
2015-07-28 00:33:17 +03:00
|
|
|
|
2016-11-05 18:42:35 +03:00
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libcjson_utils.pc.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY)
|
2016-11-05 11:57:14 +03:00
|
|
|
|
2016-11-06 11:35:53 +03:00
|
|
|
install(TARGETS "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_UTILS_LIB}")
|
2016-11-05 19:16:57 +03:00
|
|
|
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
|
|
|
|
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
2016-11-06 20:13:38 +03:00
|
|
|
if(ENABLE_TARGET_EXPORT)
|
|
|
|
# export library information for CMake projects
|
|
|
|
install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
|
|
|
|
endif()
|
2015-07-15 11:01:46 +03:00
|
|
|
|
2016-11-05 18:52:40 +03:00
|
|
|
set_target_properties("${CJSON_UTILS_LIB}"
|
2016-11-05 18:20:55 +03:00
|
|
|
PROPERTIES
|
2016-11-05 18:52:40 +03:00
|
|
|
SOVERSION "${CJSON_UTILS_VERSION_SO}"
|
2016-11-06 10:58:22 +03:00
|
|
|
VERSION "${PROJECT_VERSION}")
|
2016-11-05 18:20:55 +03:00
|
|
|
endif()
|
2016-11-04 20:50:51 +03:00
|
|
|
|
2016-11-04 21:59:04 +03:00
|
|
|
# create the other package config files
|
|
|
|
configure_file(
|
2016-11-15 16:21:30 +03:00
|
|
|
cJSONConfig.cmake.in
|
|
|
|
${PROJECT_BINARY_DIR}/cJSONConfig.cmake @ONLY)
|
2016-11-04 21:59:04 +03:00
|
|
|
configure_file(
|
2016-11-15 16:21:30 +03:00
|
|
|
cJSONConfigVersion.cmake.in
|
|
|
|
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake @ONLY)
|
2016-11-04 21:59:04 +03:00
|
|
|
|
|
|
|
# Install package config files
|
|
|
|
install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
|
2016-11-15 16:21:30 +03:00
|
|
|
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
|
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
|
2016-11-04 21:59:04 +03:00
|
|
|
|
2016-11-14 15:36:04 +03:00
|
|
|
option(ENABLE_CJSON_TEST "Enable building cJSON test" ON)
|
2015-07-15 11:01:46 +03:00
|
|
|
if(ENABLE_CJSON_TEST)
|
2017-01-16 16:52:01 +03:00
|
|
|
enable_testing()
|
|
|
|
|
2016-11-04 20:40:23 +03:00
|
|
|
set(TEST_CJSON cJSON_test)
|
2016-11-05 18:52:40 +03:00
|
|
|
add_executable("${TEST_CJSON}" test.c)
|
|
|
|
target_link_libraries("${TEST_CJSON}" "${CJSON_LIB}")
|
2015-07-28 00:33:17 +03:00
|
|
|
|
2016-11-05 18:20:55 +03:00
|
|
|
if(ENABLE_CJSON_UTILS)
|
|
|
|
set(TEST_CJSON_UTILS cJSON_test_utils)
|
2016-11-05 18:52:40 +03:00
|
|
|
add_executable("${TEST_CJSON_UTILS}" test_utils.c)
|
|
|
|
target_link_libraries("${TEST_CJSON_UTILS}" "${CJSON_UTILS_LIB}")
|
2016-11-05 18:20:55 +03:00
|
|
|
endif()
|
2015-07-15 11:01:46 +03:00
|
|
|
endif()
|