From a5dd0c9d427d66f7e361b0aa714a0a41b65ae4f0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 18 Dec 2015 09:57:55 -0500 Subject: [PATCH] Add option to use a system-installed KWIML Do not activate it with the general use-system-libs options for now because KWIML is not commonly distributed or available. --- CMakeLists.txt | 25 ++++++++++++++++++++++--- Source/CMakeLists.txt | 1 + Utilities/cmThirdParty.h.in | 1 + Utilities/cm_kwiml.h | 11 +++++++++-- Utilities/cmjsoncpp/CMakeLists.txt | 1 + bootstrap | 14 ++++++++++++++ 6 files changed, 48 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 932d07e7b..9381f357f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,8 +138,13 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES) option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}") option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}") + # For now use system KWIML only if explicitly requested rather + # than activating via the general system libs options. + option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF) + mark_as_advanced(CMAKE_USE_SYSTEM_KWIML) + # Mention to the user what system libraries are being used. - foreach(util ${UTILITIES}) + foreach(util ${UTILITIES} KWIML) if(CMAKE_USE_SYSTEM_${util}) message(STATUS "Using system-installed ${util}") endif() @@ -270,6 +275,20 @@ macro (CMAKE_BUILD_UTILITIES) # (a macro defined in this file) CMAKE_HANDLE_SYSTEM_LIBRARIES() + if(CMAKE_USE_SYSTEM_KWIML) + find_package(KWIML 1.0) + if(NOT KWIML_FOUND) + message(FATAL_ERROR "CMAKE_USE_SYSTEM_KWIML is ON but KWIML is not found!") + endif() + set(CMake_KWIML_LIBRARIES kwiml::kwiml) + else() + set(CMake_KWIML_LIBRARIES "") + if(BUILD_TESTING) + set(KWIML_TEST_ENABLE 1) + endif() + add_subdirectory(Utilities/KWIML) + endif() + #--------------------------------------------------------------------- # Build zlib library for Curl, CMake, and CTest. set(CMAKE_ZLIB_HEADER "cm_zlib.h") @@ -538,10 +557,10 @@ if("x${CMAKE_TESTS_CDASH_SERVER}" STREQUAL "x") set(CMAKE_TESTS_CDASH_SERVER "http://open.cdash.org") endif() -if(BUILD_TESTING) +if(CMake_TEST_EXTERNAL_CMAKE) set(KWIML_TEST_ENABLE 1) + add_subdirectory(Utilities/KWIML) endif() -add_subdirectory(Utilities/KWIML) if(NOT CMake_TEST_EXTERNAL_CMAKE) # build the utilities (a macro defined in this file) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index f23331bec..ab70568d3 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -566,6 +566,7 @@ target_link_libraries(CMakeLib cmsys ${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES} ${CMAKE_CURL_LIBRARIES} ${CMAKE_JSONCPP_LIBRARIES} + ${CMake_KWIML_LIBRARIES} ) # On Apple we need CoreFoundation diff --git a/Utilities/cmThirdParty.h.in b/Utilities/cmThirdParty.h.in index 0cb6809c3..4c1177ca8 100644 --- a/Utilities/cmThirdParty.h.in +++ b/Utilities/cmThirdParty.h.in @@ -15,6 +15,7 @@ /* Whether CMake is using its own utility libraries. */ #cmakedefine CMAKE_USE_SYSTEM_CURL #cmakedefine CMAKE_USE_SYSTEM_EXPAT +#cmakedefine CMAKE_USE_SYSTEM_KWIML #cmakedefine CMAKE_USE_SYSTEM_ZLIB #cmakedefine CMAKE_USE_SYSTEM_BZIP2 #cmakedefine CMAKE_USE_SYSTEM_LIBARCHIVE diff --git a/Utilities/cm_kwiml.h b/Utilities/cm_kwiml.h index 2e1a10806..ab2b80b3c 100644 --- a/Utilities/cm_kwiml.h +++ b/Utilities/cm_kwiml.h @@ -12,7 +12,14 @@ #ifndef cm_kwiml_h #define cm_kwiml_h -#include "KWIML/include/kwiml/abi.h" -#include "KWIML/include/kwiml/int.h" +/* Use the KWIML library configured for CMake. */ +#include "cmThirdParty.h" +#ifdef CMAKE_USE_SYSTEM_KWIML +# include +# include +#else +# include "KWIML/include/kwiml/abi.h" +# include "KWIML/include/kwiml/int.h" +#endif #endif diff --git a/Utilities/cmjsoncpp/CMakeLists.txt b/Utilities/cmjsoncpp/CMakeLists.txt index 1c863f855..d0114e711 100644 --- a/Utilities/cmjsoncpp/CMakeLists.txt +++ b/Utilities/cmjsoncpp/CMakeLists.txt @@ -23,3 +23,4 @@ include_directories( ) add_library(cmjsoncpp ${JSONCPP_SOURCES}) +target_link_libraries(cmjsoncpp ${CMake_KWIML_LIBRARIES}) diff --git a/bootstrap b/bootstrap index 860b5e49e..9e3036366 100755 --- a/bootstrap +++ b/bootstrap @@ -450,6 +450,18 @@ cmake_error() exit ${res} } +cmake_generate_file () +{ + OUTFILE="$1" + CONTENT="$2" + echo "$CONTENT" > "$OUTFILE.tmp" + if "${_diff}" "$OUTFILE.tmp" "$OUTFILE" > /dev/null 2> /dev/null ; then + rm -f "$OUTFILE.tmp" + else + mv -f "$OUTFILE.tmp" "$OUTFILE" + fi +} + # Replace KWSYS_NAMESPACE with cmsys cmake_replace_string () { @@ -1270,6 +1282,8 @@ for a in ${KWSYS_FILES}; do "${cmake_bootstrap_dir}/cmsys/${a}" KWSYS_NAMESPACE cmsys done +cmake_generate_file "${cmake_bootstrap_dir}/cmThirdParty.h" "" + # Generate Makefile dep="cmConfigure.h cmsys/*.hxx cmsys/*.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h" objs=""