From 1c3a20de50dcc02620a804fb67a10d3e38285023 Mon Sep 17 00:00:00 2001 From: Yu Xiaolei Date: Tue, 4 Nov 2014 12:44:48 +0800 Subject: [PATCH 1/2] Allow customization of component install dirs --- CMakeLists.txt | 10 ++++++++++ include/CMakeLists.txt | 2 +- src/lib_json/CMakeLists.txt | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee2a8bfda..806e726e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,16 @@ IF(NOT WIN32) ENDIF(NOT CMAKE_BUILD_TYPE) ENDIF(NOT WIN32) +SET(RUNTIME_INSTALL_DIR lib + CACHE PATH "Install dir for executables and dlls") +SET(ARCHIVE_INSTALL_DIR lib + CACHE PATH "Install dir for static libraries") +SET(LIBRARY_INSTALL_DIR lib + CACHE PATH "Install dir for shared libraries") +SET(INCLUDE_INSTALL_DIR include + CACHE PATH "Install dir for headers") +MARK_AS_ADVANCED( RUNTIME_INSTALL_DIR ARCHIVE_INSTALL_DIR INCLUDE_INSTALL_DIR ) + # This ensures shared DLL are in the same dir as executable on Windows. # Put all executables / libraries are in a project global directory. SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 7d832a00b..7dde10d6f 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,2 +1,2 @@ FILE(GLOB INCLUDE_FILES "json/*.h") -INSTALL(FILES ${INCLUDE_FILES} DESTINATION include/json) +INSTALL(FILES ${INCLUDE_FILES} DESTINATION ${INCLUDE_INSTALL_DIR}/json) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 16036d134..738ba649a 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -41,7 +41,7 @@ SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSI # Install instructions for this target INSTALL( TARGETS jsoncpp_lib - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} + LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${ARCHIVE_INSTALL_DIR} ) From dc84d96a49cd034957c8bca668012a279b8124e5 Mon Sep 17 00:00:00 2001 From: Yu Xiaolei Date: Tue, 4 Nov 2014 16:33:25 +0800 Subject: [PATCH 2/2] Add CMake package file generation support --- CMakeLists.txt | 11 ++++++++++- src/lib_json/CMakeLists.txt | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 806e726e4..0eeb1ffd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ OPTION(JSONCPP_WITH_TESTS "Compile and run JsonCpp test executables" ON) OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON) OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF) OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON) +OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF) # Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix IF(NOT WIN32) @@ -24,7 +25,9 @@ SET(LIBRARY_INSTALL_DIR lib CACHE PATH "Install dir for shared libraries") SET(INCLUDE_INSTALL_DIR include CACHE PATH "Install dir for headers") -MARK_AS_ADVANCED( RUNTIME_INSTALL_DIR ARCHIVE_INSTALL_DIR INCLUDE_INSTALL_DIR ) +SET(PACKAGE_INSTALL_DIR lib/cmake + CACHE PATH "Install dir for cmake package config files") +MARK_AS_ADVANCED( RUNTIME_INSTALL_DIR ARCHIVE_INSTALL_DIR INCLUDE_INSTALL_DIR PACKAGE_INSTALL_DIR ) # This ensures shared DLL are in the same dir as executable on Windows. # Put all executables / libraries are in a project global directory. @@ -101,6 +104,12 @@ IF(JSONCPP_WITH_PKGCONFIG_SUPPORT) DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") ENDIF(JSONCPP_WITH_PKGCONFIG_SUPPORT) +IF(JSONCPP_WITH_CMAKE_PACKAGE) + INSTALL(EXPORT jsoncpp + DESTINATION ${PACKAGE_INSTALL_DIR}/jsoncpp + FILE jsoncppConfig.cmake) +ENDIF(JSONCPP_WITH_CMAKE_PACKAGE) + # Build the different applications ADD_SUBDIRECTORY( src ) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 738ba649a..418044deb 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -40,7 +40,17 @@ SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp ) SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR} ) # Install instructions for this target -INSTALL( TARGETS jsoncpp_lib +IF(JSONCPP_WITH_CMAKE_PACKAGE) + TARGET_INCLUDE_DIRECTORIES( jsoncpp_lib + PUBLIC $ + $ + ) + SET(INSTALL_EXPORT EXPORT jsoncpp) +ELSE(JSONCPP_WITH_CMAKE_PACKAGE) + SET(INSTALL_EXPORT) +ENDIF(JSONCPP_WITH_CMAKE_PACKAGE) + +INSTALL( TARGETS jsoncpp_lib ${INSTALL_EXPORT} RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} ARCHIVE DESTINATION ${ARCHIVE_INSTALL_DIR}