CMakeLists.txt 2.3 KB
Newer Older
A
Anton Sergeev 已提交
1 2
cmake_minimum_required(VERSION 2.8)

M
Max Bruckner 已提交
3 4
project(cJSON C)

M
Max Bruckner 已提交
5 6 7 8
set(CJSON_VERSION_MAJOR 1)
set(CJSON_VERSION_MINOR 0)
set(CJSON_VERSION_PATCH 0)
set(CJSON_VERSION_SO 1)
9
set(CJSON_UTILS_VERSION_SO 1)
M
Max Bruckner 已提交
10
set(CJSON_VERSION "${CJSON_VERSION_MAJOR}.${CJSON_VERSION_MINOR}.${CJSON_VERSION_PATCH}")
A
Anton Sergeev 已提交
11

12 13 14
if(("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang"))
    add_compile_options(-ansi -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings)
endif()
M
Max Bruckner 已提交
15

16 17 18
#variables for pkg-config
set(prefix ${CMAKE_INSTALL_PREFIX})
set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
M
Max Bruckner 已提交
19
set(version ${CJSON_VERSION})
20

21 22
option(BUILD_SHARED_LIBS "Build shared libraries" ON)

M
Max Bruckner 已提交
23
#cJSON
24
set(CJSON_LIB cjson)
M
Max Bruckner 已提交
25

A
Anton Sergeev 已提交
26 27 28
file(GLOB HEADERS cJSON.h)
set(SOURCES cJSON.c)

29
add_library(${CJSON_LIB} ${HEADERS} ${SOURCES})
30
if (NOT WIN32)
31
    target_link_libraries(${CJSON_LIB} m)
32
endif()
A
Anton Sergeev 已提交
33

34 35 36
configure_file("${cJSON_SOURCE_DIR}/libcjson.pc.in"
    "${cJSON_BINARY_DIR}/libcjson.pc" @ONLY)

37 38
install(TARGETS ${CJSON_LIB} DESTINATION lib${LIB_SUFFIX})
install(FILES cJSON.h DESTINATION include/cjson)
39
install (FILES ${cJSON_BINARY_DIR}/libcjson.pc DESTINATION lib/pkgconfig)
40

M
Max Bruckner 已提交
41 42 43 44 45
set_target_properties(${CJSON_LIB}
    PROPERTIES
        SOVERSION ${CJSON_VERSION_SO}
        VERSION ${CJSON_VERSION})

M
Max Bruckner 已提交
46
#cJSON_Utils
47
set(CJSON_UTILS_LIB cjson_utils)
48 49 50 51

file(GLOB HEADERS_UTILS cJSON_Utils.h)
set(SOURCES_UTILS cJSON_Utils.c)

52 53
add_library(${CJSON_UTILS_LIB} ${HEADERS_UTILS} ${SOURCES_UTILS})
target_link_libraries(${CJSON_UTILS_LIB} ${CJSON_LIB})
54

M
Max Bruckner 已提交
55 56
configure_file("${cJSON_SOURCE_DIR}/libcjson_utils.pc.in"
    "${cJSON_BINARY_DIR}/libcjson_utils.pc" @ONLY)
M
Max Bruckner 已提交
57

58
install(TARGETS ${CJSON_UTILS_LIB} DESTINATION lib${LIB_SUFFIX})
59
install(FILES cJSON_Utils.h DESTINATION include/cjson)
M
Max Bruckner 已提交
60
install (FILES ${cJSON_BINARY_DIR}/libcjson.pc DESTINATION lib/pkgconfig)
A
Anton Sergeev 已提交
61

M
Max Bruckner 已提交
62 63
set_target_properties(${CJSON_UTILS_LIB}
    PROPERTIES
64
        SOVERSION ${CJSON_UTILS_VERSION_SO}
M
Max Bruckner 已提交
65 66
        VERSION ${CJSON_VERSION})

M
Max Bruckner 已提交
67
option(ENABLE_CJSON_TEST "Enable building cJSON test" ON)
A
Anton Sergeev 已提交
68
if(ENABLE_CJSON_TEST)
M
Max Bruckner 已提交
69 70
    set(TEST_CJSON cJSON_test)
    add_executable(${TEST_CJSON} test.c)
71
    target_link_libraries(${TEST_CJSON} ${CJSON_LIB})
72

M
Max Bruckner 已提交
73 74
    set(TEST_CJSON_UTILS cJSON_test_utils)
    add_executable(${TEST_CJSON_UTILS} test_utils.c)
75
    target_link_libraries(${TEST_CJSON_UTILS} ${CJSON_UTILS_LIB})
A
Anton Sergeev 已提交
76
endif()