2019-10-05 22:51:07 +08:00
## # vcpkg_configure_make
##
## Configure configure for Debug and Release builds of a project.
##
## ## Usage
## ```cmake
## vcpkg_configure_make(
## SOURCE_PATH <${SOURCE_PATH}>
## [AUTOCONFIG]
2020-08-14 04:32:55 +08:00
## [BUILD_TRIPLET "--host=x64 --build=i686-unknown-pc"]
## [NO_ADDITIONAL_PATHS]
## [CONFIG_DEPENDENT_ENVIRONMENT <SOME_VAR>...]
## [CONFIGURE_ENVIRONMENT_VARIABLES <SOME_ENVVAR>...]
## [ADD_BIN_TO_PATH]
2019-10-05 22:51:07 +08:00
## [NO_DEBUG]
2019-10-22 07:23:52 +08:00
## [SKIP_CONFIGURE]
2019-10-05 22:51:07 +08:00
## [PROJECT_SUBPATH <${PROJ_SUBPATH}>]
## [PRERUN_SHELL <${SHELL_PATH}>]
## [OPTIONS <-DUSE_THIS_IN_ALL_BUILDS=1>...]
## [OPTIONS_RELEASE <-DOPTIMIZE=1>...]
## [OPTIONS_DEBUG <-DDEBUGGABLE=1>...]
## )
## ```
##
## ## Parameters
## ### SOURCE_PATH
## Specifies the directory containing the `configure`/`configure.ac`.
## By convention, this is usually set in the portfile as the variable `SOURCE_PATH`.
##
## ### PROJECT_SUBPATH
## Specifies the directory containing the ``configure`/`configure.ac`.
## By convention, this is usually set in the portfile as the variable `SOURCE_PATH`.
##
2019-10-22 07:23:52 +08:00
## ### SKIP_CONFIGURE
## Skip configure process
##
2020-08-14 04:32:55 +08:00
## ### BUILD_TRIPLET
## Used to pass custom --build/--target/--host to configure. Can be globally overwritten by VCPKG_MAKE_BUILD_TRIPLET
##
## ### NO_ADDITIONAL_PATHS
## Don't pass any additional paths except for --prefix to the configure call
##
2019-10-05 22:51:07 +08:00
## ### AUTOCONFIG
## Need to use autoconfig to generate configure file.
##
## ### PRERUN_SHELL
2020-05-22 01:46:07 +08:00
## Script that needs to be called before configuration (do not use for batch files which simply call autoconf or configure)
2019-10-05 22:51:07 +08:00
##
2020-08-14 04:32:55 +08:00
## ### ADD_BIN_TO_PATH
## Adds the appropriate Release and Debug `bin\` directories to the path during configure such that executables can run against the in-tree DLLs.
##
## ## DISABLE_VERBOSE_FLAGS
## do not pass '--disable-silent-rules --verbose' to configure
##
2019-10-05 22:51:07 +08:00
## ### OPTIONS
## Additional options passed to configure during the configuration.
##
## ### OPTIONS_RELEASE
## Additional options passed to configure during the Release configuration. These are in addition to `OPTIONS`.
##
## ### OPTIONS_DEBUG
## Additional options passed to configure during the Debug configuration. These are in addition to `OPTIONS`.
##
2020-08-14 04:32:55 +08:00
## ### CONFIG_DEPENDENT_ENVIRONMENT
## List of additional configuration dependent environment variables to set.
## Pass SOMEVAR to set the environment and have SOMEVAR_(DEBUG|RELEASE) set in the portfile to the appropriate values
## General environment variables can be set from within the portfile itself.
##
## ### CONFIGURE_ENVIRONMENT_VARIABLES
## List of additional environment variables to pass via the configure call.
##
2019-10-05 22:51:07 +08:00
## ## Notes
## This command supplies many common arguments to configure. To see the full list, examine the source.
##
## ## Examples
##
## * [x264](https://github.com/Microsoft/vcpkg/blob/master/ports/x264/portfile.cmake)
## * [tcl](https://github.com/Microsoft/vcpkg/blob/master/ports/tcl/portfile.cmake)
## * [freexl](https://github.com/Microsoft/vcpkg/blob/master/ports/freexl/portfile.cmake)
## * [libosip2](https://github.com/Microsoft/vcpkg/blob/master/ports/libosip2/portfile.cmake)
2020-08-14 04:32:55 +08:00
macro ( _vcpkg_determine_host_mingw out_var )
if ( DEFINED ENV{PROCESSOR_ARCHITEW6432} )
set ( HOST_ARCH $ENV{ PROCESSOR_ARCHITEW6432 } )
else ( )
set ( HOST_ARCH $ENV{ PROCESSOR_ARCHITECTURE } )
endif ( )
2020-05-22 01:46:07 +08:00
if ( HOST_ARCH MATCHES "(amd|AMD)64" )
2020-08-14 04:32:55 +08:00
set ( ${ out_var } mingw64 )
2020-05-22 01:46:07 +08:00
elseif ( HOST_ARCH MATCHES "(x|X)86" )
2020-08-14 04:32:55 +08:00
set ( ${ out_var } mingw32 )
else ( )
message ( FATAL_ERROR "Unsupported mingw architecture ${HOST_ARCH} in _vcpkg_determine_autotools_host_cpu!" )
endif ( )
unset ( HOST_ARCH )
endmacro ( )
macro ( _vcpkg_determine_autotools_host_cpu out_var )
if ( DEFINED ENV{PROCESSOR_ARCHITEW6432} )
set ( HOST_ARCH $ENV{ PROCESSOR_ARCHITEW6432 } )
else ( )
set ( HOST_ARCH $ENV{ PROCESSOR_ARCHITECTURE } )
endif ( )
if ( HOST_ARCH MATCHES "(amd|AMD)64" )
set ( ${ out_var } x86_64 )
elseif ( HOST_ARCH MATCHES "(x|X)86" )
set ( ${ out_var } i686 )
2020-05-22 01:46:07 +08:00
elseif ( HOST_ARCH MATCHES "^(ARM|arm)64$" )
2020-08-14 04:32:55 +08:00
set ( ${ out_var } aarch64 )
2020-05-22 01:46:07 +08:00
elseif ( HOST_ARCH MATCHES "^(ARM|arm)$" )
2020-08-14 04:32:55 +08:00
set ( ${ out_var } arm )
2020-05-22 01:46:07 +08:00
else ( )
2020-08-14 04:32:55 +08:00
message ( FATAL_ERROR "Unsupported host architecture ${HOST_ARCH} in _vcpkg_determine_autotools_host_cpu!" )
endif ( )
unset ( HOST_ARCH )
endmacro ( )
macro ( _vcpkg_determine_autotools_target_cpu out_var )
if ( VCPKG_TARGET_ARCHITECTURE MATCHES "(x|X)64" )
set ( ${ out_var } x86_64 )
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "(x|X)86" )
set ( ${ out_var } i686 )
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "^(ARM|arm)64$" )
set ( ${ out_var } aarch64 )
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "^(ARM|arm)$" )
set ( ${ out_var } arm )
else ( )
message ( FATAL_ERROR "Unsupported VCPKG_TARGET_ARCHITECTURE architecture ${VCPKG_TARGET_ARCHITECTURE} in _vcpkg_determine_autotools_target_cpu!" )
2020-05-22 01:46:07 +08:00
endif ( )
endmacro ( )
macro ( _vcpkg_backup_env_variable envvar )
2020-08-14 04:32:55 +08:00
if ( DEFINED ENV{ ${ envvar } } )
2020-05-22 01:46:07 +08:00
set ( ${ envvar } _BACKUP "$ENV{${envvar}}" )
set ( ${ envvar } _PATHLIKE_CONCAT "${VCPKG_HOST_PATH_SEPARATOR}$ENV{${envvar}}" )
else ( )
2020-08-14 04:32:55 +08:00
set ( ${ envvar } _BACKUP )
2020-05-22 01:46:07 +08:00
set ( ${ envvar } _PATHLIKE_CONCAT )
endif ( )
endmacro ( )
2020-08-14 04:32:55 +08:00
macro ( _vcpkg_backup_env_variables )
foreach ( _var ${ ARGV } )
_vcpkg_backup_env_variable ( ${ _var } )
endforeach ( )
endmacro ( )
2020-05-22 01:46:07 +08:00
macro ( _vcpkg_restore_env_variable envvar )
if ( ${ envvar } _BACKUP )
2020-08-14 04:32:55 +08:00
set ( ENV{ ${ envvar } } "${${envvar}_BACKUP}" )
2020-05-22 01:46:07 +08:00
else ( )
unset ( ENV{ ${ envvar } } )
endif ( )
endmacro ( )
2020-08-14 04:32:55 +08:00
macro ( _vcpkg_restore_env_variables )
foreach ( _var ${ ARGV } )
_vcpkg_restore_env_variable ( ${ _var } )
endforeach ( )
endmacro ( )
2020-05-22 01:46:07 +08:00
2019-10-05 22:51:07 +08:00
function ( vcpkg_configure_make )
cmake_parse_arguments ( _csc
2020-08-14 04:32:55 +08:00
" A U T O C O N F I G ; S K I P _ C O N F I G U R E ; C O P Y _ S O U R C E ; D I S A B L E _ V E R B O S E _ F L A G S ; N O _ A D D I T I O N A L _ P A T H S ; A D D _ B I N _ T O _ P A T H "
" S O U R C E _ P A T H ; P R O J E C T _ S U B P A T H ; P R E R U N _ S H E L L ; B U I L D _ T R I P L E T "
" O P T I O N S ; O P T I O N S _ D E B U G ; O P T I O N S _ R E L E A S E ; C O N F I G U R E _ E N V I R O N M E N T _ V A R I A B L E S ; C O N F I G _ D E P E N D E N T _ E N V I R O N M E N T "
2019-10-05 22:51:07 +08:00
$ { A R G N }
)
2020-08-14 04:32:55 +08:00
if ( DEFINED VCPKG_MAKE_BUILD_TRIPLET )
set ( _csc_BUILD_TRIPLET ${ VCPKG_MAKE_BUILD_TRIPLET } ) # Triplet overwrite for crosscompiling
endif ( )
set ( SRC_DIR "${_csc_SOURCE_PATH}/${_csc_PROJECT_SUBPATH}" )
set ( REQUIRES_AUTOGEN FALSE ) # use autogen.sh
set ( REQUIRES_AUTOCONFIG FALSE ) # use autotools and configure.ac
if ( EXISTS "${SRC_DIR}/configure" AND "${SRC_DIR}/configure.ac" ) # remove configure; rerun autoconf
if ( NOT VCPKG_MAINTAINER_SKIP_AUTOCONFIG ) # If fixing bugs skipping autoconfig saves a lot of time
set ( REQUIRES_AUTOCONFIG TRUE )
file ( REMOVE "${SRC_DIR}/configure" ) # remove possible autodated configure scripts
set ( _csc_AUTOCONFIG ON )
endif ( )
elseif ( EXISTS "${SRC_DIR}/configure" AND NOT _csc_SKIP_CONFIGURE ) # run normally; no autoconf or autgen required
elseif ( EXISTS "${SRC_DIR}/configure.ac" ) # Run autoconfig
set ( REQUIRES_AUTOCONFIG TRUE )
set ( _csc_AUTOCONFIG ON )
elseif ( EXISTS "${SRC_DIR}/autogen.sh" ) # Run autogen
set ( REQUIRES_AUTOGEN TRUE )
else ( )
message ( FATAL_ERROR "Could not determine method to configure make" )
endif ( )
2020-09-01 13:36:25 +08:00
2020-08-14 04:32:55 +08:00
debug_message ( "REQUIRES_AUTOGEN:${REQUIRES_AUTOGEN}" )
debug_message ( "REQUIRES_AUTOCONFIG:${REQUIRES_AUTOCONFIG}" )
# Backup environment variables
# CCAS CC C CPP CXX FC FF GC LD LF LIBTOOL OBJC OBJCXX R UPC Y
set ( FLAGPREFIXES CCAS CC C CPP CXX FC FF GC LD LF LIBTOOL OBJC OBJXX R UPC Y )
foreach ( _prefix IN LISTS FLAGPREFIXES )
_vcpkg_backup_env_variable ( ${ prefix } FLAGS )
endforeach ( )
# FC fotran compiler | FF Fortran 77 compiler
# LDFLAGS -> pass -L flags
# LIBS -> pass -l flags
#Used by gcc/linux
_vcpkg_backup_env_variables ( C_INCLUDE_PATH CPLUS_INCLUDE_PATH LIBRARY_PATH LD_LIBRARY_PATH )
#Used by cl
_vcpkg_backup_env_variables ( INCLUDE LIB LIBPATH )
if ( CURRENT_PACKAGES_DIR MATCHES " " OR CURRENT_INSTALLED_DIR MATCHES " " )
2020-05-22 01:46:07 +08:00
# Don't bother with whitespace. The tools will probably fail and I tried very hard trying to make it work (no success so far)!
message ( WARNING "Detected whitespace in root directory. Please move the path to one without whitespaces! The required tools do not handle whitespaces correctly and the build will most likely fail" )
2019-10-05 22:51:07 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
2019-10-05 22:51:07 +08:00
# Pre-processing windows configure requirements
if ( CMAKE_HOST_WIN32 )
2020-08-14 04:32:55 +08:00
_vcpkg_determine_autotools_host_cpu ( BUILD_ARCH ) # VCPKG_HOST => machine you are building on => --build=
2020-05-22 01:46:07 +08:00
2020-09-01 13:36:25 +08:00
list ( APPEND MSYS_REQUIRE_PACKAGES binutils libtool autoconf automake-wrapper automake1.16 m4 )
vcpkg_acquire_msys ( MSYS_ROOT PACKAGES ${ MSYS_REQUIRE_PACKAGES } )
# This inserts msys before system32 (which masks sort.exe and find.exe) but after MSVC (which avoids masking link.exe)
string ( REPLACE ";$ENV{SystemRoot}\\System32;" ";${MSYS_ROOT}/usr/share/automake-1.16;${MSYS_ROOT}/usr/bin;$ENV{SystemRoot}\\System32;" NEWPATH "$ENV{PATH}" )
set ( ENV{PATH} "${NEWPATH}" )
set ( BASH "${MSYS_ROOT}/usr/bin/bash.exe" )
2019-10-22 07:23:23 +08:00
if ( _csc_AUTOCONFIG )
2020-08-14 04:32:55 +08:00
# --build: the machine you are building on
# --host: the machine you are building for
# --target: the machine that CC will produce binaries for
# https://stackoverflow.com/questions/21990021/how-to-determine-host-value-for-configure-when-using-cross-compiler
# Only for ports using autotools so we can assume that they follow the common conventions for build/target/host
if ( NOT _csc_BUILD_TRIPLET )
set ( _csc_BUILD_TRIPLET "--build=${BUILD_ARCH}-pc-mingw32" ) # This is required since we are running in a msys
# shell which will be otherwise identified as ${BUILD_ARCH}-pc-msys
_vcpkg_determine_autotools_target_cpu ( TARGET_ARCH )
if ( NOT TARGET_ARCH MATCHES "${BUILD_ARCH}" ) # we do not need to specify the additional flags if we build nativly.
string ( APPEND _csc_BUILD_TRIPLET " --host=${TARGET_ARCH}-pc-mingw32" ) # (Host activates crosscompilation; The name given here is just the prefix of the host tools for the target)
endif ( )
if ( VCPKG_TARGET_IS_UWP AND NOT _csc_BUILD_TRIPLET MATCHES "--host" )
# Needs to be different from --build to enable cross builds.
string ( APPEND _csc_BUILD_TRIPLET " --host=${TARGET_ARCH}-unknown-mingw32" )
endif ( )
endif ( )
debug_message ( "Using make triplet: ${_csc_BUILD_TRIPLET}" )
2019-10-22 07:23:23 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
2020-07-16 06:23:40 +08:00
macro ( _vcpkg_append_to_configure_environment inoutstring var defaultval )
2020-08-14 04:32:55 +08:00
# Allows to overwrite settings in custom triplets via the environment
if ( DEFINED ENV{ ${ var } } )
2020-05-22 01:46:07 +08:00
string ( APPEND ${ inoutstring } " ${var}='$ENV{${var}}'" )
else ( )
string ( APPEND ${ inoutstring } " ${var}='${defaultval}'" )
2019-10-05 22:51:07 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
endmacro ( )
2020-08-14 04:32:55 +08:00
set ( CONFIGURE_ENV "V=1" )
if ( _csc_AUTOCONFIG ) # without autotools we assume a custom configure script which correctly handles cl and lib. Otherwise the port needs to set CC|CXX|AR and probably CPP
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV CPP "compile cl.exe -nologo -E" )
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV CC "compile cl.exe -nologo" )
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV CXX "compile cl.exe -nologo" )
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV AR "ar-lib lib.exe -verbose" )
else ( )
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV CPP "cl.exe -nologo -E" )
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV CC "cl.exe -nologo" )
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV CXX "cl.exe -nologo" )
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV AR "lib.exe -verbose" )
endif ( )
2020-07-16 06:23:40 +08:00
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV LD "link.exe -verbose" )
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV RANLIB ":" ) # Trick to ignore the RANLIB call
2020-08-14 04:32:55 +08:00
#_vcpkg_append_to_configure_environment(CONFIGURE_ENV OBJDUMP ":") ' Objdump is required to make shared libraries. Otherwise define lt_cv_deplibs_check_method=pass_all
2020-07-16 06:23:40 +08:00
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV CCAS ":" ) # If required set the ENV variable CCAS in the portfile correctly
2020-08-14 04:32:55 +08:00
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV STRIP ":" ) # If required set the ENV variable STRIP in the portfile correctly
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV NM "dumpbin.exe -symbols -headers" )
2020-05-22 01:46:07 +08:00
# Would be better to have a true nm here! Some symbols (mainly exported variables) get not properly imported with dumpbin as nm
# and require __declspec(dllimport) for some reason (same problem CMake has with WINDOWS_EXPORT_ALL_SYMBOLS)
2020-07-16 06:23:40 +08:00
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV DLLTOOL "link.exe -verbose -dll" )
2020-08-14 04:32:55 +08:00
foreach ( _env IN LISTS _csc_CONFIGURE_ENVIRONMENT_VARIABLES )
_vcpkg_append_to_configure_environment ( CONFIGURE_ENV ${ _env } "${${_env}}" )
endforeach ( )
2020-05-22 01:46:07 +08:00
# Other maybe interesting variables to control
# COMPILE This is the command used to actually compile a C source file. The file name is appended to form the complete command line.
# LINK This is the command used to actually link a C program.
# CXXCOMPILE The command used to actually compile a C++ source file. The file name is appended to form the complete command line.
# CXXLINK The command used to actually link a C++ program.
2019-10-05 22:51:07 +08:00
2020-05-22 01:46:07 +08:00
#Some PATH handling for dealing with spaces....some tools will still fail with that!
string ( REPLACE " " "\\\ " _VCPKG_PREFIX ${ CURRENT_INSTALLED_DIR } )
string ( REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_PREFIX "${_VCPKG_PREFIX}" )
set ( _VCPKG_INSTALLED ${ CURRENT_INSTALLED_DIR } )
string ( REPLACE " " "\ " _VCPKG_INSTALLED_PKGCONF ${ CURRENT_INSTALLED_DIR } )
string ( REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_INSTALLED_PKGCONF ${ _VCPKG_INSTALLED_PKGCONF } )
string ( REPLACE "\\" "/" _VCPKG_INSTALLED_PKGCONF ${ _VCPKG_INSTALLED_PKGCONF } )
set ( prefix_var "'\${prefix}'" ) # Windows needs extra quotes or else the variable gets expanded in the makefile!
2019-10-05 22:51:07 +08:00
else ( )
2020-05-22 01:46:07 +08:00
string ( REPLACE " " "\ " _VCPKG_PREFIX ${ CURRENT_INSTALLED_DIR } )
string ( REPLACE " " "\ " _VCPKG_INSTALLED ${ CURRENT_INSTALLED_DIR } )
set ( _VCPKG_INSTALLED_PKGCONF ${ CURRENT_INSTALLED_DIR } )
set ( EXTRA_QUOTES )
set ( prefix_var "\${prefix}" )
2019-10-05 22:51:07 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
# Cleanup previous build dirs
file ( REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
" $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - d b g "
" $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } " )
2020-06-27 10:22:12 +08:00
2020-05-22 01:46:07 +08:00
# Set configure paths
2020-08-14 04:32:55 +08:00
set ( _csc_OPTIONS_RELEASE ${ _csc_OPTIONS_RELEASE } "--prefix=${EXTRA_QUOTES}${_VCPKG_PREFIX}${EXTRA_QUOTES}" )
set ( _csc_OPTIONS_DEBUG ${ _csc_OPTIONS_DEBUG } "--prefix=${EXTRA_QUOTES}${_VCPKG_PREFIX}/debug${EXTRA_QUOTES}" )
if ( NOT _csc_NO_ADDITIONAL_PATHS )
set ( _csc_OPTIONS_RELEASE ${ _csc_OPTIONS_RELEASE }
2020-05-22 01:46:07 +08:00
# Important: These should all be relative to prefix!
" - - b i n d i r = $ { p r e f i x _ v a r } / t o o l s / $ { P O R T } / b i n "
" - - s b i n d i r = $ { p r e f i x _ v a r } / t o o l s / $ { P O R T } / s b i n "
#"--libdir='\${prefix}'/lib" # already the default!
#"--includedir='\${prefix}'/include" # already the default!
" - - m a n d i r = $ { p r e f i x _ v a r } / s h a r e / $ { P O R T } "
" - - d o c d i r = $ { p r e f i x _ v a r } / s h a r e / $ { P O R T } "
" - - d a t a r o o t d i r = $ { p r e f i x _ v a r } / s h a r e / $ { P O R T } " )
2020-08-14 04:32:55 +08:00
set ( _csc_OPTIONS_DEBUG ${ _csc_OPTIONS_DEBUG }
2020-05-22 01:46:07 +08:00
# Important: These should all be relative to prefix!
" - - b i n d i r = $ { p r e f i x _ v a r } / . . / t o o l s / $ { P O R T } / d e b u g / b i n "
" - - s b i n d i r = $ { p r e f i x _ v a r } / . . / t o o l s / $ { P O R T } / d e b u g / s b i n "
#"--libdir='\${prefix}'/lib" # already the default!
" - - i n c l u d e d i r = $ { p r e f i x _ v a r } / . . / i n c l u d e "
" - - d a t a r o o t d i r = $ { p r e f i x _ v a r } / s h a r e / $ { P O R T } " )
2020-08-14 04:32:55 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
# Setup common options
2020-08-14 04:32:55 +08:00
if ( NOT DISABLE_VERBOSE_FLAGS )
list ( APPEND _csc_OPTIONS --disable-silent-rules --verbose )
endif ( )
2020-05-22 01:46:07 +08:00
if ( VCPKG_LIBRARY_LINKAGE STREQUAL dynamic )
2020-08-14 04:32:55 +08:00
list ( APPEND _csc_OPTIONS --enable-shared --disable-static )
2020-05-22 01:46:07 +08:00
else ( )
2020-08-14 04:32:55 +08:00
list ( APPEND _csc_OPTIONS --disable-shared --enable-static )
2019-10-05 22:51:07 +08:00
endif ( )
2020-08-14 04:32:55 +08:00
2020-05-22 01:46:07 +08:00
file ( RELATIVE_PATH RELATIVE_BUILD_PATH "${CURRENT_BUILDTREES_DIR}" "${_csc_SOURCE_PATH}/${_csc_PROJECT_SUBPATH}" )
set ( base_cmd )
2019-10-05 22:51:07 +08:00
if ( CMAKE_HOST_WIN32 )
2020-05-22 01:46:07 +08:00
set ( base_cmd ${ BASH } --noprofile --norc --debug )
2019-10-05 22:51:07 +08:00
# Load toolchains
if ( NOT VCPKG_CHAINLOAD_TOOLCHAIN_FILE )
set ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/windows.cmake" )
endif ( )
include ( "${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}" )
2020-05-22 01:46:07 +08:00
#Join the options list as a string with spaces between options
2019-10-05 22:51:07 +08:00
list ( JOIN _csc_OPTIONS " " _csc_OPTIONS )
list ( JOIN _csc_OPTIONS_RELEASE " " _csc_OPTIONS_RELEASE )
list ( JOIN _csc_OPTIONS_DEBUG " " _csc_OPTIONS_DEBUG )
endif ( )
2020-08-14 04:32:55 +08:00
# Setup include environment (since these are buildtype independent restoring them is unnecessary)
# Used by CL
2020-05-22 01:46:07 +08:00
set ( ENV{INCLUDE} "${_VCPKG_INSTALLED}/include${VCPKG_HOST_PATH_SEPARATOR}${INCLUDE_BACKUP}" )
2020-08-14 04:32:55 +08:00
# Used by GCC
2020-05-22 01:46:07 +08:00
set ( ENV{C_INCLUDE_PATH} "${_VCPKG_INSTALLED}/include${VCPKG_HOST_PATH_SEPARATOR}${C_INCLUDE_PATH_BACKUP}" )
set ( ENV{CPLUS_INCLUDE_PATH} "${_VCPKG_INSTALLED}/include${VCPKG_HOST_PATH_SEPARATOR}${CPLUS_INCLUDE_PATH_BACKUP}" )
# Setup global flags -> TODO: Further improve with toolchain file in mind!
2020-08-14 04:32:55 +08:00
set ( CPP_FLAGS_GLOBAL "$ENV{CPPFLAGS} -I${_VCPKG_INSTALLED}/include" )
2020-05-22 01:46:07 +08:00
set ( C_FLAGS_GLOBAL "$ENV{CFLAGS} ${VCPKG_C_FLAGS}" )
set ( CXX_FLAGS_GLOBAL "$ENV{CXXFLAGS} ${VCPKG_CXX_FLAGS}" )
set ( LD_FLAGS_GLOBAL "$ENV{LDFLAGS} ${VCPKG_LINKER_FLAGS}" )
2020-08-14 04:32:55 +08:00
# Flags should be set in the toolchain instead (Setting this up correctly requires a function named vcpkg_determined_cmake_compiler_flags which can also be used to setup CC and CXX etc.)
2020-05-22 01:46:07 +08:00
if ( NOT VCPKG_TARGET_IS_WINDOWS )
string ( APPEND C_FLAGS_GLOBAL " -fPIC" )
string ( APPEND CXX_FLAGS_GLOBAL " -fPIC" )
else ( )
2020-08-14 04:32:55 +08:00
# TODO: Should be CPP flags instead -> rewrite when vcpkg_determined_cmake_compiler_flags defined
string ( APPEND CPP_FLAGS_GLOBAL " /D_WIN32_WINNT=0x0601 /DWIN32_LEAN_AND_MEAN /DWIN32 /D_WINDOWS" )
if ( VCPKG_TARGET_IS_UWP )
# Be aware that configure thinks it is crosscompiling due to:
# error while loading shared libraries: VCRUNTIME140D_APP.dll:
# cannot open shared object file: No such file or directory
# IMPORTANT: The only way to pass linker flags through libtool AND the compile wrapper
# is to use the CL and LINK environment variables !!!
# (This is due to libtool and compiler wrapper using the same set of options to pass those variables around)
string ( REPLACE "\\" "/" VCToolsInstallDir "$ENV{VCToolsInstallDir}" )
set ( ENV{_CL_} "$ENV{_CL_} /DWINAPI_FAMILY=WINAPI_FAMILY_APP /D__WRL_NO_DEFAULT_LIB_ -FU\" ${ VCToolsInstallDir } /lib/x86/store/references/platform.winmd\ "" )
set ( ENV{_LINK_} "$ENV{_LINK_} /MANIFEST /DYNAMICBASE WindowsApp.lib /WINMD:NO /APPCONTAINER" )
endif ( )
2020-05-22 01:46:07 +08:00
if ( VCPKG_TARGET_ARCHITECTURE STREQUAL x64 )
2020-08-14 04:32:55 +08:00
set ( ENV{_LINK_} "$ENV{_LINK_} -MACHINE:x64" )
2020-05-22 01:46:07 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE STREQUAL x86 )
2020-08-14 04:32:55 +08:00
set ( ENV{_LINK_} "$ENV{_LINK_} -MACHINE:x86" )
elseif ( VCPKG_TARGET_ARCHITECTURE STREQUAL arm )
set ( ENV{_LINK_} "$ENV{_LINK_} -MACHINE:ARM" )
elseif ( VCPKG_TARGET_ARCHITECTURE STREQUAL arm64 )
set ( ENV{_LINK_} "$ENV{_LINK_} -MACHINE:ARM64" )
2019-10-05 22:51:07 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
endif ( )
2020-08-19 03:16:39 +08:00
vcpkg_find_acquire_program ( PKGCONFIG )
2020-08-14 04:32:55 +08:00
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "static" AND NOT PKGCONFIG STREQUAL "--static" )
set ( PKGCONFIG "${PKGCONFIG} --static" )
2020-05-22 01:46:07 +08:00
endif ( )
2020-08-14 04:32:55 +08:00
# Run autoconf if necessary
2020-05-22 01:46:07 +08:00
set ( _GENERATED_CONFIGURE FALSE )
if ( _csc_AUTOCONFIG OR REQUIRES_AUTOCONFIG )
2020-09-01 13:36:25 +08:00
find_program ( AUTORECONF autoreconf )
2020-05-22 01:46:07 +08:00
if ( NOT AUTORECONF )
2020-09-01 13:36:25 +08:00
message ( FATAL_ERROR "${PORT} requires autoconf from the system package manager (example: \" sudo apt-get install autoconf\ ")" )
2020-05-22 01:46:07 +08:00
endif ( )
message ( STATUS "Generating configure for ${TARGET_TRIPLET}" )
if ( CMAKE_HOST_WIN32 )
2019-10-05 22:51:07 +08:00
vcpkg_execute_required_process (
2020-05-22 01:46:07 +08:00
C O M M A N D $ { b a s e _ c m d } - c " a u t o r e c o n f - v f i "
W O R K I N G _ D I R E C T O R Y " $ { S R C _ D I R } "
L O G N A M E a u t o c o n f - $ { T A R G E T _ T R I P L E T }
)
else ( )
vcpkg_execute_required_process (
2020-09-01 13:36:25 +08:00
C O M M A N D $ { A U T O R E C O N F } - v f i
2020-05-22 01:46:07 +08:00
W O R K I N G _ D I R E C T O R Y " $ { S R C _ D I R } "
L O G N A M E a u t o c o n f - $ { T A R G E T _ T R I P L E T }
2019-10-05 22:51:07 +08:00
)
endif ( )
2020-05-22 01:46:07 +08:00
message ( STATUS "Finished generating configure for ${TARGET_TRIPLET}" )
endif ( )
if ( REQUIRES_AUTOGEN )
message ( STATUS "Generating configure for ${TARGET_TRIPLET} via autogen.sh" )
if ( CMAKE_HOST_WIN32 )
vcpkg_execute_required_process (
C O M M A N D $ { b a s e _ c m d } - c " . / a u t o g e n . s h "
W O R K I N G _ D I R E C T O R Y " $ { S R C _ D I R } "
L O G N A M E a u t o c o n f - $ { T A R G E T _ T R I P L E T }
)
else ( )
2019-10-22 07:23:52 +08:00
vcpkg_execute_required_process (
2020-05-22 01:46:07 +08:00
C O M M A N D " . / a u t o g e n . s h "
W O R K I N G _ D I R E C T O R Y " $ { S R C _ D I R } "
L O G N A M E a u t o c o n f - $ { T A R G E T _ T R I P L E T }
2019-10-22 07:23:52 +08:00
)
endif ( )
2020-05-22 01:46:07 +08:00
message ( STATUS "Finished generating configure for ${TARGET_TRIPLET}" )
2019-10-05 22:51:07 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
if ( _csc_PRERUN_SHELL )
message ( STATUS "Prerun shell with ${TARGET_TRIPLET}" )
vcpkg_execute_required_process (
C O M M A N D $ { b a s e _ c m d } - c " $ { _ c s c _ P R E R U N _ S H E L L } "
W O R K I N G _ D I R E C T O R Y " $ { S R C _ D I R } "
L O G N A M E p r e r u n - $ { T A R G E T _ T R I P L E T }
)
endif ( )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" AND NOT _csc_NO_DEBUG )
set ( _VAR_SUFFIX DEBUG )
set ( PATH_SUFFIX_ ${ _VAR_SUFFIX } "/debug" )
set ( SHORT_NAME_ ${ _VAR_SUFFIX } "dbg" )
list ( APPEND _buildtypes ${ _VAR_SUFFIX } )
if ( CMAKE_HOST_WIN32 ) # Flags should be set in the toolchain instead
2020-08-14 04:32:55 +08:00
string ( REGEX REPLACE "[ \t]+/" " -" CPPFLAGS_ ${ _VAR_SUFFIX } "${CPP_FLAGS_GLOBAL}" )
2020-05-22 01:46:07 +08:00
string ( REGEX REPLACE "[ \t]+/" " -" CFLAGS_ ${ _VAR_SUFFIX } "${C_FLAGS_GLOBAL} ${VCPKG_CRT_LINK_FLAG_PREFIX}d /D_DEBUG /Ob0 /Od ${VCPKG_C_FLAGS_${_VAR_SUFFIX}}" )
string ( REGEX REPLACE "[ \t]+/" " -" CXXFLAGS_ ${ _VAR_SUFFIX } "${CXX_FLAGS_GLOBAL} ${VCPKG_CRT_LINK_FLAG_PREFIX}d /D_DEBUG /Ob0 /Od ${VCPKG_CXX_FLAGS_${_VAR_SUFFIX}}" )
string ( REGEX REPLACE "[ \t]+/" " -" LDFLAGS_ ${ _VAR_SUFFIX } "-L${_VCPKG_INSTALLED}${PATH_SUFFIX_${_VAR_SUFFIX}}/lib ${LD_FLAGS_GLOBAL} ${VCPKG_LINKER_FLAGS_${_VAR_SUFFIX}}" )
else ( )
2020-08-14 04:32:55 +08:00
set ( CPPFLAGS_ ${ _VAR_SUFFIX } "${CPP_FLAGS_GLOBAL}" )
2020-05-22 01:46:07 +08:00
set ( CFLAGS_ ${ _VAR_SUFFIX } "${C_FLAGS_GLOBAL} ${VCPKG_C_FLAGS_DEBUG}" )
set ( CXXFLAGS_ ${ _VAR_SUFFIX } "${CXX_FLAGS_GLOBAL} ${VCPKG_CXX_FLAGS_DEBUG}" )
set ( LDFLAGS_ ${ _VAR_SUFFIX } "-L${_VCPKG_INSTALLED}${PATH_SUFFIX_${_VAR_SUFFIX}}/lib/ -L${_VCPKG_INSTALLED}${PATH_SUFFIX_${_VAR_SUFFIX}}/lib/manual-link/ ${LD_FLAGS_GLOBAL} ${VCPKG_LINKER_FLAGS_${_VAR_SUFFIX}}" )
2019-10-05 22:51:07 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
unset ( _VAR_SUFFIX )
endif ( )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release" )
set ( _VAR_SUFFIX RELEASE )
set ( PATH_SUFFIX_ ${ _VAR_SUFFIX } "" )
set ( SHORT_NAME_ ${ _VAR_SUFFIX } "rel" )
list ( APPEND _buildtypes ${ _VAR_SUFFIX } )
2020-08-14 04:32:55 +08:00
if ( CMAKE_HOST_WIN32 ) # Flags should be set in the toolchain
string ( REGEX REPLACE "[ \t]+/" " -" CPPFLAGS_ ${ _VAR_SUFFIX } "${CPP_FLAGS_GLOBAL}" )
2020-05-22 01:46:07 +08:00
string ( REGEX REPLACE "[ \t]+/" " -" CFLAGS_ ${ _VAR_SUFFIX } "${C_FLAGS_GLOBAL} ${VCPKG_CRT_LINK_FLAG_PREFIX} /O2 /Oi /Gy /DNDEBUG ${VCPKG_C_FLAGS_${_VAR_SUFFIX}}" )
string ( REGEX REPLACE "[ \t]+/" " -" CXXFLAGS_ ${ _VAR_SUFFIX } "${CXX_FLAGS_GLOBAL} ${VCPKG_CRT_LINK_FLAG_PREFIX} /O2 /Oi /Gy /DNDEBUG ${VCPKG_CXX_FLAGS_${_VAR_SUFFIX}}" )
string ( REGEX REPLACE "[ \t]+/" " -" LDFLAGS_ ${ _VAR_SUFFIX } "-L${_VCPKG_INSTALLED}${PATH_SUFFIX_${_VAR_SUFFIX}}/lib ${LD_FLAGS_GLOBAL} ${VCPKG_LINKER_FLAGS_${_VAR_SUFFIX}}" )
2019-10-05 22:51:07 +08:00
else ( )
2020-08-14 04:32:55 +08:00
set ( CPPFLAGS_ ${ _VAR_SUFFIX } "${CPP_FLAGS_GLOBAL}" )
2020-05-22 01:46:07 +08:00
set ( CFLAGS_ ${ _VAR_SUFFIX } "${C_FLAGS_GLOBAL} ${VCPKG_C_FLAGS_DEBUG}" )
set ( CXXFLAGS_ ${ _VAR_SUFFIX } "${CXX_FLAGS_GLOBAL} ${VCPKG_CXX_FLAGS_DEBUG}" )
set ( LDFLAGS_ ${ _VAR_SUFFIX } "-L${_VCPKG_INSTALLED}${PATH_SUFFIX_${_VAR_SUFFIX}}/lib/ -L${_VCPKG_INSTALLED}${PATH_SUFFIX_${_VAR_SUFFIX}}/lib/manual-link/ ${LD_FLAGS_GLOBAL} ${VCPKG_LINKER_FLAGS_${_VAR_SUFFIX}}" )
2019-10-05 22:51:07 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
unset ( _VAR_SUFFIX )
endif ( )
foreach ( _buildtype IN LISTS _buildtypes )
2020-08-14 04:32:55 +08:00
foreach ( ENV_VAR ${ _csc_CONFIG_DEPENDENT_ENVIRONMENT } )
if ( DEFINED ENV{ ${ ENV_VAR } } )
set ( BACKUP_CONFIG_ ${ ENV_VAR } "$ENV{${ENV_VAR}}" )
endif ( )
set ( ENV{ ${ ENV_VAR } } "${${ENV_VAR}_${_buildtype}}" )
endforeach ( )
2020-05-22 01:46:07 +08:00
set ( TAR_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${SHORT_NAME_${_buildtype}}" )
file ( MAKE_DIRECTORY "${TAR_DIR}" )
file ( RELATIVE_PATH RELATIVE_BUILD_PATH "${TAR_DIR}" "${SRC_DIR}" )
if ( _csc_COPY_SOURCE )
file ( COPY "${SRC_DIR}/" DESTINATION "${TAR_DIR}" )
set ( RELATIVE_BUILD_PATH . )
2019-10-05 22:51:07 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
set ( PKGCONFIG_INSTALLED_DIR "${_VCPKG_INSTALLED_PKGCONF}${PATH_SUFFIX_${_buildtype}}/lib/pkgconfig" )
set ( PKGCONFIG_INSTALLED_SHARE_DIR "${_VCPKG_INSTALLED_PKGCONF}/share/pkgconfig" )
if ( ENV{PKG_CONFIG_PATH} )
set ( BACKUP_ENV_PKG_CONFIG_PATH_ ${ _buildtype } $ENV{ PKG_CONFIG_PATH } )
set ( ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}:${PKGCONFIG_INSTALLED_SHARE_DIR}:$ENV{PKG_CONFIG_PATH}" )
else ( )
set ( ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}:${PKGCONFIG_INSTALLED_SHARE_DIR}" )
2019-10-05 22:51:07 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
2020-08-14 04:32:55 +08:00
# Setup environment
set ( ENV{CPPFLAGS} ${ CPPFLAGS_${_buildtype } } )
2020-05-22 01:46:07 +08:00
set ( ENV{CFLAGS} ${ CFLAGS_${_buildtype } } )
set ( ENV{CXXFLAGS} ${ CXXFLAGS_${_buildtype } } )
set ( ENV{LDFLAGS} ${ LDFLAGS_${_buildtype } } )
set ( ENV{PKG_CONFIG} "${PKGCONFIG} --define-variable=prefix=${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}" )
2020-08-14 04:32:55 +08:00
set ( ENV{LIB} "${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}/lib/${VCPKG_HOST_PATH_SEPARATOR}${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}/lib/manual-link/${LIB_PATHLIKE_CONCAT}" )
set ( ENV{LIBPATH} "${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}/lib/${VCPKG_HOST_PATH_SEPARATOR}${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}/lib/manual-link/${LIBPATH_PATHLIKE_CONCAT}" )
set ( ENV{LIBRARY_PATH} "${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}/lib/${VCPKG_HOST_PATH_SEPARATOR}${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}/lib/manual-link/${LIBRARY_PATH_PATHLIKE_CONCAT}" )
2020-05-22 01:46:07 +08:00
set ( ENV{LD_LIBRARY_PATH} "${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}/lib/${VCPKG_HOST_PATH_SEPARATOR}${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}/lib/manual-link/${LD_LIBRARY_PATH_PATHLIKE_CONCAT}" )
2020-08-14 04:32:55 +08:00
if ( CMAKE_HOST_WIN32 )
set ( command ${ base_cmd } -c "${CONFIGURE_ENV} ./${RELATIVE_BUILD_PATH}/configure ${_csc_BUILD_TRIPLET} ${_csc_OPTIONS} ${_csc_OPTIONS_${_buildtype}}" )
2020-05-22 01:46:07 +08:00
else ( )
2020-08-14 04:32:55 +08:00
set ( command /bin/bash "./${RELATIVE_BUILD_PATH}/configure" ${ _csc_BUILD_TRIPLET } ${ _csc_OPTIONS } ${ _csc_OPTIONS_${_buildtype } } )
2019-10-05 22:51:07 +08:00
endif ( )
2020-08-14 04:32:55 +08:00
if ( _csc_ADD_BIN_TO_PATH )
set ( PATH_BACKUP $ENV{ PATH } )
vcpkg_add_to_path ( "${CURRENT_INSTALLED_DIR}${PATH_SUFFIX_${_buildtype}}/bin" )
endif ( )
debug_message ( "Configure command:'${command}'" )
2019-10-22 07:23:52 +08:00
if ( NOT _csc_SKIP_CONFIGURE )
2020-05-22 01:46:07 +08:00
message ( STATUS "Configuring ${TARGET_TRIPLET}-${SHORT_NAME_${_buildtype}}" )
2019-10-22 07:23:52 +08:00
vcpkg_execute_required_process (
2020-05-22 01:46:07 +08:00
C O M M A N D $ { c o m m a n d }
W O R K I N G _ D I R E C T O R Y " $ { T A R _ D I R } "
L O G N A M E c o n f i g - $ { T A R G E T _ T R I P L E T } - $ { S H O R T _ N A M E _ $ { _ b u i l d t y p e } }
2019-10-22 07:23:52 +08:00
)
2020-05-22 01:46:07 +08:00
if ( EXISTS "${TAR_DIR}/libtool" AND VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL dynamic )
set ( _file "${TAR_DIR}/libtool" )
file ( READ "${_file}" _contents )
string ( REPLACE ".dll.lib" ".lib" _contents "${_contents}" )
file ( WRITE "${_file}" "${_contents}" )
endif ( )
2019-10-22 07:23:52 +08:00
endif ( )
2020-05-22 01:46:07 +08:00
if ( BACKUP_ENV_PKG_CONFIG_PATH_ ${ _buildtype } )
set ( ENV{PKG_CONFIG_PATH} "${BACKUP_ENV_PKG_CONFIG_PATH_${_buildtype}}" )
else ( )
unset ( ENV{PKG_CONFIG_PATH} )
endif ( )
unset ( BACKUP_ENV_PKG_CONFIG_PATH_ ${ _buildtype } )
2020-08-14 04:32:55 +08:00
if ( _csc_ADD_BIN_TO_PATH )
set ( ENV{PATH} "${PATH_BACKUP}" )
endif ( )
# Restore environment (config dependent)
foreach ( ENV_VAR ${ _csc_CONFIG_DEPENDENT_ENVIRONMENT } )
if ( BACKUP_CONFIG_ ${ ENV_VAR } )
set ( ENV{ ${ ENV_VAR } } "${BACKUP_CONFIG_${ENV_VAR}}" )
else ( )
unset ( ENV{ ${ ENV_VAR } } )
endif ( )
endforeach ( )
endforeach ( )
# Restore environment
foreach ( _prefix IN LISTS FLAGPREFIXES )
_vcpkg_restore_env_variable ( ${ prefix } FLAGS )
2020-05-22 01:46:07 +08:00
endforeach ( )
2020-08-14 04:32:55 +08:00
_vcpkg_restore_env_variables ( LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH )
2019-10-05 22:51:07 +08:00
SET ( _VCPKG_PROJECT_SOURCE_PATH ${ _csc_SOURCE_PATH } PARENT_SCOPE )
set ( _VCPKG_PROJECT_SUBPATH ${ _csc_PROJECT_SUBPATH } PARENT_SCOPE )
endfunction ( )