A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.
1 cmake_minimum_required (VERSION 3.1) 2 project(jansson C) 3 4 # Options 5 option(JANSSON_BUILD_SHARED_LIBS "Build shared libraries." OFF) 6 option(USE_URANDOM "Use /dev/urandom to seed the hash function." ON) 7 option(USE_WINDOWS_CRYPTOAPI "Use CryptGenRandom to seed the hash function." ON) 8 9 if (MSVC) 10 # This option must match the settings used in your program, in particular if you 11 # are linking statically 12 option(JANSSON_STATIC_CRT "Link the static CRT libraries" OFF ) 13 endif () 14 15 option(JANSSON_EXAMPLES "Compile example applications" ON) 16 17 if (UNIX) 18 option(JANSSON_COVERAGE "(GCC Only! Requires gcov/lcov to be installed). Include target for doing coverage analysis for the test suite. Note that -DCMAKE_BUILD_TYPE=Debug must be set" OFF) 19 endif () 20 21 # Set some nicer output dirs. 22 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) 23 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) 24 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) 25 set(JANSSON_TEMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/tmp) 26 27 # Give the debug version a different postfix for windows, 28 # so both the debug and release version can be built in the 29 # same build-tree on Windows (MSVC). 30 if (WIN32 AND NOT CMAKE_DEBUG_POSTFIX) 31 set(CMAKE_DEBUG_POSTFIX "_d") 32 endif() 33 34 # This is how I thought it should go 35 # set (JANSSON_VERSION "2.3.1") 36 # set (JANSSON_SOVERSION 2) 37 38 set(JANSSON_DISPLAY_VERSION "2.14") 39 40 # This is what is required to match the same numbers as automake's 41 set(JANSSON_VERSION "4.14.0") 42 set(JANSSON_SOVERSION 4) 43 44 # for CheckFunctionKeywords 45 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 46 47 include (CheckCSourceCompiles) 48 include (CheckFunctionExists) 49 include (CheckFunctionKeywords) 50 include (CheckIncludeFiles) 51 include (CheckTypeSize) 52 53 # suppress format-truncation warning 54 include (CheckCCompilerFlag) 55 check_c_compiler_flag(-Wno-format-truncation HAS_NO_FORMAT_TRUNCATION) 56 if (HAS_NO_FORMAT_TRUNCATION) 57 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format-truncation") 58 endif() 59 60 if (MSVC) 61 # Turn off Microsofts "security" warnings. 62 add_definitions( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /nologo" ) 63 64 if (JANSSON_STATIC_CRT) 65 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT") 66 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd") 67 endif() 68 endif() 69 70 message("C compiler: ${CMAKE_C_COMPILER_ID}") 71 72 if (JANSSON_COVERAGE) 73 include(CodeCoverage) 74 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") 75 endif() 76 77 check_include_files (endian.h HAVE_ENDIAN_H) 78 check_include_files (fcntl.h HAVE_FCNTL_H) 79 check_include_files (sched.h HAVE_SCHED_H) 80 check_include_files (unistd.h HAVE_UNISTD_H) 81 check_include_files (sys/param.h HAVE_SYS_PARAM_H) 82 check_include_files (sys/stat.h HAVE_SYS_STAT_H) 83 check_include_files (sys/time.h HAVE_SYS_TIME_H) 84 check_include_files (sys/types.h HAVE_SYS_TYPES_H) 85 86 check_function_exists (close HAVE_CLOSE) 87 check_function_exists (getpid HAVE_GETPID) 88 check_function_exists (gettimeofday HAVE_GETTIMEOFDAY) 89 check_function_exists (open HAVE_OPEN) 90 check_function_exists (read HAVE_READ) 91 check_function_exists (sched_yield HAVE_SCHED_YIELD) 92 93 # Check for the int-type includes 94 check_include_files (stdint.h HAVE_STDINT_H) 95 96 # Check our 64 bit integer sizes 97 check_type_size (__int64 __INT64) 98 check_type_size (int64_t INT64_T) 99 check_type_size ("long long" LONG_LONG_INT) 100 101 # Check our 32 bit integer sizes 102 check_type_size (int32_t INT32_T) 103 check_type_size (__int32 __INT32) 104 check_type_size ("long" LONG_INT) 105 check_type_size ("int" INT) 106 if (HAVE_INT32_T) 107 set (JSON_INT32 int32_t) 108 elseif (HAVE___INT32) 109 set (JSON_INT32 __int32) 110 elseif (HAVE_LONG_INT AND (LONG_INT EQUAL 4)) 111 set (JSON_INT32 long) 112 elseif (HAVE_INT AND (INT EQUAL 4)) 113 set (JSON_INT32 int) 114 else () 115 message (FATAL_ERROR "Could not detect a valid 32-bit integer type") 116 endif () 117 118 check_type_size ("unsigned long" UNSIGNED_LONG_INT) 119 check_type_size ("unsigned int" UNSIGNED_INT) 120 check_type_size ("unsigned short" UNSIGNED_SHORT) 121 122 check_type_size (uint32_t UINT32_T) 123 check_type_size (__uint32 __UINT32) 124 if (HAVE_UINT32_T) 125 set (JSON_UINT32 uint32_t) 126 elseif (HAVE___UINT32) 127 set (JSON_UINT32 __uint32) 128 elseif (HAVE_UNSIGNED_LONG_INT AND (UNSIGNED_LONG_INT EQUAL 4)) 129 set (JSON_UINT32 "unsigned long") 130 elseif (HAVE_UNSIGNED_INT AND (UNSIGNED_INT EQUAL 4)) 131 set (JSON_UINT32 "unsigned int") 132 else () 133 message (FATAL_ERROR "Could not detect a valid unsigned 32-bit integer type") 134 endif () 135 136 check_type_size (uint16_t UINT16_T) 137 check_type_size (__uint16 __UINT16) 138 if (HAVE_UINT16_T) 139 set (JSON_UINT16 uint16_t) 140 elseif (HAVE___UINT16) 141 set (JSON_UINT16 __uint16) 142 elseif (HAVE_UNSIGNED_INT AND (UNSIGNED_INT EQUAL 2)) 143 set (JSON_UINT16 "unsigned int") 144 elseif (HAVE_UNSIGNED_SHORT AND (UNSIGNED_SHORT EQUAL 2)) 145 set (JSON_UINT16 "unsigned short") 146 else () 147 message (FATAL_ERROR "Could not detect a valid unsigned 16-bit integer type") 148 endif () 149 150 check_type_size (uint8_t UINT8_T) 151 check_type_size (__uint8 __UINT8) 152 if (HAVE_UINT8_T) 153 set (JSON_UINT8 uint8_t) 154 elseif (HAVE___UINT8) 155 set (JSON_UINT8 __uint8) 156 else () 157 set (JSON_UINT8 "unsigned char") 158 endif () 159 160 # Check for ssize_t and SSIZE_T existence. 161 check_type_size(ssize_t SSIZE_T) 162 check_type_size(SSIZE_T UPPERCASE_SSIZE_T) 163 if(NOT HAVE_SSIZE_T) 164 if(HAVE_UPPERCASE_SSIZE_T) 165 set(JSON_SSIZE SSIZE_T) 166 else() 167 set(JSON_SSIZE int) 168 endif() 169 endif() 170 set(CMAKE_EXTRA_INCLUDE_FILES "") 171 172 # Check for all the variants of strtoll 173 check_function_exists (strtoll HAVE_STRTOLL) 174 check_function_exists (strtoq HAVE_STRTOQ) 175 check_function_exists (_strtoi64 HAVE__STRTOI64) 176 177 # Figure out what variant we should use 178 if (HAVE_STRTOLL) 179 set (JSON_STRTOINT strtoll) 180 elseif (HAVE_STRTOQ) 181 set (JSON_STRTOINT strtoq) 182 elseif (HAVE__STRTOI64) 183 set (JSON_STRTOINT _strtoi64) 184 else () 185 # fallback to strtol (32 bit) 186 # this will set all the required variables 187 set (JSON_STRTOINT strtol) 188 set (JSON_INT_T long) 189 set (JSON_INTEGER_FORMAT "\"ld\"") 190 endif () 191 192 # if we haven't defined JSON_INT_T, then we have a 64 bit conversion function. 193 # detect what to use for the 64 bit type. 194 # Note: I will prefer long long if I can get it, as that is what the automake system aimed for. 195 if (NOT DEFINED JSON_INT_T) 196 if (HAVE_LONG_LONG_INT AND (LONG_LONG_INT EQUAL 8)) 197 set (JSON_INT_T "long long") 198 elseif (HAVE_INT64_T) 199 set (JSON_INT_T int64_t) 200 elseif (HAVE___INT64) 201 set (JSON_INT_T __int64) 202 else () 203 message (FATAL_ERROR "Could not detect 64 bit type, although I detected the strtoll equivalent") 204 endif () 205 206 # Apparently, Borland BCC and MSVC wants I64d, 207 # Borland BCC could also accept LD 208 # and gcc wants ldd, 209 # I am not sure what cygwin will want, so I will assume I64d 210 211 if (WIN32) # matches both msvc and cygwin 212 set (JSON_INTEGER_FORMAT "\"I64d\"") 213 else () 214 set (JSON_INTEGER_FORMAT "\"lld\"") 215 endif () 216 endif () 217 218 219 # If locale.h and localeconv() are available, define to 1, otherwise to 0. 220 check_include_files (locale.h HAVE_LOCALE_H) 221 check_function_exists (localeconv HAVE_LOCALECONV) 222 223 if (HAVE_LOCALECONV AND HAVE_LOCALE_H) 224 set (JSON_HAVE_LOCALECONV 1) 225 else () 226 set (JSON_HAVE_LOCALECONV 0) 227 endif() 228 229 # check if we have setlocale 230 check_function_exists(setlocale HAVE_SETLOCALE) 231 232 # Check what the inline keyword is. 233 # Note that the original JSON_INLINE was always set to just 'inline', so this goes further. 234 check_function_keywords("inline") 235 check_function_keywords("__inline") 236 check_function_keywords("__inline__") 237 238 if (HAVE_INLINE) 239 set(JSON_INLINE inline) 240 elseif (HAVE___INLINE) 241 set(JSON_INLINE __inline) 242 elseif (HAVE___INLINE__) 243 set(JSON_INLINE __inline__) 244 else() 245 # no inline on this platform 246 set (JSON_INLINE) 247 endif() 248 249 check_c_source_compiles ("int main() { unsigned long val; __sync_bool_compare_and_swap(&val, 0, 1); __sync_add_and_fetch(&val, 1); __sync_sub_and_fetch(&val, 1); return 0; } " HAVE_SYNC_BUILTINS) 250 check_c_source_compiles ("int main() { char l; unsigned long v; __atomic_test_and_set(&l, __ATOMIC_RELAXED); __atomic_store_n(&v, 1, __ATOMIC_RELEASE); __atomic_load_n(&v, __ATOMIC_ACQUIRE); __atomic_add_fetch(&v, 1, __ATOMIC_ACQUIRE); __atomic_sub_fetch(&v, 1, __ATOMIC_RELEASE); return 0; }" HAVE_ATOMIC_BUILTINS) 251 252 if (HAVE_SYNC_BUILTINS) 253 set(JSON_HAVE_SYNC_BUILTINS 1) 254 else() 255 set(JSON_HAVE_SYNC_BUILTINS 0) 256 endif() 257 258 if (HAVE_ATOMIC_BUILTINS) 259 set(JSON_HAVE_ATOMIC_BUILTINS 1) 260 else() 261 set(JSON_HAVE_ATOMIC_BUILTINS 0) 262 endif() 263 264 set (JANSSON_INITIAL_HASHTABLE_ORDER 3 CACHE STRING "Number of buckets new object hashtables contain is 2 raised to this power. The default is 3, so empty hashtables contain 2^3 = 8 buckets.") 265 266 # configure the public config file 267 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_config.h.cmake 268 ${CMAKE_CURRENT_BINARY_DIR}/include/jansson_config.h) 269 270 # Copy the jansson.h file to the public include folder 271 file (COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h 272 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) 273 274 add_definitions(-DJANSSON_USING_CMAKE) 275 276 # configure the private config file 277 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_private_config.h.cmake 278 ${CMAKE_CURRENT_BINARY_DIR}/private_include/jansson_private_config.h) 279 280 # and tell the source code to include it 281 add_definitions(-DHAVE_CONFIG_H) 282 283 include_directories (${CMAKE_CURRENT_BINARY_DIR}/include) 284 include_directories (${CMAKE_CURRENT_BINARY_DIR}/private_include) 285 286 # Add the lib sources. 287 file(GLOB JANSSON_SRC src/*.c) 288 289 set(JANSSON_HDR_PRIVATE 290 ${CMAKE_CURRENT_SOURCE_DIR}/src/hashtable.h 291 ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson_private.h 292 ${CMAKE_CURRENT_SOURCE_DIR}/src/strbuffer.h 293 ${CMAKE_CURRENT_SOURCE_DIR}/src/utf.h 294 ${CMAKE_CURRENT_BINARY_DIR}/private_include/jansson_private_config.h) 295 296 set(JANSSON_HDR_PUBLIC 297 ${CMAKE_CURRENT_BINARY_DIR}/include/jansson_config.h 298 ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h) 299 300 source_group("Library Sources" FILES ${JANSSON_SRC}) 301 source_group("Library Private Headers" FILES ${JANSSON_HDR_PRIVATE}) 302 source_group("Library Public Headers" FILES ${JANSSON_HDR_PUBLIC}) 303 304 if(JANSSON_BUILD_SHARED_LIBS) 305 add_library(jansson SHARED 306 ${JANSSON_SRC} 307 ${JANSSON_HDR_PRIVATE} 308 ${JANSSON_HDR_PUBLIC} 309 src/jansson.def) 310 311 # check if linker support --default-symver 312 list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,--default-symver") 313 check_c_source_compiles( 314 " 315 int main (void) 316 { 317 return 0; 318 } 319 " 320 DSYMVER_WORKS 321 ) 322 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "-Wl,--default-symver") 323 324 if (SYMVER_WORKS) 325 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--default-symver") 326 else() 327 # some linkers may only support --version-script 328 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/jansson.sym" "JANSSON_${JANSSON_SOVERSION} { 329 global: 330 *; 331 }; 332 ") 333 list(APPEND CMAKE_REQUIRED_LIBRARIES "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/jansson.sym") 334 check_c_source_compiles( 335 " 336 int main (void) 337 { 338 return 0; 339 } 340 " 341 VSCRIPT_WORKS 342 ) 343 list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/jansson.sym") 344 if (VSCRIPT_WORKS) 345 set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/jansson.sym") 346 endif() 347 endif() 348 349 set_target_properties(jansson PROPERTIES 350 VERSION ${JANSSON_VERSION} 351 SOVERSION ${JANSSON_SOVERSION}) 352 else() 353 add_library(jansson STATIC 354 ${JANSSON_SRC} 355 ${JANSSON_HDR_PRIVATE} 356 ${JANSSON_HDR_PUBLIC}) 357 set_target_properties(jansson PROPERTIES 358 POSITION_INDEPENDENT_CODE true) 359 endif() 360 361 if (JANSSON_EXAMPLES) 362 add_executable(simple_parse "${CMAKE_CURRENT_SOURCE_DIR}/examples/simple_parse.c") 363 target_link_libraries(simple_parse jansson) 364 endif() 365 366 # For building Documentation (uses Sphinx) 367 option(JANSSON_BUILD_DOCS "Build documentation (uses python-sphinx)." ON) 368 if (JANSSON_BUILD_DOCS) 369 find_package(Sphinx) 370 371 if (NOT SPHINX_FOUND) 372 message(WARNING "Sphinx not found. Cannot generate documentation! 373 Set -DJANSSON_BUILD_DOCS=OFF to get rid of this message.") 374 else() 375 if (Sphinx_VERSION_STRING VERSION_LESS 1.0) 376 message(WARNING "Your Sphinx version is too old! 377 This project requires Sphinx v1.0 or above to produce 378 proper documentation (you have v${Sphinx_VERSION_STRING}). 379 You will get output but it will have errors.") 380 endif() 381 382 # configured documentation tools and intermediate build results 383 set(BINARY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/_build") 384 385 # Sphinx cache with pickled ReST documents 386 set(SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees") 387 388 # CMake could be used to build the conf.py file too, 389 # eg it could automatically write the version of the program or change the theme. 390 # if(NOT DEFINED SPHINX_THEME) 391 # set(SPHINX_THEME default) 392 # endif() 393 # 394 # if(NOT DEFINED SPHINX_THEME_DIR) 395 # set(SPHINX_THEME_DIR) 396 # endif() 397 # 398 # configure_file( 399 # "${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in" 400 # "${BINARY_BUILD_DIR}/conf.py" 401 # @ONLY) 402 403 # TODO: Add support for all sphinx builders: http://sphinx-doc.org/builders.html 404 405 # Add documentation targets. 406 set(DOC_TARGETS html) 407 408 option(JANSSON_BUILD_MAN "Create a target for building man pages." ON) 409 410 if (JANSSON_BUILD_MAN) 411 if (Sphinx_VERSION_STRING VERSION_LESS 1.0) 412 message(WARNING "Sphinx version 1.0 > is required to build man pages. You have v${Sphinx_VERSION_STRING}.") 413 else() 414 list(APPEND DOC_TARGETS man) 415 endif() 416 endif() 417 418 option(JANSSON_BUILD_LATEX "Create a target for building latex docs (to create PDF)." OFF) 419 420 if (JANSSON_BUILD_LATEX) 421 find_package(LATEX) 422 423 if (NOT LATEX_COMPILER) 424 message("Couldn't find Latex, can't build latex docs using Sphinx") 425 else() 426 message("Latex found! If you have problems building, see Sphinx documentation for required Latex packages.") 427 list(APPEND DOC_TARGETS latex) 428 endif() 429 endif() 430 431 # The doc target will build all documentation targets. 432 add_custom_target(doc) 433 434 foreach (DOC_TARGET ${DOC_TARGETS}) 435 add_custom_target(${DOC_TARGET} 436 ${SPHINX_EXECUTABLE} 437 # -q # Enable for quiet mode 438 -b ${DOC_TARGET} 439 -d "${SPHINX_CACHE_DIR}" 440 # -c "${BINARY_BUILD_DIR}" # enable if using cmake-generated conf.py 441 "${CMAKE_CURRENT_SOURCE_DIR}/doc" 442 "${CMAKE_CURRENT_BINARY_DIR}/doc/${DOC_TARGET}" 443 COMMENT "Building ${DOC_TARGET} documentation with Sphinx") 444 445 add_dependencies(doc ${DOC_TARGET}) 446 endforeach() 447 448 message("Building documentation enabled for: ${DOC_TARGETS}") 449 endif() 450 endif () 451 452 453 option(JANSSON_WITHOUT_TESTS "Don't build tests ('make test' to execute tests)" OFF) 454 455 if (NOT JANSSON_WITHOUT_TESTS) 456 option(JANSSON_TEST_WITH_VALGRIND "Enable valgrind tests." OFF) 457 458 ENABLE_TESTING() 459 460 if (JANSSON_TEST_WITH_VALGRIND) 461 # TODO: Add FindValgrind.cmake instead of having a hardcoded path. 462 463 add_definitions(-DVALGRIND) 464 465 # enable valgrind 466 set(CMAKE_MEMORYCHECK_COMMAND valgrind) 467 set(CMAKE_MEMORYCHECK_COMMAND_OPTIONS 468 "--error-exitcode=1 --leak-check=full --show-reachable=yes --track-origins=yes -q") 469 470 set(MEMCHECK_COMMAND 471 "${CMAKE_MEMORYCHECK_COMMAND} ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS}") 472 separate_arguments(MEMCHECK_COMMAND) 473 endif () 474 475 # 476 # Test suites. 477 # 478 if (CMAKE_COMPILER_IS_GNUCC) 479 add_definitions(-Wall -Wextra -Wdeclaration-after-statement) 480 endif () 481 482 set(api_tests 483 test_array 484 test_chaos 485 test_copy 486 test_dump 487 test_dump_callback 488 test_equal 489 test_fixed_size 490 test_load 491 test_load_callback 492 test_loadb 493 test_number 494 test_object 495 test_pack 496 test_simple 497 test_sprintf 498 test_unpack) 499 500 # Doing arithmetic on void pointers is not allowed by Microsofts compiler 501 # such as secure_malloc and secure_free is doing, so exclude it for now. 502 if (NOT MSVC) 503 list(APPEND api_tests test_memory_funcs) 504 endif() 505 506 # Helper macro for building and linking a test program. 507 macro(build_testprog name dir) 508 add_executable(${name} ${dir}/${name}.c) 509 add_dependencies(${name} jansson) 510 target_link_libraries(${name} jansson) 511 endmacro(build_testprog) 512 513 # Create executables and tests/valgrind tests for API tests. 514 foreach (test ${api_tests}) 515 build_testprog(${test} ${CMAKE_CURRENT_SOURCE_DIR}/test/suites/api) 516 517 if (JANSSON_TEST_WITH_VALGRIND) 518 add_test(memcheck__${test} 519 ${MEMCHECK_COMMAND} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test} 520 WORKING_DIRECTORY ${JANSSON_TEMP_DIR}) 521 else() 522 add_test(${test} 523 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test} 524 WORKING_DIRECTORY ${JANSSON_TEMP_DIR}) 525 endif () 526 endforeach () 527 528 # Test harness for the suites tests. 529 build_testprog(json_process ${CMAKE_CURRENT_SOURCE_DIR}/test/bin) 530 531 set(SUITE_TEST_CMD ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/json_process) 532 set(SUITES encoding-flags valid invalid invalid-unicode) 533 foreach (SUITE ${SUITES}) 534 file(GLOB TESTDIRS test/suites/${SUITE}/*) 535 536 foreach (TESTDIR ${TESTDIRS}) 537 if (IS_DIRECTORY ${TESTDIR}) 538 get_filename_component(TNAME ${TESTDIR} NAME) 539 540 if (JANSSON_TEST_WITH_VALGRIND) 541 add_test(memcheck__${SUITE}__${TNAME} 542 ${MEMCHECK_COMMAND} ${SUITE_TEST_CMD} ${TESTDIR}) 543 else() 544 add_test(${SUITE}__${TNAME} 545 ${SUITE_TEST_CMD} ${TESTDIR}) 546 endif() 547 548 if ((${SUITE} STREQUAL "valid" OR ${SUITE} STREQUAL "invalid") AND NOT EXISTS ${TESTDIR}/nostrip) 549 if (JANSSON_TEST_WITH_VALGRIND) 550 add_test(memcheck__${SUITE}__${TNAME}__strip 551 ${MEMCHECK_COMMAND} ${SUITE_TEST_CMD} --strip ${TESTDIR}) 552 else() 553 add_test(${SUITE}__${TNAME}__strip 554 ${SUITE_TEST_CMD} --strip ${TESTDIR}) 555 endif() 556 endif () 557 endif () 558 endforeach () 559 endforeach () 560 561 if (JANSSON_COVERAGE) 562 SETUP_TARGET_FOR_COVERAGE(coverage coverage ctest) 563 endif () 564 565 # Enable using "make check" just like the autotools project. 566 # By default cmake creates a target "make test" 567 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} 568 DEPENDS json_process ${api_tests}) 569 endif () 570 571 # 572 # Installation preparation. 573 # 574 575 # Allow the user to override installation directories. 576 set(JANSSON_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") 577 set(JANSSON_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") 578 set(JANSSON_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") 579 580 if(WIN32 AND NOT CYGWIN) 581 set(DEF_INSTALL_CMAKE_DIR cmake) 582 else() 583 set(DEF_INSTALL_CMAKE_DIR lib/cmake/jansson) 584 endif() 585 586 set(JANSSON_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") 587 588 # Create pkg-conf file. 589 # (We use the same files as ./configure does, so we 590 # have to defined the same variables used there). 591 set(prefix ${CMAKE_INSTALL_PREFIX}) 592 set(exec_prefix "\${prefix}") 593 set(libdir "\${exec_prefix}/${JANSSON_INSTALL_LIB_DIR}") 594 set(includedir "\${prefix}/${JANSSON_INSTALL_INCLUDE_DIR}") 595 set(VERSION ${JANSSON_DISPLAY_VERSION}) 596 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jansson.pc.in 597 ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc @ONLY) 598 599 # Make sure the paths are relative. 600 foreach(p LIB BIN INCLUDE CMAKE) 601 set(var JANSSON_INSTALL_${p}_DIR) 602 endforeach() 603 604 # Generate the config file for the build-tree. 605 set(JANSSON__INCLUDE_DIRS 606 "${CMAKE_CURRENT_SOURCE_DIR}/include" 607 "${CMAKE_CURRENT_BINARY_DIR}/include") 608 set(JANSSON_INCLUDE_DIRS ${JANSSON__INCLUDE_DIRS} CACHE PATH "Jansson include directories") 609 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfig.cmake.in 610 ${CMAKE_CURRENT_BINARY_DIR}/janssonConfig.cmake 611 @ONLY) 612 613 614 # Generate the config file for the installation tree. 615 include(CMakePackageConfigHelpers) 616 617 write_basic_package_version_file( 618 "${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonConfigVersion.cmake" 619 VERSION ${JANSSON_VERSION} 620 COMPATIBILITY ExactVersion 621 ) 622 623 configure_package_config_file( 624 "cmake/janssonConfig.cmake.in" 625 "${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonConfig.cmake" 626 INSTALL_DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}" 627 ) 628 629 # 630 # Install targets. 631 # 632 option(JANSSON_INSTALL "Generate installation target" ON) 633 if (JANSSON_INSTALL) 634 install(TARGETS jansson 635 EXPORT janssonTargets 636 LIBRARY DESTINATION "lib" 637 ARCHIVE DESTINATION "lib" 638 RUNTIME DESTINATION "bin" 639 INCLUDES DESTINATION "include") 640 641 install(FILES ${JANSSON_HDR_PUBLIC} 642 DESTINATION "include") 643 644 # Install the pkg-config. 645 install(FILES 646 ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc 647 DESTINATION lib/pkgconfig) 648 649 # Install the configs. 650 install(FILES 651 ${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonConfig.cmake 652 ${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonConfigVersion.cmake 653 DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}") 654 655 # Install exports for the install-tree. 656 install(EXPORT janssonTargets 657 NAMESPACE jansson:: 658 DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}") 659 endif() 660 661 # For use when simply using add_library from a parent project to build jansson. 662 set(JANSSON_LIBRARIES jansson CACHE STRING "jansson libraries")