Skip to content

Commit

Permalink
CMake: allow absolute install paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nim65s committed May 28, 2024
1 parent c345d1c commit fdda562
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
21 changes: 13 additions & 8 deletions cmake/VISPGenerateConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@
# output: path_to_parent, the relative path to go from path_to_child to parent
# example: if input =lib/x86_64-linux-gnu, then output=../..
macro(get_path_to_parent path_to_child path_to_parent)
set(${path_to_parent} "")
set(input_ "${path_to_child}")
while(input_)
if(input_)
set(${path_to_parent} "${${path_to_parent}}../")
endif()
get_filename_component(input_ "${input_}" PATH)
endwhile(input_)
if(IS_ABSOLUTE ${path_to_child})
file(RELATIVE_PATH _path_to_parent "${path_to_child}" "${CMAKE_INSTALL_PREFIX}")
string(REGEX REPLACE "/$" "" ${path_to_parent} "${_path_to_parent}")
else()
set(${path_to_parent} "")
set(input_ "${path_to_child}")
while(input_)
if(input_)
set(${path_to_parent} "${${path_to_parent}}../")
endif()
get_filename_component(input_ "${input_}" PATH)
endwhile(input_)
endif()
endmacro()

# Here we determine the relative path from ./${VISP_LIB_INSTALL_PATH} to its parent folder
Expand Down
45 changes: 34 additions & 11 deletions cmake/VISPGenerateConfigScript.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,16 @@ else() # DEFINED CMAKE_HELPER_SCRIPT
# Updates VISP_SCRIPT_PC_LIBS (for visp.pc used by pkg-config)
#----------------------------------------------------------------------
set(exec_prefix "\${prefix}")
set(includedir "\${prefix}/${VISP_INC_INSTALL_PATH}")
set(libdir "\${prefix}/${VISP_LIB_INSTALL_PATH}")
if(IS_ABSOLUTE ${VISP_INC_INSTALL_PATH})
set(includedir "${VISP_INC_INSTALL_PATH}")
else()
set(includedir "\${prefix}/${VISP_INC_INSTALL_PATH}")
endif()
if(IS_ABSOLUTE ${VISP_LIB_INSTALL_PATH})
set(libdir "${VISP_LIB_INSTALL_PATH}")
else()
set(libdir "\${prefix}/${VISP_LIB_INSTALL_PATH}")
endif()

# prepend with ViSP own include dir
set(VISP_SCRIPT_PC_CFLAGS
Expand All @@ -356,18 +364,33 @@ else() # DEFINED CMAKE_HELPER_SCRIPT
vp_list_remove_separator(VISP_SCRIPT_PC_CFLAGS)

# prepend with ViSP own modules first
set(VISP_SCRIPT_PC_LIBS
"-L\${exec_prefix}/${VISP_LIB_INSTALL_PATH}"
"${_modules}"
)
if(IS_ABSOLUTE ${VISP_LIB_INSTALL_PATH})
set(VISP_SCRIPT_PC_LIBS
"-L${VISP_LIB_INSTALL_PATH}"
"${_modules}"
)
else()
set(VISP_SCRIPT_PC_LIBS
"-L\${exec_prefix}/${VISP_LIB_INSTALL_PATH}"
"${_modules}"
)
endif()
if(BUILD_SHARED_LIBS)
set(VISP_SCRIPT_PC_LIBS_PRIVATE "${_extra_opt}")
else()
set(VISP_SCRIPT_PC_LIBS_PRIVATE
"-L\${exec_prefix}/${VISP_3P_LIB_INSTALL_PATH}"
"${_3rdparty}"
"${_extra_opt}"
)
if(IS_ABSOLUTE ${VISP_3P_LIB_INSTALL_PATH})
set(VISP_SCRIPT_PC_LIBS_PRIVATE
"-L${VISP_3P_LIB_INSTALL_PATH}"
"${_3rdparty}"
"${_extra_opt}"
)
else()
set(VISP_SCRIPT_PC_LIBS_PRIVATE
"-L\${exec_prefix}/${VISP_3P_LIB_INSTALL_PATH}"
"${_3rdparty}"
"${_extra_opt}"
)
endif()
endif()

vp_list_remove_separator(VISP_SCRIPT_PC_LIBS)
Expand Down

0 comments on commit fdda562

Please sign in to comment.