• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.1.2)
2    #-Werror=* was introduced -after- GCC 4.1.2
3    add_compile_options("-Werror=strict-aliasing")
4endif()
5
6include(CheckIncludeFileCXX)
7include(CheckTypeSize)
8include(CheckStructHasMember)
9include(CheckCXXSymbolExists)
10
11check_include_file_cxx(clocale HAVE_CLOCALE)
12check_cxx_symbol_exists(localeconv clocale HAVE_LOCALECONV)
13
14if(CMAKE_VERSION VERSION_LESS 3.0.0)
15    # The "LANGUAGE CXX" parameter is not supported in CMake versions below 3,
16    # so the C compiler and header has to be used.
17    check_include_file(locale.h HAVE_LOCALE_H)
18    set(CMAKE_EXTRA_INCLUDE_FILES locale.h)
19    check_type_size("struct lconv" LCONV_SIZE)
20    unset(CMAKE_EXTRA_INCLUDE_FILES)
21    check_struct_has_member("struct lconv" decimal_point locale.h HAVE_DECIMAL_POINT)
22else()
23    set(CMAKE_EXTRA_INCLUDE_FILES clocale)
24    check_type_size(lconv LCONV_SIZE LANGUAGE CXX)
25    unset(CMAKE_EXTRA_INCLUDE_FILES)
26    check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX)
27endif()
28
29if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV))
30    message(WARNING "Locale functionality is not supported")
31    if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
32        add_compile_definitions(JSONCPP_NO_LOCALE_SUPPORT)
33    else()
34        add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT)
35    endif()
36endif()
37
38set(JSONCPP_INCLUDE_DIR ../../include)
39
40set(PUBLIC_HEADERS
41    ${JSONCPP_INCLUDE_DIR}/json/config.h
42    ${JSONCPP_INCLUDE_DIR}/json/forwards.h
43    ${JSONCPP_INCLUDE_DIR}/json/json_features.h
44    ${JSONCPP_INCLUDE_DIR}/json/value.h
45    ${JSONCPP_INCLUDE_DIR}/json/reader.h
46    ${JSONCPP_INCLUDE_DIR}/json/version.h
47    ${JSONCPP_INCLUDE_DIR}/json/writer.h
48    ${JSONCPP_INCLUDE_DIR}/json/assertions.h
49)
50
51source_group("Public API" FILES ${PUBLIC_HEADERS})
52
53set(jsoncpp_sources
54    json_tool.h
55    json_reader.cpp
56    json_valueiterator.inl
57    json_value.cpp
58    json_writer.cpp
59)
60
61# Install instructions for this target
62if(JSONCPP_WITH_CMAKE_PACKAGE)
63    set(INSTALL_EXPORT EXPORT jsoncpp)
64else()
65    set(INSTALL_EXPORT)
66endif()
67
68
69if(BUILD_SHARED_LIBS)
70    if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
71        add_compile_definitions(JSON_DLL_BUILD)
72    else()
73        add_definitions(-DJSON_DLL_BUILD)
74    endif()
75endif()
76
77add_library(jsoncpp_lib ${PUBLIC_HEADERS} ${jsoncpp_sources})
78set_target_properties( jsoncpp_lib PROPERTIES
79    OUTPUT_NAME jsoncpp
80    VERSION ${JSONCPP_VERSION}
81    SOVERSION ${JSONCPP_SOVERSION}
82    POSITION_INDEPENDENT_CODE ON
83)
84
85# Set library's runtime search path on OSX
86if(APPLE)
87    set_target_properties(jsoncpp_lib PROPERTIES INSTALL_RPATH "@loader_path/.")
88endif()
89
90# Specify compiler features required when compiling a given target.
91# See https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES
92# for complete list of features available
93if(CMAKE_CXX_STANDARD EQUAL "11")
94target_compile_features(jsoncpp_lib PUBLIC
95        cxx_std_11 # Compiler mode is aware of C++ 11.
96        #MSVC 1900 cxx_alignas # Alignment control alignas, as defined in N2341.
97        #MSVC 1900 cxx_alignof # Alignment control alignof, as defined in N2341.
98        #MSVC 1900 cxx_attributes # Generic attributes, as defined in N2761.
99        cxx_auto_type # Automatic type deduction, as defined in N1984.
100        #MSVC 1900 cxx_constexpr # Constant expressions, as defined in N2235.
101        cxx_decltype # Decltype, as defined in N2343.
102        cxx_default_function_template_args # Default template arguments for function templates, as defined in DR226
103        cxx_defaulted_functions # Defaulted functions, as defined in N2346.
104        #MSVC 1900 cxx_defaulted_move_initializers # Defaulted move initializers, as defined in N3053.
105        cxx_delegating_constructors # Delegating constructors, as defined in N1986.
106        #MSVC 1900 cxx_deleted_functions # Deleted functions, as defined in N2346.
107        cxx_enum_forward_declarations # Enum forward declarations, as defined in N2764.
108        cxx_explicit_conversions # Explicit conversion operators, as defined in N2437.
109        cxx_extended_friend_declarations # Extended friend declarations, as defined in N1791.
110        cxx_extern_templates # Extern templates, as defined in N1987.
111        cxx_final # Override control final keyword, as defined in N2928, N3206 and N3272.
112        #MSVC 1900 cxx_func_identifier # Predefined __func__ identifier, as defined in N2340.
113        #MSVC 1900 cxx_generalized_initializers # Initializer lists, as defined in N2672.
114        #MSVC 1900 cxx_inheriting_constructors # Inheriting constructors, as defined in N2540.
115        #MSVC 1900 cxx_inline_namespaces # Inline namespaces, as defined in N2535.
116        cxx_lambdas # Lambda functions, as defined in N2927.
117        #MSVC 1900 cxx_local_type_template_args # Local and unnamed types as template arguments, as defined in N2657.
118        cxx_long_long_type # long long type, as defined in N1811.
119        #MSVC 1900 cxx_noexcept # Exception specifications, as defined in N3050.
120        #MSVC 1900 cxx_nonstatic_member_init # Non-static data member initialization, as defined in N2756.
121        cxx_nullptr # Null pointer, as defined in N2431.
122        cxx_override # Override control override keyword, as defined in N2928, N3206 and N3272.
123        cxx_range_for # Range-based for, as defined in N2930.
124        cxx_raw_string_literals # Raw string literals, as defined in N2442.
125        #MSVC 1900 cxx_reference_qualified_functions # Reference qualified functions, as defined in N2439.
126        cxx_right_angle_brackets # Right angle bracket parsing, as defined in N1757.
127        cxx_rvalue_references # R-value references, as defined in N2118.
128        #MSVC 1900 cxx_sizeof_member # Size of non-static data members, as defined in N2253.
129        cxx_static_assert # Static assert, as defined in N1720.
130        cxx_strong_enums # Strongly typed enums, as defined in N2347.
131        #MSVC 1900 cxx_thread_local # Thread-local variables, as defined in N2659.
132        cxx_trailing_return_types # Automatic function return type, as defined in N2541.
133        #MSVC 1900 cxx_unicode_literals # Unicode string literals, as defined in N2442.
134        cxx_uniform_initialization # Uniform initialization, as defined in N2640.
135        #MSVC 1900 cxx_unrestricted_unions # Unrestricted unions, as defined in N2544.
136        #MSVC 1900 cxx_user_literals # User-defined literals, as defined in N2765.
137        cxx_variadic_macros # Variadic macros, as defined in N1653.
138        cxx_variadic_templates # Variadic templates, as defined in N2242.
139)
140else()
141    set(CMAKE_CXX_STANDARD 98)
142    target_compile_features(jsoncpp_lib PUBLIC)
143endif()
144
145install(TARGETS jsoncpp_lib ${INSTALL_EXPORT}
146    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
147    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
148    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
149)
150
151if(NOT CMAKE_VERSION VERSION_LESS 2.8.11)
152    target_include_directories(jsoncpp_lib PUBLIC
153        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
154        $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
155        $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/json>
156    )
157endif()
158