2019-09-13 01:07:22 +08:00
function ( configure_qt )
cmake_parse_arguments ( _csc "" "SOURCE_PATH;TARGET_PLATFORM;HOST_PLATFORM;HOST_TOOLS_ROOT" "OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE" ${ ARGN } )
if ( NOT _csc_TARGET_PLATFORM )
message ( FATAL_ERROR "configure_qt requires a TARGET_PLATFORM argument." )
endif ( )
if ( DEFINED _csc_HOST_PLATFORM )
list ( APPEND _csc_OPTIONS -platform ${ _csc_HOST_PLATFORM } )
endif ( )
if ( DEFINED _csc_HOST_TOOLS_ROOT )
## vcpkg internal file struture assumed here!
message ( STATUS "Building Qt with prepared host tools from ${_csc_HOST_TOOLS_ROOT}!" )
vcpkg_add_to_path ( "${_csc_HOST_TOOLS_ROOT}/bin" )
vcpkg_add_to_path ( "${_csc_HOST_TOOLS_ROOT}" )
set ( EXT_BIN_DIR -external-hostbindir ${ _csc_HOST_TOOLS_ROOT } /bin ) # we only use release binaries for building
find_program ( QMAKE_COMMAND NAMES qmake PATHS ${ _csc_HOST_TOOLS_ROOT } /bin NO_DEFAULT_PATH )
set ( INVOKE "${QMAKE_COMMAND}" )
else ( )
if ( CMAKE_HOST_WIN32 )
set ( CONFIGURE_BAT "configure.bat" )
else ( )
set ( CONFIGURE_BAT "configure" )
endif ( )
set ( INVOKE "${_csc_SOURCE_PATH}/${CONFIGURE_BAT}" )
endif ( )
#Cleanup previous build folders
file ( REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" )
2022-09-13 04:30:47 +08:00
vcpkg_cmake_get_vars ( detected_file )
include ( "${detected_file}" )
function ( qmake_append_program var qmake_var value )
get_filename_component ( prog "${value}" NAME )
# QMake assumes everything is on PATH?
vcpkg_list ( APPEND ${ var } "${qmake_var}=${prog}" )
find_program ( ${ qmake_var } NAMES "${prog}" )
cmake_path ( COMPARE "${${qmake_var}}" EQUAL "${value}" correct_prog_on_path )
if ( NOT correct_prog_on_path AND NOT "${value}" MATCHES "|:" )
message ( FATAL_ERROR "Detect path mismatch for '${qmake_var}'. '${value}' is not the same as '${${qmake_var}}'. Please correct your PATH!" )
endif ( )
unset ( ${ qmake_var } )
unset ( ${ qmake_var } CACHE )
set ( ${ var } "${${var}}" PARENT_SCOPE )
endfunction ( )
# Setup Build tools
set ( qmake_build_tools "" )
qmake_append_program ( qmake_build_tools "QMAKE_CC" "${VCPKG_DETECTED_CMAKE_C_COMPILER}" )
qmake_append_program ( qmake_build_tools "QMAKE_CXX" "${VCPKG_DETECTED_CMAKE_CXX_COMPILER}" )
qmake_append_program ( qmake_build_tools "QMAKE_AR" "${VCPKG_DETECTED_CMAKE_AR}" )
qmake_append_program ( qmake_build_tools "QMAKE_RANLIB" "${VCPKG_DETECTED_CMAKE_RANLIB}" )
qmake_append_program ( qmake_build_tools "QMAKE_STRIP" "${VCPKG_DETECTED_CMAKE_STRIP}" )
qmake_append_program ( qmake_build_tools "QMAKE_NM" "${VCPKG_DETECTED_CMAKE_NM}" )
qmake_append_program ( qmake_build_tools "QMAKE_RC" "${VCPKG_DETECTED_CMAKE_RC_COMPILER}" )
qmake_append_program ( qmake_build_tools "QMAKE_MT" "${VCPKG_DETECTED_CMAKE_MT}" )
if ( NOT VCPKG_TARGET_IS_WINDOWS OR VCPKG_DETECTED_CMAKE_AR MATCHES "ar$" )
# This is the reason why users should probably use a
# customized qt.conf with more domain knowledge.
vcpkg_list ( APPEND qmake_build_tools "QMAKE_AR+=qc" )
endif ( )
if ( VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW )
qmake_append_program ( qmake_build_tools "QMAKE_LIB" "${VCPKG_DETECTED_CMAKE_AR}" )
qmake_append_program ( qmake_build_tools "QMAKE_LINK" "${VCPKG_DETECTED_CMAKE_LINKER}" )
else ( )
qmake_append_program ( qmake_build_tools "QMAKE_LINK" "${VCPKG_DETECTED_CMAKE_CXX_COMPILER}" )
qmake_append_program ( qmake_build_tools "QMAKE_LINK_SHLIB" "${VCPKG_DETECTED_CMAKE_CXX_COMPILER}" )
qmake_append_program ( qmake_build_tools "QMAKE_LINK_C" "${VCPKG_DETECTED_CMAKE_C_COMPILER}" )
qmake_append_program ( qmake_build_tools "QMAKE_LINK_C_SHLIB" "${VCPKG_DETECTED_CMAKE_C_COMPILER}" )
endif ( )
2019-09-13 01:07:22 +08:00
#Find and ad Perl to PATH
vcpkg_find_acquire_program ( PERL )
get_filename_component ( PERL_EXE_PATH ${ PERL } DIRECTORY )
vcpkg_add_to_path ( "${PERL_EXE_PATH}" )
if ( "${VCPKG_LIBRARY_LINKAGE}" STREQUAL "static" )
list ( APPEND _csc_OPTIONS -static )
else ( )
#list(APPEND _csc_OPTIONS_DEBUG -separate-debug-info)
endif ( )
2022-09-13 04:30:47 +08:00
2019-09-13 01:07:22 +08:00
if ( VCPKG_TARGET_IS_WINDOWS AND "${VCPKG_CRT_LINKAGE}" STREQUAL "static" )
list ( APPEND _csc_OPTIONS -static-runtime )
endif ( )
list ( APPEND _csc_OPTIONS_RELEASE -release )
list ( APPEND _csc_OPTIONS_DEBUG -debug )
#Replace with VCPKG variables if PR #7733 is merged
unset ( BUILDTYPES )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR "${VCPKG_BUILD_TYPE}" STREQUAL "debug" )
set ( _buildname "DEBUG" )
list ( APPEND BUILDTYPES ${ _buildname } )
set ( _short_name_ ${ _buildname } "dbg" )
set ( _path_suffix_ ${ _buildname } "/debug" )
2020-10-17 17:10:11 +08:00
set ( _build_type_ ${ _buildname } "debug" )
2019-09-13 01:07:22 +08:00
endif ( )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR "${VCPKG_BUILD_TYPE}" STREQUAL "release" )
set ( _buildname "RELEASE" )
list ( APPEND BUILDTYPES ${ _buildname } )
set ( _short_name_ ${ _buildname } "rel" )
set ( _path_suffix_ ${ _buildname } "" )
2020-10-17 17:10:11 +08:00
set ( _build_type_ ${ _buildname } "release" )
2019-09-13 01:07:22 +08:00
endif ( )
unset ( _buildname )
2020-10-17 17:10:11 +08:00
vcpkg_find_acquire_program ( PKGCONFIG )
set ( ENV{PKG_CONFIG} "${PKGCONFIG}" )
get_filename_component ( PKGCONFIG_PATH "${PKGCONFIG}" DIRECTORY )
vcpkg_add_to_path ( "${PKGCONFIG_PATH}" )
2022-09-13 04:30:47 +08:00
2019-09-13 01:07:22 +08:00
foreach ( _buildname ${ BUILDTYPES } )
2020-10-17 17:10:11 +08:00
set ( PKGCONFIG_INSTALLED_DIR "${_VCPKG_INSTALLED_PKGCONF}${_path_suffix_${_buildname}}/lib/pkgconfig" )
set ( PKGCONFIG_INSTALLED_SHARE_DIR "${_VCPKG_INSTALLED_PKGCONF}/share/pkgconfig" )
set ( PKGCONFIG_PACKAGES_DIR "${_VCPKG_PACKAGES_PKGCONF}${_path_suffix_${_buildname}}/lib/pkgconfig" )
set ( PKGCONFIG_PACKAGES_SHARE_DIR "${_VCPKG_PACKAGES_PKGCONF}/share/pkgconfig" )
if ( DEFINED ENV{PKG_CONFIG_PATH} )
set ( BACKUP_ENV_PKG_CONFIG_PATH_ ${ _config } $ENV{ PKG_CONFIG_PATH } )
set ( ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}${VCPKG_HOST_PATH_SEPARATOR}${PKGCONFIG_INSTALLED_SHARE_DIR}${VCPKG_HOST_PATH_SEPARATOR}${PKGCONFIG_PACKAGES_DIR}${VCPKG_HOST_PATH_SEPARATOR}${PKGCONFIG_PACKAGES_SHARE_DIR}${VCPKG_HOST_PATH_SEPARATOR}$ENV{PKG_CONFIG_PATH}" )
else ( )
set ( ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}${VCPKG_HOST_PATH_SEPARATOR}${PKGCONFIG_INSTALLED_SHARE_DIR}${VCPKG_HOST_PATH_SEPARATOR}${PKGCONFIG_PACKAGES_DIR}${VCPKG_HOST_PATH_SEPARATOR}${PKGCONFIG_PACKAGES_SHARE_DIR}" )
endif ( )
2019-09-13 01:07:22 +08:00
set ( _build_triplet ${ TARGET_TRIPLET } - ${ _short_name_${_buildname } } )
message ( STATUS "Configuring ${_build_triplet}" )
set ( _build_dir "${CURRENT_BUILDTREES_DIR}/${_build_triplet}" )
file ( MAKE_DIRECTORY ${ _build_dir } )
2022-09-13 04:30:47 +08:00
set ( qmake_comp_flags "" )
# Note sure about these. VCPKG_QMAKE_OPTIONS offers a way to opt out of these. (earlier values being overwritten by later values; = set +=append *=append unique -=remove)
macro ( qmake_add_flags qmake_var operation flags )
string ( STRIP "${flags}" striped_flags )
if ( striped_flags )
vcpkg_list ( APPEND qmake_comp_flags "${qmake_var}${operation}${striped_flags}" )
endif ( )
endmacro ( )
qmake_add_flags ( "QMAKE_LIBS" "+=" "${VCPKG_DETECTED_CMAKE_C_STANDARD_LIBRARIES} ${VCPKG_DETECTED_CMAKE_CXX_STANDARD_LIBRARIES}" )
qmake_add_flags ( "QMAKE_RC" "+=" "${VCPKG_COMBINED_RC_FLAGS_${_buildname}}" )
qmake_add_flags ( "QMAKE_CFLAGS_${_buildname}" "+=" "${VCPKG_COMBINED_C_FLAGS_${_buildname}}" )
qmake_add_flags ( "QMAKE_CXXFLAGS_${_buildname}" "+=" "${VCPKG_COMBINED_CXX_FLAGS_${_buildname}}" )
qmake_add_flags ( "QMAKE_LFLAGS" "+=" "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_${_buildname}}" )
qmake_add_flags ( "QMAKE_LFLAGS_SHLIB" "+=" "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_${_buildname}}" )
qmake_add_flags ( "QMAKE_LFLAGS_PLUGIN" "+=" "${VCPKG_COMBINED_MODULE_LINKER_FLAGS_${_buildname}}" )
qmake_add_flags ( "QMAKE_LIBFLAGS_${_buildname}" "+=" "${VCPKG_COMBINED_STATIC_LINKER_FLAGS_${_buildname}}" )
2019-09-13 01:07:22 +08:00
# These paths get hardcoded into qmake. So point them into the CURRENT_INSTALLED_DIR instead of CURRENT_PACKAGES_DIR
# makefiles will be fixed to install into CURRENT_PACKAGES_DIR in install_qt
set ( BUILD_OPTIONS ${ _csc_OPTIONS } ${ _csc_OPTIONS_${_buildname } }
- p r e f i x $ { C U R R E N T _ I N S T A L L E D _ D I R }
2020-10-17 17:10:11 +08:00
#-extprefix ${CURRENT_INSTALLED_DIR}
2019-09-13 01:07:22 +08:00
$ { E X T _ B I N _ D I R }
- h o s t p r e f i x $ { C U R R E N T _ I N S T A L L E D _ D I R } / t o o l s / q t 5 $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } }
2020-04-24 12:19:45 +08:00
#-hostprefix ${CURRENT_INSTALLED_DIR}/tools/qt5
2019-09-13 01:07:22 +08:00
- h o s t l i b d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } / t o o l s / q t 5 $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } } / l i b # could probably be move to manual-link
- h o s t b i n d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } / t o o l s / q t 5 $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } } / b i n
2020-04-24 12:19:45 +08:00
#-hostbindir ${CURRENT_INSTALLED_DIR}/tools/qt5/bin
2019-09-13 01:07:22 +08:00
# Qt VS Plugin requires a /bin subfolder with the executables in the root dir. But to use the wizard a correctly setup lib folder is also required
# So with the vcpkg layout there is no way to make it work unless all dll are are copied to tools/qt5/bin and all libs to tools/qt5/lib
- a r c h d a t a d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } / t o o l s / q t 5 $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } }
- d a t a d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } $ { _ p a t h _ s u f f i x } / s h a r e / q t 5 $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } }
- p l u g i n d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } } / p l u g i n s
- q m l d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } } / q m l
2021-04-10 00:55:53 +08:00
- h e a d e r d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } / i n c l u d e / q t 5
2019-09-13 01:07:22 +08:00
- l i b e x e c d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } / t o o l s / q t 5 $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } }
- b i n d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } } / b i n
- l i b d i r $ { C U R R E N T _ I N S T A L L E D _ D I R } $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } } / l i b
- I $ { C U R R E N T _ I N S T A L L E D _ D I R } / i n c l u d e
2021-04-10 00:55:53 +08:00
- I $ { C U R R E N T _ I N S T A L L E D _ D I R } / i n c l u d e / q t 5
2019-09-13 01:07:22 +08:00
- L $ { C U R R E N T _ I N S T A L L E D _ D I R } $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } } / l i b
- L $ { C U R R E N T _ I N S T A L L E D _ D I R } $ { _ p a t h _ s u f f i x _ $ { _ b u i l d n a m e } } / l i b / m a n u a l - l i n k
2020-10-17 17:10:11 +08:00
- p l a t f o r m $ { _ c s c _ T A R G E T _ P L A T F O R M }
2019-09-13 01:07:22 +08:00
)
2022-09-13 04:30:47 +08:00
2020-10-17 17:10:11 +08:00
if ( DEFINED _csc_HOST_TOOLS_ROOT ) #use qmake
2019-09-13 01:07:22 +08:00
if ( WIN32 )
set ( INVOKE_OPTIONS "QMAKE_CXX.QMAKE_MSC_VER=1911" "QMAKE_MSC_VER=1911" )
endif ( )
vcpkg_execute_required_process (
2022-09-13 04:30:47 +08:00
C O M M A N D $ { I N V O K E } " $ { _ c s c _ S O U R C E _ P A T H } " " $ { I N V O K E _ O P T I O N S } " - - $ { B U I L D _ O P T I O N S } $ { q m a k e _ b u i l d _ t o o l s } $ { q m a k e _ c o m p _ f l a g s }
2019-09-13 01:07:22 +08:00
W O R K I N G _ D I R E C T O R Y $ { _ b u i l d _ d i r }
L O G N A M E c o n f i g - $ { _ b u i l d _ t r i p l e t }
)
else ( ) # call configure (builds qmake for triplet and calls it like above)
vcpkg_execute_required_process (
2022-09-13 04:30:47 +08:00
C O M M A N D " $ { I N V O K E } " $ { B U I L D _ O P T I O N S } $ { q m a k e _ b u i l d _ t o o l s } $ { q m a k e _ c o m p _ f l a g s }
2019-09-13 01:07:22 +08:00
W O R K I N G _ D I R E C T O R Y $ { _ b u i l d _ d i r }
L O G N A M E c o n f i g - $ { _ b u i l d _ t r i p l e t }
)
endif ( )
# Note archdatadir and datadir are required to be prefixed with the hostprefix?
message ( STATUS "Configuring ${_build_triplet} done" )
# Copy configuration dependent qt.conf
file ( TO_CMAKE_PATH "${CURRENT_PACKAGES_DIR}" CMAKE_CURRENT_PACKAGES_DIR_PATH )
file ( TO_CMAKE_PATH "${CURRENT_INSTALLED_DIR}" CMAKE_CURRENT_INSTALLED_DIR_PATH )
file ( READ "${CURRENT_BUILDTREES_DIR}/${_build_triplet}/bin/qt.conf" _contents )
string ( REPLACE "${CMAKE_CURRENT_PACKAGES_DIR_PATH}" "\${CURRENT_INSTALLED_DIR}" _contents ${ _contents } )
string ( REPLACE "${CMAKE_CURRENT_INSTALLED_DIR_PATH}" "\${CURRENT_INSTALLED_DIR}" _contents ${ _contents } )
#string(REPLACE "HostPrefix=\${CURRENT_PACKAGES_DIR}" "HostPrefix=\${CURRENT_INSTALLED_DIR}" _contents ${_contents})
string ( REPLACE "[EffectivePaths]\nPrefix=..\n" "" _contents ${ _contents } )
2021-12-10 06:20:48 +08:00
string ( REGEX REPLACE "\\[EffectiveSourcePaths\\]\r?\nPrefix=[^\r\n]+\r?\n" "" _contents ${ _contents } )
2019-09-13 01:07:22 +08:00
string ( REPLACE "Sysroot=\n" "" _contents ${ _contents } )
string ( REPLACE "SysrootifyPrefix=false\n" "" _contents ${ _contents } )
2022-09-13 04:30:47 +08:00
file ( WRITE "${CURRENT_PACKAGES_DIR}/tools/qt5/qt_${_build_type_${_buildname}}.conf" "${_contents}" )
endforeach ( )
2019-09-13 01:07:22 +08:00
endfunction ( )