From 5379ec5715ffc69252a0a6a20a5db579e21f9fa2 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 19 Apr 2012 10:26:48 +0000 Subject: [PATCH] [1.5] Fix computation of relative path from include/ to lib/ --- CMake/OpenJPEGConfig.cmake.in | 8 +++++++- CMakeLists.txt | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CMake/OpenJPEGConfig.cmake.in b/CMake/OpenJPEGConfig.cmake.in index 020ddfcc..00a98bd6 100644 --- a/CMake/OpenJPEGConfig.cmake.in +++ b/CMake/OpenJPEGConfig.cmake.in @@ -23,10 +23,16 @@ SET(OPENJPEG_BUILD_SHARED_LIBS "@BUILD_SHARED_LIBS@") SET(OPENJPEG_USE_FILE "@OPENJPEG_USE_FILE_CONFIG@") get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +# The following is inspired from: +# http://www.cmake.org/Wiki/CMake/Tutorials/Packaging#Packaging_and_Exporting +# However the following is difficult to handle: +# get_filename_component(myproj_INCLUDE_DIRS "${SELF_DIR}/../../include/myproj" ABSOLUTE) +# it asssumes a non multi-arch system, where 'include' is located '../include' from lib +# therefore we need to take into account the number of subdirs in OPENJPEG_INSTALL_LIB_DIR if(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake) # This is an install tree include(${SELF_DIR}/OpenJPEGTargets.cmake) - get_filename_component(OPENJPEG_INCLUDE_ROOT "${SELF_DIR}/../../@OPENJPEG_INSTALL_INCLUDE_DIR@" ABSOLUTE) + get_filename_component(OPENJPEG_INCLUDE_ROOT "${SELF_DIR}/@relative_parent@/@OPENJPEG_INSTALL_INCLUDE_DIR@" ABSOLUTE) set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG_INCLUDE_ROOT}) else(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake) diff --git a/CMakeLists.txt b/CMakeLists.txt index e796bd34..bc2d0988 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,18 @@ IF(NOT OPENJPEG_INSTALL_LIB_DIR) SET(OPENJPEG_INSTALL_LIB_DIR "lib") ENDIF(NOT OPENJPEG_INSTALL_LIB_DIR) +# The following will compute the amount of parent dir to go +# from include to lib. it works nicely with +# OPENJPEG_INSTALL_LIB_DIR=lib +# OPENJPEG_INSTALL_LIB_DIR=lib/ +# OPENJPEG_INSTALL_LIB_DIR=/lib +# OPENJPEG_INSTALL_LIB_DIR=lib/gnu-linux-x64 +STRING(REPLACE "/" ";" relative_to_lib ${OPENJPEG_INSTALL_LIB_DIR}) +set(relative_parent "..") +foreach( elem ${relative_to_lib}) + set( relative_parent "${relative_parent}/.." ) +endforeach() + IF(NOT OPENJPEG_INSTALL_SHARE_DIR) SET(OPENJPEG_INSTALL_SHARE_DIR "share") ENDIF(NOT OPENJPEG_INSTALL_SHARE_DIR)