2021-05-10 01:47:21 +08:00
# DEPRECATED BY ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup
2020-12-02 05:37:26 +08:00
#[===[.md:
# vcpkg_fixup_cmake_targets
M e r g e r e l e a s e a n d d e b u g C M a k e t a r g e t s a n d c o n f i g s t o s u p p o r t m u l t i c o n f i g g e n e r a t o r s .
A d d i t i o n a l l y c o r r e c t s c o m m o n i s s u e s w i t h t a r g e t s , s u c h a s a b s o l u t e p a t h s a n d i n c o r r e c t l y p l a c e d b i n a r i e s .
## Usage
` ` ` c m a k e
2021-04-01 03:47:35 +08:00
vcpkg_fixup_cmake_targets ( [CONFIG_PATH <share/ ${ PORT } >]
[ T A R G E T _ P A T H < s h a r e / $ { P O R T } > ]
[ T O O L S _ P A T H < t o o l s / $ { P O R T } > ]
[ D O _ N O T _ D E L E T E _ P A R E N T _ C O N F I G _ P A T H ] )
2020-12-02 05:37:26 +08:00
` ` `
## Parameters
### CONFIG_PATH
S u b p a t h c u r r e n t l y c o n t a i n i n g ` * . c m a k e ` f i l e s subdirectory ( like `lib/cmake/ ${ PORT } ` ) . S h o u l d b e r e l a t i v e t o ` $ { C U R R E N T _ P A C K A G E S _ D I R } ` .
D e f a u l t s t o ` s h a r e / $ { P O R T } ` .
### TARGET_PATH
S u b p a t h t o w h i c h t h e a b o v e ` * . c m a k e ` f i l e s s h o u l d b e m o v e d . S h o u l d b e r e l a t i v e t o ` $ { C U R R E N T _ P A C K A G E S _ D I R } ` .
T h i s n e e d s t o b e s p e c i f i e d i f t h e p o r t n a m e d i f f e r s f r o m t h e ` find_package ( ) ` n a m e .
D e f a u l t s t o ` s h a r e / $ { P O R T } ` .
2021-03-01 05:17:19 +08:00
### DO_NOT_DELETE_PARENT_CONFIG_PATH
2020-12-02 05:37:26 +08:00
B y d e f a u l t t h e p a r e n t d i r e c t o r y o f C O N F I G _ P A T H i s r e m o v e d i f i t i s n a m e d " c m a k e " .
P a s s i n g t h i s o p t i o n d i s a b l e s u c h b e h a v i o r , a s i t i s c o n v e n i e n t f o r p o r t s t h a t i n s t a l l
m o r e t h a n o n e C M a k e p a c k a g e c o n f i g u r a t i o n f i l e .
### NO_PREFIX_CORRECTION
D i s a b l e s t h e c o r r e c t i o n o f _ I M P O R T _ P R E F I X d o n e b y v c p k g d u e t o m o v i n g t h e t a r g e t s .
C u r r e n t l y t h e c o r r e c t i o n d o e s n o t t a k e i n t o a c c o u n t h o w t h e f i l e s a r e m o v e d a n d a p p l i e s
I r a t h e r s i m p l y c o r r e c t i o n w h i c h i n s o m e c a s e s w i l l y i e l d t h e w r o n g r e s u l t s .
2021-04-01 03:47:35 +08:00
### TOOLS_PATH
D e f i n e t h e b a s e p a t h t o t o o l s . D e f a u l t : ` t o o l s / < P O R T > `
2020-12-02 05:37:26 +08:00
## Notes
T r a n s f o r m a l l ` / d e b u g / < C O N F I G _ P A T H > / * t a r g e t s - d e b u g . c m a k e ` f i l e s a n d m o v e t h e m t o ` / < T A R G E T _ P A T H > ` .
R e m o v e s a l l ` / d e b u g / < C O N F I G _ P A T H > / * t a r g e t s . c m a k e ` a n d ` / d e b u g / < C O N F I G _ P A T H > / * c o n f i g . c m a k e ` .
2021-04-01 03:47:35 +08:00
T r a n s f o r m a l l r e f e r e n c e s m a t c h i n g ` / b i n / * . e x e ` t o ` / $ { T O O L S _ P A T H } / * . e x e ` o n W i n d o w s .
T r a n s f o r m a l l r e f e r e n c e s m a t c h i n g ` / b i n / * ` t o ` / $ { T O O L S _ P A T H } / * ` o n o t h e r p l a t f o r m s .
2020-12-02 05:37:26 +08:00
F i x ` $ { _ I M P O R T _ P R E F I X } ` i n a u t o g e n e r a t e d t a r g e t s t o b e o n e f o l d e r d e e p e r .
R e p l a c e ` $ { C U R R E N T _ I N S T A L L E D _ D I R } ` w i t h ` $ { _ I M P O R T _ P R E F I X } ` i n c o n f i g s a n d t a r g e t s .
## Examples
* [ c o n c u r r e n t q u e u e ] ( h t t p s : / / g i t h u b . c o m / M i c r o s o f t / v c p k g / b l o b / m a s t e r / p o r t s / c o n c u r r e n t q u e u e / p o r t f i l e . c m a k e )
* [ c u r l ] ( h t t p s : / / g i t h u b . c o m / M i c r o s o f t / v c p k g / b l o b / m a s t e r / p o r t s / c u r l / p o r t f i l e . c m a k e )
* [ n l o h m a n n - j s o n ] ( h t t p s : / / g i t h u b . c o m / M i c r o s o f t / v c p k g / b l o b / m a s t e r / p o r t s / n l o h m a n n - j s o n / p o r t f i l e . c m a k e )
#]===]
2017-05-03 11:34:11 +08:00
function ( vcpkg_fixup_cmake_targets )
2021-03-01 05:17:19 +08:00
if ( Z_VCPKG_CMAKE_CONFIG_FIXUP_GUARD )
message ( FATAL_ERROR "The ${PORT} port already depends on vcpkg-cmake-config; using both vcpkg-cmake-config and vcpkg_fixup_cmake_targets in the same port is unsupported." )
endif ( )
2017-05-03 11:34:11 +08:00
2021-04-01 03:47:35 +08:00
cmake_parse_arguments ( PARSE_ARGV 0 arg "DO_NOT_DELETE_PARENT_CONFIG_PATH" "CONFIG_PATH;TARGET_PATH;NO_PREFIX_CORRECTION;TOOLS_PATH" "" )
2021-03-01 05:17:19 +08:00
if ( arg_UNPARSED_ARGUMENTS )
message ( FATAL_ERROR "vcpkg_fixup_cmake_targets was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}" )
2017-06-21 07:19:36 +08:00
endif ( )
2021-03-01 05:17:19 +08:00
if ( NOT arg_TARGET_PATH )
set ( arg_TARGET_PATH share/ ${ PORT } )
2018-01-04 12:11:35 +08:00
endif ( )
2021-04-01 03:47:35 +08:00
if ( NOT arg_TOOLS_PATH )
set ( arg_TOOLS_PATH tools/ ${ PORT } )
endif ( )
2018-01-04 12:11:35 +08:00
2020-08-01 02:13:45 +08:00
string ( REPLACE "." "\\." EXECUTABLE_SUFFIX "${VCPKG_TARGET_EXECUTABLE_SUFFIX}" )
2019-06-25 14:21:30 +08:00
2021-03-01 05:17:19 +08:00
set ( DEBUG_SHARE ${ CURRENT_PACKAGES_DIR } /debug/ ${ arg_TARGET_PATH } )
set ( RELEASE_SHARE ${ CURRENT_PACKAGES_DIR } / ${ arg_TARGET_PATH } )
2017-05-03 11:34:11 +08:00
2021-03-01 05:17:19 +08:00
if ( arg_CONFIG_PATH AND NOT RELEASE_SHARE STREQUAL "${CURRENT_PACKAGES_DIR}/${arg_CONFIG_PATH}" )
if ( arg_CONFIG_PATH STREQUAL "share" )
2018-04-18 07:11:18 +08:00
file ( RENAME ${ CURRENT_PACKAGES_DIR } /debug/share ${ CURRENT_PACKAGES_DIR } /debug/share2 )
file ( RENAME ${ CURRENT_PACKAGES_DIR } /share ${ CURRENT_PACKAGES_DIR } /share2 )
2021-03-01 05:17:19 +08:00
set ( arg_CONFIG_PATH share2 )
2018-04-18 07:11:18 +08:00
endif ( )
2021-03-01 05:17:19 +08:00
set ( DEBUG_CONFIG ${ CURRENT_PACKAGES_DIR } /debug/ ${ arg_CONFIG_PATH } )
set ( RELEASE_CONFIG ${ CURRENT_PACKAGES_DIR } / ${ arg_CONFIG_PATH } )
2017-11-26 07:25:18 +08:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
if ( NOT EXISTS ${ DEBUG_CONFIG } )
message ( FATAL_ERROR "'${DEBUG_CONFIG}' does not exist." )
endif ( )
2017-05-11 06:08:52 +08:00
2018-04-18 07:11:18 +08:00
# This roundabout handling enables CONFIG_PATH share
2017-11-26 07:25:18 +08:00
file ( MAKE_DIRECTORY ${ DEBUG_SHARE } )
file ( GLOB FILES ${ DEBUG_CONFIG } /* )
file ( COPY ${ FILES } DESTINATION ${ DEBUG_SHARE } )
file ( REMOVE_RECURSE ${ DEBUG_CONFIG } )
endif ( )
2017-10-27 13:34:54 +08:00
file ( GLOB FILES ${ RELEASE_CONFIG } /* )
file ( COPY ${ FILES } DESTINATION ${ RELEASE_SHARE } )
file ( REMOVE_RECURSE ${ RELEASE_CONFIG } )
2017-05-11 06:08:52 +08:00
2017-11-26 07:25:18 +08:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
get_filename_component ( DEBUG_CONFIG_DIR_NAME ${ DEBUG_CONFIG } NAME )
2017-05-11 06:08:52 +08:00
string ( TOLOWER "${DEBUG_CONFIG_DIR_NAME}" DEBUG_CONFIG_DIR_NAME )
2021-03-01 05:17:19 +08:00
if ( DEBUG_CONFIG_DIR_NAME STREQUAL "cmake" AND NOT arg_DO_NOT_DELETE_PARENT_CONFIG_PATH )
2017-11-26 07:25:18 +08:00
file ( REMOVE_RECURSE ${ DEBUG_CONFIG } )
else ( )
get_filename_component ( DEBUG_CONFIG_PARENT_DIR ${ DEBUG_CONFIG } DIRECTORY )
get_filename_component ( DEBUG_CONFIG_DIR_NAME ${ DEBUG_CONFIG_PARENT_DIR } NAME )
string ( TOLOWER "${DEBUG_CONFIG_DIR_NAME}" DEBUG_CONFIG_DIR_NAME )
2021-03-01 05:17:19 +08:00
if ( DEBUG_CONFIG_DIR_NAME STREQUAL "cmake" AND NOT arg_DO_NOT_DELETE_PARENT_CONFIG_PATH )
2017-11-26 07:25:18 +08:00
file ( REMOVE_RECURSE ${ DEBUG_CONFIG_PARENT_DIR } )
endif ( )
2017-05-11 06:08:52 +08:00
endif ( )
endif ( )
get_filename_component ( RELEASE_CONFIG_DIR_NAME ${ RELEASE_CONFIG } NAME )
string ( TOLOWER "${RELEASE_CONFIG_DIR_NAME}" RELEASE_CONFIG_DIR_NAME )
2021-03-01 05:17:19 +08:00
if ( RELEASE_CONFIG_DIR_NAME STREQUAL "cmake" AND NOT arg_DO_NOT_DELETE_PARENT_CONFIG_PATH )
2017-05-11 06:08:52 +08:00
file ( REMOVE_RECURSE ${ RELEASE_CONFIG } )
else ( )
get_filename_component ( RELEASE_CONFIG_PARENT_DIR ${ RELEASE_CONFIG } DIRECTORY )
get_filename_component ( RELEASE_CONFIG_DIR_NAME ${ RELEASE_CONFIG_PARENT_DIR } NAME )
string ( TOLOWER "${RELEASE_CONFIG_DIR_NAME}" RELEASE_CONFIG_DIR_NAME )
2021-03-01 05:17:19 +08:00
if ( RELEASE_CONFIG_DIR_NAME STREQUAL "cmake" AND NOT arg_DO_NOT_DELETE_PARENT_CONFIG_PATH )
2017-05-11 06:08:52 +08:00
file ( REMOVE_RECURSE ${ RELEASE_CONFIG_PARENT_DIR } )
endif ( )
endif ( )
endif ( )
2017-11-26 07:25:18 +08:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
2018-04-18 07:11:18 +08:00
if ( NOT EXISTS "${DEBUG_SHARE}" )
2017-11-26 07:25:18 +08:00
message ( FATAL_ERROR "'${DEBUG_SHARE}' does not exist." )
endif ( )
2017-05-03 11:34:11 +08:00
endif ( )
2018-03-25 04:08:06 +08:00
file ( GLOB_RECURSE UNUSED_FILES
2017-05-23 03:10:20 +08:00
" $ { D E B U G _ S H A R E } / * [ T t ] a r g e t s . c m a k e "
" $ { D E B U G _ S H A R E } / * [ C c ] o n f i g . c m a k e "
" $ { D E B U G _ S H A R E } / * [ C c ] o n f i g V e r s i o n . c m a k e "
" $ { D E B U G _ S H A R E } / * [ C c ] o n f i g - v e r s i o n . c m a k e "
)
2017-06-28 02:24:31 +08:00
if ( UNUSED_FILES )
file ( REMOVE ${ UNUSED_FILES } )
endif ( )
2017-05-03 11:34:11 +08:00
2018-03-25 04:08:06 +08:00
file ( GLOB_RECURSE RELEASE_TARGETS
2018-01-18 17:28:56 +08:00
" $ { R E L E A S E _ S H A R E } / * - r e l e a s e . c m a k e "
2017-05-23 03:10:20 +08:00
)
2018-03-25 04:08:06 +08:00
foreach ( RELEASE_TARGET IN LISTS RELEASE_TARGETS )
2017-05-07 14:02:25 +08:00
file ( READ ${ RELEASE_TARGET } _contents )
2017-10-19 23:53:59 +08:00
string ( REPLACE "${CURRENT_INSTALLED_DIR}" "\${_IMPORT_PREFIX}" _contents "${_contents}" )
2021-04-01 03:47:35 +08:00
string ( REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \" ]+ ${ EXECUTABLE_SUFFIX } ) " " \ $ { _ I M P O R T _ P R E F I X } / $ { a r g _ T O O L S _ P A T H } / \ \ 1 " _ c o n t e n t s " $ { _ c o n t e n t s } " )
2017-05-07 14:02:25 +08:00
file ( WRITE ${ RELEASE_TARGET } "${_contents}" )
endforeach ( )
2017-11-26 07:25:18 +08:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
2018-03-25 04:08:06 +08:00
file ( GLOB_RECURSE DEBUG_TARGETS
2018-01-18 17:28:56 +08:00
" $ { D E B U G _ S H A R E } / * - d e b u g . c m a k e "
2017-11-26 07:25:18 +08:00
)
2018-03-25 04:08:06 +08:00
foreach ( DEBUG_TARGET IN LISTS DEBUG_TARGETS )
file ( RELATIVE_PATH DEBUG_TARGET_REL "${DEBUG_SHARE}" "${DEBUG_TARGET}" )
2017-11-26 07:25:18 +08:00
file ( READ ${ DEBUG_TARGET } _contents )
string ( REPLACE "${CURRENT_INSTALLED_DIR}" "\${_IMPORT_PREFIX}" _contents "${_contents}" )
2021-04-01 03:47:35 +08:00
string ( REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \" ;]+ ${ EXECUTABLE_SUFFIX } ) " " \ $ { _ I M P O R T _ P R E F I X } / $ { a r g _ T O O L S _ P A T H } / \ \ 1 " _ c o n t e n t s " $ { _ c o n t e n t s } " )
2017-11-26 07:25:18 +08:00
string ( REPLACE "\${_IMPORT_PREFIX}/lib" "\${_IMPORT_PREFIX}/debug/lib" _contents "${_contents}" )
string ( REPLACE "\${_IMPORT_PREFIX}/bin" "\${_IMPORT_PREFIX}/debug/bin" _contents "${_contents}" )
2018-03-25 04:08:06 +08:00
file ( WRITE ${ RELEASE_SHARE } / ${ DEBUG_TARGET_REL } "${_contents}" )
2017-11-26 07:25:18 +08:00
file ( REMOVE ${ DEBUG_TARGET } )
endforeach ( )
endif ( )
2017-05-03 11:34:11 +08:00
2021-03-01 05:17:19 +08:00
#Fix ${_IMPORT_PREFIX} in cmake generated targets and configs;
2019-03-01 15:53:42 +08:00
#Since those can be renamed we have to check in every *.cmake
file ( GLOB_RECURSE MAIN_CMAKES "${RELEASE_SHARE}/*.cmake" )
2020-11-26 04:06:25 +08:00
2019-03-01 15:53:42 +08:00
foreach ( MAIN_CMAKE IN LISTS MAIN_CMAKES )
file ( READ ${ MAIN_CMAKE } _contents )
2020-11-26 04:06:25 +08:00
#This correction is not correct for all cases. To make it correct for all cases it needs to consider
2021-03-01 05:17:19 +08:00
#original folder deepness to CURRENT_PACKAGES_DIR in comparison to the moved to folder deepness which
#is always at least (>=) 2, e.g. share/${PORT}. Currently the code assumes it is always 2 although
2020-11-26 04:06:25 +08:00
#this requirement is only true for the *Config.cmake. The targets are not required to be in the same
#folder as the *Config.cmake!
2021-03-01 05:17:19 +08:00
if ( NOT arg_NO_PREFIX_CORRECTION )
2020-11-26 04:06:25 +08:00
string ( REGEX REPLACE
" g e t _ f i l e n a m e _ c o m p o n e n t \ \ ( _ I M P O R T _ P R E F I X \ " \ \ \ $ { C M A K E _ C U R R E N T _ L I S T _ F I L E } \ " P A T H \ \ ) ( \ n g e t _ f i l e n a m e _ c o m p o n e n t \ \ ( _ I M P O R T _ P R E F I X \ " \ \ \ $ { _ I M P O R T _ P R E F I X } \ " P A T H \ \ ) ) * "
" get_filename_component ( _IMPORT_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH ) \ nget_filename_component ( _IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH ) \ nget_filename_component ( _IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH ) "
_ c o n t e n t s " $ { _ c o n t e n t s } " ) # see #1044 for details why this replacement is necessary. See #4782 why it must be a regex.
string ( REGEX REPLACE
" g e t _ f i l e n a m e _ c o m p o n e n t \ \ ( P A C K A G E _ P R E F I X _ D I R \ " \ \ \ $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / \ \ . \ \ . / ( \ \ . \ \ . / ) * \ " A B S O L U T E \ \ ) "
" get_filename_component ( PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/../../\" ABSOLUTE ) "
_ c o n t e n t s " $ { _ c o n t e n t s } " )
string ( REGEX REPLACE
" g e t _ f i l e n a m e _ c o m p o n e n t \ \ ( P A C K A G E _ P R E F I X _ D I R \ " \ \ \ $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / \ \ . \ \ . ( ( \ \ \ \ | / ) \ \ . \ \ . ) * \ " A B S O L U T E \ \ ) "
" get_filename_component ( PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/../../\" ABSOLUTE ) "
_ c o n t e n t s " $ { _ c o n t e n t s } " ) # This is a meson-related workaround, see https://github.com/mesonbuild/meson/issues/6955
endif ( )
2019-03-01 15:53:42 +08:00
#Fix wrongly absolute paths to install dir with the correct dir using ${_IMPORT_PREFIX}
2020-11-26 04:06:25 +08:00
#This happens if vcpkg built libraries are directly linked to a target instead of using
#an imported target for it. We could add more logic here to identify defect target files.
#Since the replacement here in a multi config build always requires a generator expression
#in front of the absoulte path to ${CURRENT_INSTALLED_DIR}. So the match should always be at
2021-03-01 05:17:19 +08:00
#least >:${CURRENT_INSTALLED_DIR}.
2020-11-26 04:06:25 +08:00
#In general the following generator expressions should be there:
#\$<\$<CONFIG:DEBUG>:${CURRENT_INSTALLED_DIR}/debug/lib/somelib>
#and/or
#\$<\$<NOT:\$<CONFIG:DEBUG>>:${CURRENT_INSTALLED_DIR}/lib/somelib>
#with ${CURRENT_INSTALLED_DIR} being fully expanded
2019-03-01 15:53:42 +08:00
string ( REPLACE "${CURRENT_INSTALLED_DIR}" [[ ${ _IMPORT_PREFIX } ]] _contents "${_contents}" )
file ( WRITE ${ MAIN_CMAKE } "${_contents}" )
2017-06-21 06:20:23 +08:00
endforeach ( )
2018-01-04 12:11:35 +08:00
# Remove /debug/<target_path>/ if it's empty.
2017-05-03 11:34:11 +08:00
file ( GLOB_RECURSE REMAINING_FILES "${DEBUG_SHARE}/*" )
if ( NOT REMAINING_FILES )
file ( REMOVE_RECURSE ${ DEBUG_SHARE } )
endif ( )
# Remove /debug/share/ if it's empty.
file ( GLOB_RECURSE REMAINING_FILES "${CURRENT_PACKAGES_DIR}/debug/share/*" )
if ( NOT REMAINING_FILES )
file ( REMOVE_RECURSE ${ CURRENT_PACKAGES_DIR } /debug/share )
endif ( )
2018-03-12 14:04:52 +08:00
# Patch out any remaining absolute references
file ( TO_CMAKE_PATH "${CURRENT_PACKAGES_DIR}" CMAKE_CURRENT_PACKAGES_DIR )
file ( GLOB CMAKE_FILES ${ RELEASE_SHARE } /*.cmake )
foreach ( CMAKE_FILE IN LISTS CMAKE_FILES )
file ( READ ${ CMAKE_FILE } _contents )
string ( REPLACE "${CMAKE_CURRENT_PACKAGES_DIR}" "\${CMAKE_CURRENT_LIST_DIR}/../.." _contents "${_contents}" )
file ( WRITE ${ CMAKE_FILE } "${_contents}" )
endforeach ( )
2017-05-03 11:34:11 +08:00
endfunction ( )
2021-08-21 05:46:02 +08:00