Debian Codegraph @

src/lib_json/CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 if(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")
4 endif()
5
6 include(CheckIncludeFileCXX)
7 include(CheckTypeSize)
8 include(CheckStructHasMember)
9 include(CheckCXXSymbolExists)
10 include(CheckCXXSourceCompiles)
11
12 check_include_file_cxx(clocale HAVE_CLOCALE)
13 check_cxx_symbol_exists(localeconv clocale HAVE_LOCALECONV)
14
15 set(CMAKE_EXTRA_INCLUDE_FILES clocale)
16 check_type_size(lconv LCONV_SIZE LANGUAGE CXX)
17 unset(CMAKE_EXTRA_INCLUDE_FILES)
18 check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX)
19
20 if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV))
21 message(WARNING "Locale functionality is not supported")
22 if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
23 add_compile_definitions(JSONCPP_NO_LOCALE_SUPPORT)
24 else()
25 add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT)
26 endif()
27 endif()
28
29 check_cxx_source_compiles(
30 "#include <string_view>
31 int main() { std::string_view sv; return 0; }"
32 JSONCPP_HAS_STRING_VIEW)
33
34 set(JSONCPP_INCLUDE_DIR ../../include)
35
36 set(PUBLIC_HEADERS
37 ${JSONCPP_INCLUDE_DIR}/json/config.h
38 ${JSONCPP_INCLUDE_DIR}/json/forwards.h
39 ${JSONCPP_INCLUDE_DIR}/json/json_features.h
40 ${JSONCPP_INCLUDE_DIR}/json/value.h
41 ${JSONCPP_INCLUDE_DIR}/json/reader.h
42 ${JSONCPP_INCLUDE_DIR}/json/version.h
43 ${JSONCPP_INCLUDE_DIR}/json/writer.h
44 ${JSONCPP_INCLUDE_DIR}/json/assertions.h
45 )
46
47 source_group("Public API" FILES ${PUBLIC_HEADERS})
48
49 set(JSONCPP_SOURCES
50 json_tool.h
51 json_reader.cpp
52 json_valueiterator.inl
53 json_value.cpp
54 json_writer.cpp
55 )
56
57 # Install instructions for this target
58 if(JSONCPP_WITH_CMAKE_PACKAGE)
59 set(INSTALL_EXPORT EXPORT jsoncpp)
60 else()
61 set(INSTALL_EXPORT)
62 endif()
63
64 # Specify compiler features required when compiling a given target.
65 # See https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES
66 # for complete list of features available
67 list(APPEND REQUIRED_FEATURES
68 cxx_std_11 # Compiler mode is aware of C++ 11.
69 #MSVC 1900 cxx_alignas # Alignment control alignas, as defined in N2341.
70 #MSVC 1900 cxx_alignof # Alignment control alignof, as defined in N2341.
71 #MSVC 1900 cxx_attributes # Generic attributes, as defined in N2761.
72 cxx_auto_type # Automatic type deduction, as defined in N1984.
73 #MSVC 1900 cxx_constexpr # Constant expressions, as defined in N2235.
74 cxx_decltype # Decltype, as defined in N2343.
75 cxx_default_function_template_args # Default template arguments for function templates, as defined in DR226
76 cxx_defaulted_functions # Defaulted functions, as defined in N2346.
77 #MSVC 1900 cxx_defaulted_move_initializers # Defaulted move initializers, as defined in N3053.
78 cxx_delegating_constructors # Delegating constructors, as defined in N1986.
79 #MSVC 1900 cxx_deleted_functions # Deleted functions, as defined in N2346.
80 cxx_enum_forward_declarations # Enum forward declarations, as defined in N2764.
81 cxx_explicit_conversions # Explicit conversion operators, as defined in N2437.
82 cxx_extended_friend_declarations # Extended friend declarations, as defined in N1791.
83 cxx_extern_templates # Extern templates, as defined in N1987.
84 cxx_final # Override control final keyword, as defined in N2928, N3206 and N3272.
85 #MSVC 1900 cxx_func_identifier # Predefined __func__ identifier, as defined in N2340.
86 #MSVC 1900 cxx_generalized_initializers # Initializer lists, as defined in N2672.
87 #MSVC 1900 cxx_inheriting_constructors # Inheriting constructors, as defined in N2540.
88 #MSVC 1900 cxx_inline_namespaces # Inline namespaces, as defined in N2535.
89 cxx_lambdas # Lambda functions, as defined in N2927.
90 #MSVC 1900 cxx_local_type_template_args # Local and unnamed types as template arguments, as defined in N2657.
91 cxx_long_long_type # long long type, as defined in N1811.
92 #MSVC 1900 cxx_noexcept # Exception specifications, as defined in N3050.
93 #MSVC 1900 cxx_nonstatic_member_init # Non-static data member initialization, as defined in N2756.
94 cxx_nullptr # Null pointer, as defined in N2431.
95 cxx_override # Override control override keyword, as defined in N2928, N3206 and N3272.
96 cxx_range_for # Range-based for, as defined in N2930.
97 cxx_raw_string_literals # Raw string literals, as defined in N2442.
98 #MSVC 1900 cxx_reference_qualified_functions # Reference qualified functions, as defined in N2439.
99 cxx_right_angle_brackets # Right angle bracket parsing, as defined in N1757.
100 cxx_rvalue_references # R-value references, as defined in N2118.
101 #MSVC 1900 cxx_sizeof_member # Size of non-static data members, as defined in N2253.
102 cxx_static_assert # Static assert, as defined in N1720.
103 cxx_strong_enums # Strongly typed enums, as defined in N2347.
104 #MSVC 1900 cxx_thread_local # Thread-local variables, as defined in N2659.
105 cxx_trailing_return_types # Automatic function return type, as defined in N2541.
106 #MSVC 1900 cxx_unicode_literals # Unicode string literals, as defined in N2442.
107 cxx_uniform_initialization # Uniform initialization, as defined in N2640.
108 #MSVC 1900 cxx_unrestricted_unions # Unrestricted unions, as defined in N2544.
109 #MSVC 1900 cxx_user_literals # User-defined literals, as defined in N2765.
110 cxx_variadic_macros # Variadic macros, as defined in N1653.
111 cxx_variadic_templates # Variadic templates, as defined in N2242.
112 )
113
114
115 if(BUILD_SHARED_LIBS)
116 set(SHARED_LIB ${PROJECT_NAME}_lib)
117 add_library(${SHARED_LIB} SHARED ${PUBLIC_HEADERS} ${JSONCPP_SOURCES})
118 set_target_properties(${SHARED_LIB} PROPERTIES
119 OUTPUT_NAME jsoncpp
120 VERSION ${PROJECT_VERSION}
121 SOVERSION ${PROJECT_SOVERSION}
122 POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
123 )
124
125 target_compile_definitions(${SHARED_LIB} PRIVATE JSON_DLL_BUILD)
126
127 # Set library's runtime search path on OSX
128 if(APPLE)
129 set_target_properties(${SHARED_LIB} PROPERTIES INSTALL_RPATH "@loader_path/.")
130 endif()
131
132 target_compile_features(${SHARED_LIB} PUBLIC ${REQUIRED_FEATURES})
133
134 if(JSONCPP_HAS_STRING_VIEW)
135 target_compile_definitions(${SHARED_LIB} PUBLIC JSONCPP_HAS_STRING_VIEW=1)
136 endif()
137
138 target_include_directories(${SHARED_LIB} PUBLIC
139 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
140 $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
141 )
142
143 list(APPEND CMAKE_TARGETS ${SHARED_LIB})
144 endif()
145
146 if(BUILD_STATIC_LIBS)
147 set(STATIC_LIB ${PROJECT_NAME}_static)
148 add_library(${STATIC_LIB} STATIC ${PUBLIC_HEADERS} ${JSONCPP_SOURCES})
149
150 # avoid name clashes on windows as the shared import lib is also named jsoncpp.lib
151 if(NOT DEFINED STATIC_SUFFIX AND BUILD_SHARED_LIBS)
152 if (MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC"))
153 set(STATIC_SUFFIX "_static")
154 else()
155 set(STATIC_SUFFIX "")
156 endif()
157 endif()
158
159 set_target_properties(${STATIC_LIB} PROPERTIES
160 OUTPUT_NAME jsoncpp${STATIC_SUFFIX}
161 VERSION ${PROJECT_VERSION}
162 )
163
164 # Set library's runtime search path on OSX
165 if(APPLE)
166 set_target_properties(${STATIC_LIB} PROPERTIES INSTALL_RPATH "@loader_path/.")
167 endif()
168
169 target_compile_features(${STATIC_LIB} PUBLIC ${REQUIRED_FEATURES})
170
171 if(JSONCPP_HAS_STRING_VIEW)
172 target_compile_definitions(${STATIC_LIB} PUBLIC JSONCPP_HAS_STRING_VIEW=1)
173 endif()
174
175 target_include_directories(${STATIC_LIB} PUBLIC
176 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
177 $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
178 )
179
180 list(APPEND CMAKE_TARGETS ${STATIC_LIB})
181 endif()
182
183 if(BUILD_OBJECT_LIBS)
184 set(OBJECT_LIB ${PROJECT_NAME}_object)
185 add_library(${OBJECT_LIB} OBJECT ${PUBLIC_HEADERS} ${JSONCPP_SOURCES})
186
187 set_target_properties(${OBJECT_LIB} PROPERTIES
188 OUTPUT_NAME jsoncpp
189 VERSION ${PROJECT_VERSION}
190 SOVERSION ${PROJECT_SOVERSION}
191 POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
192 )
193
194 # Set library's runtime search path on OSX
195 if(APPLE)
196 set_target_properties(${OBJECT_LIB} PROPERTIES INSTALL_RPATH "@loader_path/.")
197 endif()
198
199 target_compile_features(${OBJECT_LIB} PUBLIC ${REQUIRED_FEATURES})
200
201 if(JSONCPP_HAS_STRING_VIEW)
202 target_compile_definitions(${OBJECT_LIB} PUBLIC JSONCPP_HAS_STRING_VIEW=1)
203 endif()
204
205 target_include_directories(${OBJECT_LIB} PUBLIC
206 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
207 $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${JSONCPP_INCLUDE_DIR}>
208 )
209
210 list(APPEND CMAKE_TARGETS ${OBJECT_LIB})
211 endif()
212
213 if (JSONCPP_WITH_INSTALL)
214
215 install(TARGETS ${CMAKE_TARGETS} ${INSTALL_EXPORT}
216 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
217 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
218 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
219 OBJECTS DESTINATION ${CMAKE_INSTALL_LIBDIR}
220 )
221
222 endif()