diff options
author | Petri Lehtinen <petri@digip.org> | 2014-01-27 23:10:55 -0800 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2014-01-27 23:10:55 -0800 |
commit | cffc5df60034d4c3f3f5d8c40746aaafcef75546 (patch) | |
tree | 7e38f9d91359d1bdce323b790f188462b0f85135 | |
parent | b21cd65d305f04b52c3c7cb1a33c63a2b1d7ad28 (diff) | |
parent | 3fe8f74e7f292f856717f7c0a3dccd4a45e574c1 (diff) | |
download | jansson-cffc5df60034d4c3f3f5d8c40746aaafcef75546.zip jansson-cffc5df60034d4c3f3f5d8c40746aaafcef75546.tar.gz jansson-cffc5df60034d4c3f3f5d8c40746aaafcef75546.tar.bz2 |
Merge pull request #157 from JoakimSoderberg/cmake_config_new
Cmake config
-rw-r--r-- | CMakeLists.txt | 239 | ||||
-rw-r--r-- | cmake/JanssonConfig.cmake.in | 17 | ||||
-rw-r--r-- | cmake/JanssonConfigVersion.cmake.in | 11 | ||||
-rw-r--r-- | cmake/jansson_config.h.cmake | 2 | ||||
-rw-r--r-- | cmake/jansson_private_config.h.cmake (renamed from cmake/config.h.cmake) | 0 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/strconv.c | 4 | ||||
-rw-r--r-- | src/utf.h | 3 | ||||
-rw-r--r-- | test/bin/json_process.c | 2 | ||||
-rw-r--r-- | test/suites/api/test_pack.c | 2 | ||||
-rw-r--r-- | test/suites/api/util.h | 2 |
11 files changed, 201 insertions, 83 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 08c1666..1463f9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,24 +51,24 @@ cmake_minimum_required (VERSION 2.8) project (jansson C) # Options -OPTION (BUILD_SHARED_LIBS "Build shared libraries." OFF) +option(JANSSON_BUILD_SHARED_LIBS "Build shared libraries." OFF) if (MSVC) # This option must match the settings used in your program, in particular if you # are linking statically - OPTION( STATIC_CRT "Link the static CRT libraries" OFF ) + option(JANSSON_STATIC_CRT "Link the static CRT libraries" OFF ) endif () # Set some nicer output dirs. -SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) -SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) -SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) # Give the debug version a different postfix for windows, # so both the debug and release version can be built in the # same build-tree on Windows (MSVC). if (WIN32) - SET (CMAKE_DEBUG_POSTFIX "_d") + set(CMAKE_DEBUG_POSTFIX "_d") else (WIN32) endif (WIN32) @@ -79,8 +79,8 @@ endif (WIN32) set(JANSSON_DISPLAY_VERSION "2.5") # This is what is required to match the same numbers as automake's -set (JANSSON_VERSION "4.5.0") -set (JANSSON_SOVERSION 4) +set(JANSSON_VERSION "4.5.0") +set(JANSSON_SOVERSION 4) # for CheckFunctionKeywords set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -204,11 +204,11 @@ if (HAVE_LOCALECONV AND HAVE_LOCALE_H) set (JSON_HAVE_LOCALECONV 1) else () set (JSON_HAVE_LOCALECONV 0) -endif () +endif() # check if we have setlocale -check_function_exists (setlocale HAVE_SETLOCALE) +check_function_exists(setlocale HAVE_SETLOCALE) # Check what the inline keyword is. @@ -218,38 +218,25 @@ check_function_keywords("__inline") check_function_keywords("__inline__") if (HAVE_INLINE) - set (JSON_INLINE inline) + set(JSON_INLINE inline) elseif (HAVE___INLINE) - set (JSON_INLINE __inline) + set(JSON_INLINE __inline) elseif (HAVE___INLINE__) - set (JSON_INLINE __inline__) -else (HAVE_INLINE) + set(JSON_INLINE __inline__) +else() # no inline on this platform set (JSON_INLINE) -endif (HAVE_INLINE) +endif() # Find our snprintf check_function_exists (snprintf HAVE_SNPRINTF) check_function_exists (_snprintf HAVE__SNPRINTF) if (HAVE_SNPRINTF) - set (JSON_SNPRINTF snprintf) + set(JSON_SNPRINTF snprintf) elseif (HAVE__SNPRINTF) - set (JSON_SNPRINTF _snprintf) -endif () - -# Create pkg-conf file. -# (We use the same files as ./configure does, so we -# have to defined the same variables used there). -if(NOT DEFINED CMAKE_INSTALL_LIBDIR) - set(CMAKE_INSTALL_LIBDIR lib) -endif(NOT DEFINED CMAKE_INSTALL_LIBDIR) -set(prefix ${CMAKE_INSTALL_PREFIX}) -set(exec_prefix ${CMAKE_INSTALL_PREFIX}) -set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) -set(VERSION ${JANSSON_DISPLAY_VERSION}) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jansson.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc @ONLY) + set(JSON_SNPRINTF _snprintf) +endif () # configure the public config file configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_config.h.cmake @@ -259,59 +246,58 @@ configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_config.h.cmake file (COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/) +add_definitions(-DJANSSON_USING_CMAKE) # configure the private config file -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.cmake - ${CMAKE_CURRENT_BINARY_DIR}/private_include/config.h) - -# and tell the source code to include it -add_definitions (-DHAVE_CONFIG_H) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/jansson_private_config.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/private_include/jansson_private_config.h) include_directories (${CMAKE_CURRENT_BINARY_DIR}/include) include_directories (${CMAKE_CURRENT_BINARY_DIR}/private_include) # Add the lib sources. -file (GLOB C_FILES src/*.c) - -if (BUILD_SHARED_LIBS) - - add_library (jansson SHARED ${C_FILES} src/jansson.def) - - set_target_properties (jansson PROPERTIES +file(GLOB JANSSON_SRC src/*.c) + +set(JANSSON_HDR_PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src/hashtable.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson_private.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/strbuffer.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/utf.h) + +set(JANSSON_HDR_PUBLIC + ${CMAKE_CURRENT_BINARY_DIR}/include/jansson_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h) + +source_group("Library Sources" FILES ${JANSSON_SRC}) +source_group("Library Private Headers" FILES ${JANSSON_HDR_PRIVATE}) +source_group("Library Public Headers" FILES ${JANSSON_HDR_PUBLIC}) + +if(JANSSON_BUILD_SHARED_LIBS) + add_library(jansson SHARED + ${JANSSON_SRC} + ${JANSSON_HDR_PRIVATE} + ${JANSSON_HDR_PUBLIC} + src/jansson.def) + + set_target_properties(jansson PROPERTIES VERSION ${JANSSON_VERSION} SOVERSION ${JANSSON_SOVERSION}) +else() + add_library(jansson + ${JANSSON_SRC} + ${JANSSON_HDR_PRIVATE} + ${JANSSON_HDR_PUBLIC}) +endif() -else () - - add_library (jansson ${C_FILES}) - -endif () - -# LIBRARY for linux -# RUNTIME for windows (when building shared) -install (TARGETS jansson - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION bin -) - -install (FILES - ${CMAKE_CURRENT_BINARY_DIR}/include/jansson_config.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h - DESTINATION include) - -install (FILES - ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) # For building Documentation (uses Sphinx) -OPTION (BUILD_DOCS "Build documentation (uses python-sphinx)." ON) -if (BUILD_DOCS) +option(JANSSON_BUILD_DOCS "Build documentation (uses python-sphinx)." ON) +if (JANSSON_BUILD_DOCS) find_package(Sphinx) if (NOT SPHINX_FOUND) message(WARNING "Sphinx not found. Cannot generate documentation! - Set -DBUILD_DOCS=0 to get rid of this message.") + Set -DJANSSON_BUILD_DOCS=OFF to get rid of this message.") else() if (Sphinx_VERSION_STRING VERSION_LESS 1.0) message(WARNING "Your Sphinx version is too old! @@ -346,9 +332,9 @@ if (BUILD_DOCS) # Add documentation targets. set(DOC_TARGETS html) - OPTION(BUILD_MAN "Create a target for building man pages." ON) + option(JANSSON_BUILD_MAN "Create a target for building man pages." ON) - if (BUILD_MAN) + if (JANSSON_BUILD_MAN) if (Sphinx_VERSION_STRING VERSION_LESS 1.0) message(WARNING "Sphinx version 1.0 > is required to build man pages. You have v${Sphinx_VERSION_STRING}.") else() @@ -356,9 +342,9 @@ if (BUILD_DOCS) endif() endif() - OPTION(BUILD_LATEX "Create a target for building latex docs (to create PDF)." OFF) + option(JANSSON_BUILD_LATEX "Create a target for building latex docs (to create PDF)." OFF) - if (BUILD_LATEX) + if (JANSSON_BUILD_LATEX) find_package(LATEX) if (NOT LATEX_COMPILER) @@ -391,14 +377,14 @@ if (BUILD_DOCS) endif () -OPTION (WITHOUT_TESTS "Don't build tests ('make test' to execute tests)" OFF) +option(JANSSON_WITHOUT_TESTS "Don't build tests ('make test' to execute tests)" OFF) -if (NOT WITHOUT_TESTS) - OPTION (TEST_WITH_VALGRIND "Enable valgrind tests." OFF) +if (NOT JANSSON_WITHOUT_TESTS) + option(JANSSON_TEST_WITH_VALGRIND "Enable valgrind tests." OFF) ENABLE_TESTING() - if (TEST_WITH_VALGRIND) + if (JANSSON_TEST_WITH_VALGRIND) # TODO: Add FindValgrind.cmake instead of having a hardcoded path. # enable valgrind @@ -479,3 +465,104 @@ if (NOT WITHOUT_TESTS) DEPENDS json_process ${api_tests}) endif () +# +# Installation preparation. +# + +# Allow the user to override installation directories. +set(JANSSON_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") +set(JANSSON_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") +set(JANSSON_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") + +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKE_DIR cmake) +else() + set(DEF_INSTALL_CMAKE_DIR lib/cmake/jansson) +endif() + +set(JANSSON_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") + +# Make sure the paths are absolute. +foreach(p LIB BIN INCLUDE CMAKE) + set(var JANSSON_INSTALL_${p}_DIR) + if(NOT IS_ABSOLUTE "${${var}}") + set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") + endif() +endforeach() + +# Export targets (This is used for other CMake projects to easily find the libraries and include files). +export(TARGETS jansson + FILE "${PROJECT_BINARY_DIR}/JanssonTargets.cmake") +export(PACKAGE jansson) + +# Generate the config file for the build-tree. +set(JANSSON__INCLUDE_DIRS + "${PROJECT_SOURCE_DIR}/include" + "${PROJECT_BINARY_DIR}/include") +set(JANSSON_INCLUDE_DIRS ${JANSSON__INCLUDE_DIRS} CACHE PATH "Jansson include directories") +configure_file(${PROJECT_SOURCE_DIR}/cmake/JanssonConfig.cmake.in + ${PROJECT_BINARY_DIR}/JanssonConfig.cmake + @ONLY) + +# Generate the config file for the installation tree. +file(RELATIVE_PATH + REL_INCLUDE_DIR + "${JANSSON_INSTALL_CMAKE_DIR}" + "${JANSSON_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the Cmake dir. + +# Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in, +# we escape it here so it's evaluated when it is included instead +# so that the include dirs are given relative to where the +# config file is located. +set(JANSSON__INCLUDE_DIRS + "\${JANSSON_CMAKE_DIR}/${REL_INCLUDE_DIR}") +configure_file(${PROJECT_SOURCE_DIR}/cmake/JanssonConfig.cmake.in + ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/JanssonConfig.cmake + @ONLY) + +# Generate version info for both build-tree and install-tree. +configure_file(${PROJECT_SOURCE_DIR}/cmake/JanssonConfigVersion.cmake.in + ${PROJECT_BINARY_DIR}/JanssonConfigVersion.cmake + @ONLY) + +# Define the public headers. +set_target_properties(jansson PROPERTIES PUBLIC_HEADER "${JANSSON_HDR_PUBLIC}") +#TODO: fix this. + +# Create pkg-conf file. +# (We use the same files as ./configure does, so we +# have to defined the same variables used there). +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix ${CMAKE_INSTALL_PREFIX}) +set(libdir ${CMAKE_INSTALL_PREFIX}/${JANSSON_INSTALL_LIB_DIR}) +set(VERSION ${JANSSON_DISPLAY_VERSION}) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jansson.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc @ONLY) + +# +# Install targets. +# +install(TARGETS jansson + EXPORT JanssonTargets + LIBRARY DESTINATION "${JANSSON_INSTALL_LIB_DIR}" COMPONENT lib + ARCHIVE DESTINATION "${JANSSON_INSTALL_LIB_DIR}" COMPONENT lib + RUNTIME DESTINATION "${JANSSON_INSTALL_BIN_DIR}" COMPONENT lib # Windows DLLs + PUBLIC_HEADER DESTINATION "${JANSSON_INSTALL_INCLUDE_DIR}" COMPONENT dev) + +# Install the pkg-config. +install (FILES + ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc + DESTINATION ${JANSSON_INSTALL_LIB_DIR}/pkgconfig COMPONENT dev) + +# Install the configs. +install(FILES + ${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/JanssonConfig.cmake + ${PROJECT_BINARY_DIR}/JanssonConfigVersion.cmake + DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}" COMPONENT dev) + +# Install exports for the install-tree. +install(EXPORT JanssonTargets + DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}" COMPONENT dev) + +# For use when simply using add_library from a parent project to build jansson. +set(JANSSON_LIBRARIES jansson CACHE STRING "Jansson libraries") diff --git a/cmake/JanssonConfig.cmake.in b/cmake/JanssonConfig.cmake.in new file mode 100644 index 0000000..d00b3c4 --- /dev/null +++ b/cmake/JanssonConfig.cmake.in @@ -0,0 +1,17 @@ +# - Config file for the jansson package +# It defines the following variables +# JANSSON_INCLUDE_DIRS - include directories for FooBar +# JANSSON_LIBRARIES - libraries to link against + +# Get the path of the current file. +get_filename_component(JANSSON_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +# Set the include directories. +set(JANSSON_INCLUDE_DIRS "@JANSSON__INCLUDE_DIRS@") + +# Include the project Targets file, this contains definitions for IMPORTED targets. +include(${JANSSON_CMAKE_DIR}/JanssonTargets.cmake) + +# IMPORTED targets from JanssonTargets.cmake +set(JANSSON_LIBRARIES jansson) + diff --git a/cmake/JanssonConfigVersion.cmake.in b/cmake/JanssonConfigVersion.cmake.in new file mode 100644 index 0000000..83b0d74 --- /dev/null +++ b/cmake/JanssonConfigVersion.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@JANSSON_DISPLAY_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff --git a/cmake/jansson_config.h.cmake b/cmake/jansson_config.h.cmake index 8c500b5..9917b56 100644 --- a/cmake/jansson_config.h.cmake +++ b/cmake/jansson_config.h.cmake @@ -17,7 +17,9 @@ #define JANSSON_CONFIG_H /* Define this so that we can disable scattered automake configuration in source files */ +#ifndef JANSSON_USING_CMAKE #define JANSSON_USING_CMAKE +#endif /* Note: when using cmake, JSON_INTEGER_IS_LONG_LONG is not defined nor used, * as we will also check for __int64 etc types. diff --git a/cmake/config.h.cmake b/cmake/jansson_private_config.h.cmake index bc81178..bc81178 100644 --- a/cmake/config.h.cmake +++ b/cmake/jansson_private_config.h.cmake diff --git a/configure.ac b/configure.ac index 24ba37d..2f26149 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT([jansson], [2.5], [petri@digip.org]) AM_INIT_AUTOMAKE([1.10 foreign]) AC_CONFIG_SRCDIR([src/value.c]) -AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_HEADERS([jansson_private_config.h]) # Checks for programs. AC_PROG_CC diff --git a/src/strconv.c b/src/strconv.c index 3e2cb7c..3a70c6f 100644 --- a/src/strconv.c +++ b/src/strconv.c @@ -5,9 +5,9 @@ #include "jansson_private.h" #include "strbuffer.h" -/* need config.h to get the correct snprintf */ +/* need jansson_private_config.h to get the correct snprintf */ #ifdef HAVE_CONFIG_H -#include <config.h> +#include <jansson_private_config.h> #endif #if JSON_HAVE_LOCALECONV @@ -9,7 +9,8 @@ #define UTF_H #ifdef HAVE_CONFIG_H -#include <config.h> + +#include <jansson_private_config.h> #ifdef HAVE_INTTYPES_H /* inttypes.h includes stdint.h in a standard environment, so there's diff --git a/test/bin/json_process.c b/test/bin/json_process.c index 23afefe..8ca3fe3 100644 --- a/test/bin/json_process.c +++ b/test/bin/json_process.c @@ -6,7 +6,7 @@ */ #ifdef HAVE_CONFIG_H -#include <config.h> +#include <jansson_private_config.h> #endif #include <stdio.h> diff --git a/test/suites/api/test_pack.c b/test/suites/api/test_pack.c index 348d8b2..487137c 100644 --- a/test/suites/api/test_pack.c +++ b/test/suites/api/test_pack.c @@ -7,7 +7,7 @@ */ #ifdef HAVE_CONFIG_H -#include <config.h> +#include <jansson_private_config.h> #endif #include <jansson_config.h> diff --git a/test/suites/api/util.h b/test/suites/api/util.h index b86a546..e4019de 100644 --- a/test/suites/api/util.h +++ b/test/suites/api/util.h @@ -9,7 +9,7 @@ #define UTIL_H #ifdef HAVE_CONFIG_H -#include <config.h> +#include <jansson_private_config.h> #endif #include <stdio.h> |