From d8798468c6dae7227da4c5f0d6a568e99c27510f Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 09:34:45 -0400 Subject: [PATCH 01/11] Upgrade CMake to 3.1 for Hunter --- CMakeLists.txt | 57 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f6cfec..385b9ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,9 +46,8 @@ -cmake_minimum_required (VERSION 2.8) -# required for exports? cmake_minimum_required (VERSION 2.8.6) -project (jansson C) +cmake_minimum_required (VERSION 3.1) +project(jansson C) # Options option(JANSSON_BUILD_SHARED_LIBS "Build shared libraries." OFF) @@ -104,12 +103,12 @@ include (CheckTypeSize) if (MSVC) # Turn off Microsofts "security" warnings. add_definitions( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /nologo" ) - + if (JANSSON_STATIC_CRT) set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd") endif() - + endif() if (NOT WIN32 AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)) @@ -338,7 +337,7 @@ set(JANSSON_HDR_PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/utf.h ${CMAKE_CURRENT_BINARY_DIR}/private_include/jansson_private_config.h) -set(JANSSON_HDR_PUBLIC +set(JANSSON_HDR_PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include/jansson_config.h ${CMAKE_CURRENT_SOURCE_DIR}/src/jansson.h) @@ -347,19 +346,19 @@ 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} + 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 + add_library(jansson ${JANSSON_SRC} - ${JANSSON_HDR_PRIVATE} + ${JANSSON_HDR_PRIVATE} ${JANSSON_HDR_PUBLIC}) endif() @@ -374,12 +373,12 @@ if (JANSSON_BUILD_DOCS) find_package(Sphinx) if (NOT SPHINX_FOUND) - message(WARNING "Sphinx not found. Cannot generate documentation! + message(WARNING "Sphinx not found. Cannot generate documentation! 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! - This project requires Sphinx v1.0 or above to produce + message(WARNING "Your Sphinx version is too old! + This project requires Sphinx v1.0 or above to produce proper documentation (you have v${Sphinx_VERSION_STRING}). You will get output but it will have errors.") endif() @@ -432,7 +431,7 @@ if (JANSSON_BUILD_DOCS) list(APPEND DOC_TARGETS latex) endif() endif() - + # The doc target will build all documentation targets. add_custom_target(doc) @@ -576,7 +575,7 @@ if (NOT JANSSON_WITHOUT_TESTS) # Enable using "make check" just like the autotools project. # By default cmake creates a target "make test" - add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS json_process ${api_tests}) endif () @@ -622,33 +621,33 @@ export(TARGETS jansson export(PACKAGE jansson) # Generate the config file for the build-tree. -set(JANSSON__INCLUDE_DIRS +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 + ${PROJECT_BINARY_DIR}/JanssonConfig.cmake @ONLY) # Generate the config file for the installation tree. -file(RELATIVE_PATH - REL_INCLUDE_DIR +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, +# 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 +# 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}") +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 + ${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 + ${PROJECT_BINARY_DIR}/JanssonConfigVersion.cmake @ONLY) # Define the public headers. @@ -668,7 +667,7 @@ install(TARGETS jansson PUBLIC_HEADER DESTINATION "${JANSSON_INSTALL_INCLUDE_DIR}" COMPONENT dev) # Install the pkg-config. -install (FILES +install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc DESTINATION ${JANSSON_INSTALL_LIB_DIR}/pkgconfig COMPONENT dev) @@ -679,7 +678,7 @@ install(FILES DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}" COMPONENT dev) # Install exports for the install-tree. -install(EXPORT JanssonTargets +install(EXPORT JanssonTargets DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}" COMPONENT dev) endif() From 44f6606df86049668f04331df0123cc642529851 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 09:47:29 -0400 Subject: [PATCH 02/11] Rename config files --- CMakeLists.txt | 18 +++++++++--------- ...nConfig.cmake.in => janssonConfig.cmake.in} | 0 ....cmake.in => janssonConfigVersion.cmake.in} | 0 3 files changed, 9 insertions(+), 9 deletions(-) rename cmake/{JanssonConfig.cmake.in => janssonConfig.cmake.in} (100%) rename cmake/{JanssonConfigVersion.cmake.in => janssonConfigVersion.cmake.in} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 385b9ac..e94d9e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -625,8 +625,8 @@ 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 +configure_file(${PROJECT_SOURCE_DIR}/cmake/janssonConfig.cmake.in + ${PROJECT_BINARY_DIR}/janssonConfig.cmake @ONLY) # Generate the config file for the installation tree. @@ -635,19 +635,19 @@ file(RELATIVE_PATH "${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, +# 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 +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 +configure_file(${PROJECT_SOURCE_DIR}/cmake/janssonConfigVersion.cmake.in + ${PROJECT_BINARY_DIR}/janssonConfigVersion.cmake @ONLY) # Define the public headers. @@ -673,8 +673,8 @@ install (FILES # Install the configs. install(FILES - ${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/JanssonConfig.cmake - ${PROJECT_BINARY_DIR}/JanssonConfigVersion.cmake + ${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. diff --git a/cmake/JanssonConfig.cmake.in b/cmake/janssonConfig.cmake.in similarity index 100% rename from cmake/JanssonConfig.cmake.in rename to cmake/janssonConfig.cmake.in diff --git a/cmake/JanssonConfigVersion.cmake.in b/cmake/janssonConfigVersion.cmake.in similarity index 100% rename from cmake/JanssonConfigVersion.cmake.in rename to cmake/janssonConfigVersion.cmake.in From a324d18940a7f3bfb3f4d684f0421f297316b426 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 09:52:48 -0400 Subject: [PATCH 03/11] Rename target file --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e94d9e0..15fa2c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -617,7 +617,7 @@ 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") + FILE "${PROJECT_BINARY_DIR}/janssonTargets.cmake") export(PACKAGE jansson) # Generate the config file for the build-tree. @@ -660,7 +660,7 @@ set_target_properties(jansson PROPERTIES PUBLIC_HEADER "${JANSSON_HDR_PUBLIC}") option(JANSSON_INSTALL "Generate installation target" ON) if (JANSSON_INSTALL) install(TARGETS jansson - EXPORT JanssonTargets + 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 @@ -678,9 +678,9 @@ install(FILES DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}" COMPONENT dev) # Install exports for the install-tree. -install(EXPORT JanssonTargets +install(EXPORT janssonTargets DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}" COMPONENT dev) endif() # For use when simply using add_library from a parent project to build jansson. -set(JANSSON_LIBRARIES jansson CACHE STRING "Jansson libraries") +set(JANSSON_LIBRARIES jansson CACHE STRING "jansson libraries") From 6d1ae86e1c1942c46203b788fa410e91f3963483 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 09:58:26 -0400 Subject: [PATCH 04/11] Fix config file --- cmake/janssonConfig.cmake.in | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/cmake/janssonConfig.cmake.in b/cmake/janssonConfig.cmake.in index d00b3c4..abd6793 100644 --- a/cmake/janssonConfig.cmake.in +++ b/cmake/janssonConfig.cmake.in @@ -1,17 +1,4 @@ -# - 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) +@PACKAGE_INIT@ +include("${CMAKE_CURRENT_LIST_DIR}/janssonTargets.cmake") +check_required_components("@PROJECT_NAME@") From b70364b36204467d7c523ff005927fa271137461 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 10:11:09 -0400 Subject: [PATCH 05/11] Remove absolute path references --- CMakeLists.txt | 60 ++++++++++++++--------------- cmake/janssonConfigVersion.cmake.in | 2 +- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15fa2c7..25bf1bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,10 +69,10 @@ if (UNIX) 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(JANSSON_TEMP_DIR ${PROJECT_BINARY_DIR}/tmp) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +set(JANSSON_TEMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/tmp) # Give the debug version a different postfix for windows, # so both the debug and release version can be built in the @@ -363,7 +363,7 @@ else() endif() if (JANSSON_EXAMPLES) - add_executable(simple_parse "${PROJECT_SOURCE_DIR}/examples/simple_parse.c") + add_executable(simple_parse "${CMAKE_CURRENT_SOURCE_DIR}/examples/simple_parse.c") target_link_libraries(simple_parse jansson) endif() @@ -514,7 +514,7 @@ if (NOT JANSSON_WITHOUT_TESTS) # Create executables and tests/valgrind tests for API tests. foreach (test ${api_tests}) - build_testprog(${test} ${PROJECT_SOURCE_DIR}/test/suites/api) + build_testprog(${test} ${CMAKE_CURRENT_SOURCE_DIR}/test/suites/api) if (JANSSON_TEST_WITH_VALGRIND) add_test(memcheck__${test} @@ -528,12 +528,12 @@ if (NOT JANSSON_WITHOUT_TESTS) endforeach () # Test harness for the suites tests. - build_testprog(json_process ${PROJECT_SOURCE_DIR}/test/bin) + build_testprog(json_process ${CMAKE_CURRENT_SOURCE_DIR}/test/bin) set(SUITE_TEST_CMD ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/json_process) set(SUITES encoding-flags valid invalid invalid-unicode) foreach (SUITE ${SUITES}) - file(GLOB TESTDIRS ${jansson_SOURCE_DIR}/test/suites/${SUITE}/*) + file(GLOB TESTDIRS test/suites/${SUITE}/*) foreach (TESTDIR ${TESTDIRS}) if (IS_DIRECTORY ${TESTDIR}) @@ -617,16 +617,16 @@ 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") + FILE "${CMAKE_CURRENT_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") + "${CMAKE_CURRENT_SOURCE_DIR}/include" + "${CMAKE_CURRENT_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 +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/janssonConfig.cmake @ONLY) # Generate the config file for the installation tree. @@ -641,19 +641,14 @@ file(RELATIVE_PATH # 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 +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfig.cmake.in + ${CMAKE_CURRENT_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 +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfigVersion.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/janssonConfigVersion.cmake @ONLY) - -# Define the public headers. -set_target_properties(jansson PROPERTIES PUBLIC_HEADER "${JANSSON_HDR_PUBLIC}") -#TODO: fix this. - # # Install targets. # @@ -661,21 +656,24 @@ option(JANSSON_INSTALL "Generate installation target" ON) if (JANSSON_INSTALL) 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) + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "include") + +install(FILES ${JANSSON_HDR_PUBLIC} + DESTINATION "include") # Install the pkg-config. -install (FILES +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc - DESTINATION ${JANSSON_INSTALL_LIB_DIR}/pkgconfig COMPONENT dev) + DESTINATION lib/pkgconfig) # 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) + ${CMAKE_CURRENT_BINARY_DIR}/janssonConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/janssonConfigVersion.cmake + DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}") # Install exports for the install-tree. install(EXPORT janssonTargets diff --git a/cmake/janssonConfigVersion.cmake.in b/cmake/janssonConfigVersion.cmake.in index 83b0d74..4481520 100644 --- a/cmake/janssonConfigVersion.cmake.in +++ b/cmake/janssonConfigVersion.cmake.in @@ -8,4 +8,4 @@ else() if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") set(PACKAGE_VERSION_EXACT TRUE) endif() -endif() +endif() From 6d7a02beb0b5c246ac76caf636d3b634732c38f5 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 10:24:27 -0400 Subject: [PATCH 06/11] Clean up CMake install --- CMakeLists.txt | 73 ++++++++++++----------------- cmake/janssonConfigVersion.cmake.in | 11 ----- 2 files changed, 31 insertions(+), 53 deletions(-) delete mode 100644 cmake/janssonConfigVersion.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 25bf1bb..9226b66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -615,11 +615,6 @@ foreach(p LIB BIN INCLUDE CMAKE) endif() endforeach() -# Export targets (This is used for other CMake projects to easily find the libraries and include files). -export(TARGETS jansson - FILE "${CMAKE_CURRENT_BINARY_DIR}/janssonTargets.cmake") -export(PACKAGE jansson) - # Generate the config file for the build-tree. set(JANSSON__INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" @@ -629,55 +624,49 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfig.cmake.in ${CMAKE_CURRENT_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. +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonVersionConfig.cmake" + VERSION ${PROJECT_VERSION} +) -# 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(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/janssonConfig.cmake - @ONLY) +configure_package_config_file( + "cmake/janssonConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonConfig.cmake" + INSTALL_DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}" +) -# Generate version info for both build-tree and install-tree. -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfigVersion.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/janssonConfigVersion.cmake - @ONLY) # # Install targets. # option(JANSSON_INSTALL "Generate installation target" ON) if (JANSSON_INSTALL) -install(TARGETS jansson - EXPORT janssonTargets - LIBRARY DESTINATION "lib" - ARCHIVE DESTINATION "lib" - RUNTIME DESTINATION "bin" - INCLUDES DESTINATION "include") + install(TARGETS jansson + EXPORT janssonTargets + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "include") -install(FILES ${JANSSON_HDR_PUBLIC} - DESTINATION "include") + install(FILES ${JANSSON_HDR_PUBLIC} + DESTINATION "include") -# Install the pkg-config. -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc - DESTINATION lib/pkgconfig) + # Install the pkg-config. + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc + DESTINATION lib/pkgconfig) -# Install the configs. -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/janssonConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/janssonConfigVersion.cmake - DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}") + # Install the configs. + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonConfigVersion.cmake + DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}") -# Install exports for the install-tree. -install(EXPORT janssonTargets - DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}" COMPONENT dev) + # Install exports for the install-tree. + install(EXPORT janssonTargets + NAMESPACE jansson + DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}") endif() # For use when simply using add_library from a parent project to build jansson. diff --git a/cmake/janssonConfigVersion.cmake.in b/cmake/janssonConfigVersion.cmake.in deleted file mode 100644 index 4481520..0000000 --- a/cmake/janssonConfigVersion.cmake.in +++ /dev/null @@ -1,11 +0,0 @@ -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() From a586c0654f51496aae36666b9e03df8116357116 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 10:27:48 -0400 Subject: [PATCH 07/11] Fix CMake include --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9226b66..1b113fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -626,6 +626,9 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfig.cmake.in # Generate the config file for the installation tree. + +include(WriteBasicPackageVersionFile) + write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonVersionConfig.cmake" VERSION ${PROJECT_VERSION} From fe7873e96324701648d70c3f4f69e2272219016f Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 10:37:15 -0400 Subject: [PATCH 08/11] Fix package version config generation --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b113fb..de6aa61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,7 +77,7 @@ set(JANSSON_TEMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/tmp) # 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) +if (WIN32 AND NOT CMAKE_DEBUG_POSTFIX) set(CMAKE_DEBUG_POSTFIX "_d") endif (WIN32) @@ -627,11 +627,12 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfig.cmake.in # Generate the config file for the installation tree. -include(WriteBasicPackageVersionFile) +include(CMakePackageConfigHelpers) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonVersionConfig.cmake" - VERSION ${PROJECT_VERSION} + VERSION ${JANSSON_VERSION} + COMPATIBILITY ExactVersion ) configure_package_config_file( From 92760bb363505bdff5fd6dc79508fe34e4481bea Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 10:39:49 -0400 Subject: [PATCH 09/11] Remove warning --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de6aa61..ce2c93f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ set(JANSSON_TEMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/tmp) # same build-tree on Windows (MSVC). if (WIN32 AND NOT CMAKE_DEBUG_POSTFIX) set(CMAKE_DEBUG_POSTFIX "_d") -endif (WIN32) +endif() # This is how I thought it should go # set (JANSSON_VERSION "2.3.1") From bb71db204f303fc07de4f99e22f2bd7eb5d7025c Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 10:43:38 -0400 Subject: [PATCH 10/11] Fix output file name for version config --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce2c93f..7159db4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -630,7 +630,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfig.cmake.in include(CMakePackageConfigHelpers) write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonVersionConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/janssonConfigVersion.cmake" VERSION ${JANSSON_VERSION} COMPATIBILITY ExactVersion ) From 2c98c30a02e0d8ba004f9db7005dc7fbd9a90f1b Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Sun, 11 Mar 2018 10:51:43 -0400 Subject: [PATCH 11/11] Stop using absolute paths --- CMakeLists.txt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7159db4..305efbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -607,12 +607,9 @@ set(VERSION ${JANSSON_DISPLAY_VERSION}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jansson.pc.in ${CMAKE_CURRENT_BINARY_DIR}/jansson.pc @ONLY) -# Make sure the paths are absolute. +# Make sure the paths are relative. 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() # Generate the config file for the build-tree. @@ -621,12 +618,11 @@ set(JANSSON__INCLUDE_DIRS "${CMAKE_CURRENT_BINARY_DIR}/include") set(JANSSON_INCLUDE_DIRS ${JANSSON__INCLUDE_DIRS} CACHE PATH "Jansson include directories") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/janssonConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/janssonConfig.cmake - @ONLY) + ${CMAKE_CURRENT_BINARY_DIR}/janssonConfig.cmake + @ONLY) # Generate the config file for the installation tree. - include(CMakePackageConfigHelpers) write_basic_package_version_file( @@ -669,7 +665,7 @@ if (JANSSON_INSTALL) # Install exports for the install-tree. install(EXPORT janssonTargets - NAMESPACE jansson + NAMESPACE jansson:: DESTINATION "${JANSSON_INSTALL_CMAKE_DIR}") endif()