2019-10-05 22:51:07 +08:00
|
|
|
function(vcpkg_build_make)
|
2021-07-30 00:47:35 +08:00
|
|
|
z_vcpkg_get_cmake_vars(cmake_vars_file)
|
|
|
|
include("${cmake_vars_file}")
|
2020-11-18 01:18:59 +08:00
|
|
|
|
2020-10-27 10:30:27 +08:00
|
|
|
# parse parameters such that semicolons in options arguments to COMMAND don't get erased
|
2021-10-21 05:12:58 +08:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 arg
|
|
|
|
"ADD_BIN_TO_PATH;ENABLE_INSTALL;DISABLE_PARALLEL"
|
|
|
|
"LOGFILE_ROOT;BUILD_TARGET;SUBPATH;MAKEFILE;INSTALL_TARGET"
|
|
|
|
"OPTIONS"
|
|
|
|
)
|
|
|
|
|
|
|
|
if(DEFINED arg_UNPARSED_ARGUMENTS)
|
|
|
|
message(WARNING "vcpkg_make_build was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
|
|
|
|
endif()
|
2019-10-05 22:51:07 +08:00
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if(NOT DEFINED arg_LOGFILE_ROOT)
|
|
|
|
set(arg_LOGFILE_ROOT "build")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2020-05-22 01:46:07 +08:00
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if(NOT DEFINED arg_BUILD_TARGET)
|
|
|
|
set(arg_BUILD_TARGET "all")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2020-05-22 01:46:07 +08:00
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if (NOT DEFINED arg_MAKEFILE)
|
|
|
|
set(arg_MAKEFILE Makefile)
|
2020-11-21 02:29:25 +08:00
|
|
|
endif()
|
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if(NOT DEFINED arg_INSTALL_TARGET)
|
|
|
|
set(arg_INSTALL_TARGET "install")
|
2020-12-19 04:00:45 +08:00
|
|
|
endif()
|
|
|
|
|
2020-05-22 01:46:07 +08:00
|
|
|
if(WIN32)
|
2021-10-21 05:12:58 +08:00
|
|
|
set(Z_VCPKG_INSTALLED ${CURRENT_INSTALLED_DIR})
|
2020-05-22 01:46:07 +08:00
|
|
|
else()
|
2021-10-21 05:12:58 +08:00
|
|
|
string(REPLACE " " "\ " Z_VCPKG_INSTALLED "${CURRENT_INSTALLED_DIR}")
|
2020-05-22 01:46:07 +08:00
|
|
|
endif()
|
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
vcpkg_list(SET make_opts)
|
|
|
|
vcpkg_list(SET install_opts)
|
2020-05-22 01:46:07 +08:00
|
|
|
if (CMAKE_HOST_WIN32)
|
2021-10-21 05:12:58 +08:00
|
|
|
set(path_backup "$ENV{PATH}")
|
2020-05-22 01:46:07 +08:00
|
|
|
vcpkg_add_to_path(PREPEND "${SCRIPTS}/buildsystems/make_wrapper")
|
2021-08-07 22:48:44 +08:00
|
|
|
if(NOT DEFINED Z_VCPKG_MAKE)
|
|
|
|
vcpkg_acquire_msys(MSYS_ROOT)
|
|
|
|
find_program(Z_VCPKG_MAKE make PATHS "${MSYS_ROOT}/usr/bin" NO_DEFAULT_PATH REQUIRED)
|
|
|
|
endif()
|
2021-10-21 05:12:58 +08:00
|
|
|
set(make_command "${Z_VCPKG_MAKE}")
|
2022-11-12 02:33:51 +08:00
|
|
|
vcpkg_list(SET make_opts ${arg_OPTIONS} -j ${VCPKG_CONCURRENCY} --trace -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
|
|
|
|
vcpkg_list(SET no_parallel_make_opts ${arg_OPTIONS} -j 1 --trace -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
|
2020-05-22 01:46:07 +08:00
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
string(REPLACE " " [[\ ]] vcpkg_package_prefix "${CURRENT_PACKAGES_DIR}")
|
|
|
|
string(REGEX REPLACE [[([a-zA-Z]):/]] [[/\1/]] vcpkg_package_prefix "${vcpkg_package_prefix}")
|
|
|
|
vcpkg_list(SET install_opts -j ${VCPKG_CONCURRENCY} --trace -f ${arg_MAKEFILE} ${arg_INSTALL_TARGET} DESTDIR=${vcpkg_package_prefix})
|
2022-10-09 12:36:46 +08:00
|
|
|
vcpkg_list(SET no_parallel_install_opts -j 1 --trace -f ${arg_MAKEFILE} ${arg_INSTALL_TARGET} DESTDIR=${vcpkg_package_prefix})
|
2020-05-22 01:46:07 +08:00
|
|
|
#TODO: optimize for install-data (release) and install-exec (release/debug)
|
2021-11-26 16:25:40 +08:00
|
|
|
|
2019-10-05 22:51:07 +08:00
|
|
|
else()
|
2020-11-24 01:43:23 +08:00
|
|
|
if(VCPKG_HOST_IS_OPENBSD)
|
2021-08-07 22:48:44 +08:00
|
|
|
find_program(Z_VCPKG_MAKE gmake REQUIRED)
|
2020-11-24 01:43:23 +08:00
|
|
|
else()
|
2021-08-07 22:48:44 +08:00
|
|
|
find_program(Z_VCPKG_MAKE make REQUIRED)
|
2020-11-24 01:43:23 +08:00
|
|
|
endif()
|
2021-10-21 05:12:58 +08:00
|
|
|
set(make_command "${Z_VCPKG_MAKE}")
|
2022-11-12 02:33:51 +08:00
|
|
|
vcpkg_list(SET make_opts ${arg_OPTIONS} V=1 -j ${VCPKG_CONCURRENCY} -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
|
|
|
|
vcpkg_list(SET no_parallel_make_opts ${arg_OPTIONS} V=1 -j 1 -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
|
2021-10-21 05:12:58 +08:00
|
|
|
vcpkg_list(SET install_opts -j ${VCPKG_CONCURRENCY} -f ${arg_MAKEFILE} ${arg_INSTALL_TARGET} DESTDIR=${CURRENT_PACKAGES_DIR})
|
2022-10-09 12:36:46 +08:00
|
|
|
vcpkg_list(SET no_parallel_install_opts -j 1 -f ${arg_MAKEFILE} ${arg_INSTALL_TARGET} DESTDIR=${CURRENT_PACKAGES_DIR})
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2020-06-04 10:31:28 +08:00
|
|
|
|
2020-08-14 04:32:55 +08:00
|
|
|
# Since includes are buildtype independent those are setup by vcpkg_configure_make
|
2022-02-16 10:31:16 +08:00
|
|
|
vcpkg_backup_env_variables(VARS LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH CPPFLAGS CFLAGS CXXFLAGS RCFLAGS)
|
2021-10-21 05:12:58 +08:00
|
|
|
|
|
|
|
foreach(buildtype IN ITEMS "debug" "release")
|
2022-03-03 05:43:19 +08:00
|
|
|
if (buildtype STREQUAL "debug" AND _VCPKG_MAKE_NO_DEBUG)
|
|
|
|
continue()
|
|
|
|
endif()
|
2021-10-21 05:12:58 +08:00
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "${buildtype}")
|
|
|
|
if("${buildtype}" STREQUAL "debug")
|
|
|
|
set(short_buildtype "-dbg")
|
|
|
|
set(cmake_buildtype "DEBUG")
|
|
|
|
set(path_suffix "/debug")
|
2019-10-05 22:51:07 +08:00
|
|
|
else()
|
|
|
|
# In NO_DEBUG mode, we only use ${TARGET_TRIPLET} directory.
|
2021-10-21 05:12:58 +08:00
|
|
|
set(short_buildtype "-rel")
|
|
|
|
set(cmake_buildtype "RELEASE")
|
|
|
|
set(path_suffix "")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2020-06-04 10:31:28 +08:00
|
|
|
|
2021-11-26 16:25:40 +08:00
|
|
|
set(working_directory "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}${short_buildtype}/${arg_SUBPATH}")
|
2021-10-21 05:12:58 +08:00
|
|
|
message(STATUS "Building ${TARGET_TRIPLET}${short_buildtype}")
|
2019-10-05 22:51:07 +08:00
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
z_vcpkg_extract_cpp_flags_and_set_cflags_and_cxxflags("${cmake_buildtype}")
|
2020-11-18 01:18:59 +08:00
|
|
|
|
2020-11-11 01:52:02 +08:00
|
|
|
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
|
2022-02-16 10:31:16 +08:00
|
|
|
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_CMAKE_STATIC_LINKER_FLAGS_${cmake_buildtype}}")
|
2020-11-11 01:52:02 +08:00
|
|
|
else() # dynamic
|
2022-02-16 10:31:16 +08:00
|
|
|
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_CMAKE_SHARED_LINKER_FLAGS_${cmake_buildtype}}")
|
|
|
|
endif()
|
|
|
|
set(LDFLAGS_${cmake_buildtype} "")
|
|
|
|
if(EXISTS "${Z_VCPKG_INSTALLED}${path_suffix}/lib")
|
|
|
|
string(APPEND LDFLAGS_${cmake_buildtype} " -L${Z_VCPKG_INSTALLED}${path_suffix}/lib")
|
|
|
|
endif()
|
|
|
|
if(EXISTS "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
|
|
|
|
string(APPEND LDFLAGS_${cmake_buildtype} " -L${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
|
2020-11-11 01:52:02 +08:00
|
|
|
endif()
|
2021-10-21 05:12:58 +08:00
|
|
|
if (CMAKE_HOST_WIN32 AND VCPKG_DETECTED_CMAKE_C_COMPILER MATCHES "cl.exe")
|
|
|
|
set(LINK_ENV_${cmake_buildtype} "$ENV{_LINK_} ${LINKER_FLAGS_${cmake_buildtype}}")
|
2020-11-11 01:52:02 +08:00
|
|
|
else()
|
2022-02-16 10:31:16 +08:00
|
|
|
string(APPEND LDFLAGS_${cmake_buildtype} " ${LINKER_FLAGS_${cmake_buildtype}}")
|
2020-11-11 01:52:02 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Setup environment
|
2021-10-21 05:12:58 +08:00
|
|
|
set(ENV{CPPFLAGS} "${CPPFLAGS_${cmake_buildtype}}")
|
|
|
|
set(ENV{CFLAGS} "${CFLAGS_${cmake_buildtype}}")
|
|
|
|
set(ENV{CXXFLAGS} "${CXXFLAGS_${cmake_buildtype}}")
|
|
|
|
set(ENV{RCFLAGS} "${VCPKG_DETECTED_CMAKE_RC_FLAGS_${cmake_buildtype}}")
|
|
|
|
set(ENV{LDFLAGS} "${LDFLAGS_${cmake_buildtype}}")
|
2022-02-16 10:31:16 +08:00
|
|
|
vcpkg_list(APPEND lib_env_vars LIB LIBPATH LIBRARY_PATH) # LD_LIBRARY_PATH)
|
|
|
|
foreach(lib_env_var IN LISTS lib_env_vars)
|
|
|
|
if(EXISTS "${Z_VCPKG_INSTALLED}${path_suffix}/lib")
|
|
|
|
vcpkg_host_path_list(PREPEND ENV{${lib_env_var}} "${Z_VCPKG_INSTALLED}${path_suffix}/lib")
|
|
|
|
endif()
|
|
|
|
if(EXISTS "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
|
|
|
|
vcpkg_host_path_list(PREPEND ENV{${lib_env_var}} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
unset(lib_env_vars)
|
|
|
|
|
|
|
|
if(LINK_ENV_${cmake_buildtype})
|
2021-10-21 05:12:58 +08:00
|
|
|
set(config_link_backup "$ENV{_LINK_}")
|
2022-02-16 10:31:16 +08:00
|
|
|
set(ENV{_LINK_} "${LINK_ENV_${cmake_buildtype}}")
|
2020-11-11 01:52:02 +08:00
|
|
|
endif()
|
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if(arg_ADD_BIN_TO_PATH)
|
|
|
|
set(env_backup_path "$ENV{PATH}")
|
|
|
|
vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}${path_suffix}/bin")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
vcpkg_list(SET make_cmd_line ${make_command} ${make_opts})
|
|
|
|
vcpkg_list(SET no_parallel_make_cmd_line ${make_command} ${no_parallel_make_opts})
|
2020-11-11 01:52:02 +08:00
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if (arg_DISABLE_PARALLEL)
|
2020-08-20 12:15:24 +08:00
|
|
|
vcpkg_execute_build_process(
|
2021-10-21 05:12:58 +08:00
|
|
|
COMMAND ${no_parallel_make_cmd_line}
|
|
|
|
WORKING_DIRECTORY "${working_directory}"
|
|
|
|
LOGNAME "${arg_LOGFILE_ROOT}-${TARGET_TRIPLET}${short_buildtype}"
|
2020-08-20 12:15:24 +08:00
|
|
|
)
|
|
|
|
else()
|
2020-11-11 01:52:02 +08:00
|
|
|
vcpkg_execute_build_process(
|
2021-10-21 05:12:58 +08:00
|
|
|
COMMAND ${make_cmd_line}
|
|
|
|
NO_PARALLEL_COMMAND ${no_parallel_make_cmd_line}
|
|
|
|
WORKING_DIRECTORY "${working_directory}"
|
|
|
|
LOGNAME "${arg_LOGFILE_ROOT}-${TARGET_TRIPLET}${short_buildtype}"
|
2020-11-11 01:52:02 +08:00
|
|
|
)
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2020-06-04 10:31:28 +08:00
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
file(READ "${CURRENT_BUILDTREES_DIR}/${arg_LOGFILE_ROOT}-${TARGET_TRIPLET}${short_buildtype}-out.log" logdata)
|
|
|
|
if(logdata MATCHES "Warning: linker path does not have real file for library")
|
2020-11-18 01:18:59 +08:00
|
|
|
message(FATAL_ERROR "libtool could not find a file being linked against!")
|
|
|
|
endif()
|
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if (arg_ENABLE_INSTALL)
|
|
|
|
message(STATUS "Installing ${TARGET_TRIPLET}${short_buildtype}")
|
|
|
|
vcpkg_list(SET make_cmd_line ${make_command} ${install_opts})
|
2022-10-09 12:36:46 +08:00
|
|
|
vcpkg_list(SET no_parallel_make_cmd_line ${make_command} ${no_parallel_install_opts})
|
2020-05-22 01:46:07 +08:00
|
|
|
vcpkg_execute_build_process(
|
2021-10-21 05:12:58 +08:00
|
|
|
COMMAND ${make_cmd_line}
|
2022-10-09 12:36:46 +08:00
|
|
|
NO_PARALLEL_COMMAND ${no_parallel_make_cmd_line}
|
2021-10-21 05:12:58 +08:00
|
|
|
WORKING_DIRECTORY "${working_directory}"
|
|
|
|
LOGNAME "install-${TARGET_TRIPLET}${short_buildtype}"
|
2020-05-22 01:46:07 +08:00
|
|
|
)
|
2020-11-11 01:52:02 +08:00
|
|
|
endif()
|
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if(config_link_backup)
|
|
|
|
set(ENV{_LINK_} "${config_link_backup}")
|
|
|
|
unset(config_link_backup)
|
2020-11-11 01:52:02 +08:00
|
|
|
endif()
|
2020-05-22 01:46:07 +08:00
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if(arg_ADD_BIN_TO_PATH)
|
|
|
|
set(ENV{PATH} "${env_backup_path}")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2020-11-11 01:52:02 +08:00
|
|
|
endif()
|
2022-01-05 12:00:21 +08:00
|
|
|
|
|
|
|
vcpkg_restore_env_variables(VARS LIB LIBPATH LIBRARY_PATH)
|
2020-11-11 01:52:02 +08:00
|
|
|
endforeach()
|
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
if (arg_ENABLE_INSTALL)
|
|
|
|
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" Z_VCPKG_INSTALL_PREFIX "${CURRENT_INSTALLED_DIR}")
|
2020-05-22 01:46:07 +08:00
|
|
|
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}_tmp")
|
|
|
|
file(RENAME "${CURRENT_PACKAGES_DIR}" "${CURRENT_PACKAGES_DIR}_tmp")
|
2021-10-21 05:12:58 +08:00
|
|
|
file(RENAME "${CURRENT_PACKAGES_DIR}_tmp${Z_VCPKG_INSTALL_PREFIX}" "${CURRENT_PACKAGES_DIR}")
|
2020-05-22 01:46:07 +08:00
|
|
|
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}_tmp")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2020-05-22 01:46:07 +08:00
|
|
|
|
2021-01-17 11:53:05 +08:00
|
|
|
# Remove libtool files since they contain absolute paths and are not necessary.
|
2021-10-21 05:12:58 +08:00
|
|
|
file(GLOB_RECURSE libtool_files "${CURRENT_PACKAGES_DIR}/**/*.la")
|
|
|
|
if(libtool_files)
|
|
|
|
file(REMOVE ${libtool_files})
|
2021-01-17 11:53:05 +08:00
|
|
|
endif()
|
|
|
|
|
2019-10-05 22:51:07 +08:00
|
|
|
if (CMAKE_HOST_WIN32)
|
2021-10-21 05:12:58 +08:00
|
|
|
set(ENV{PATH} "${path_backup}")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2020-06-04 10:31:28 +08:00
|
|
|
|
2022-02-16 10:31:16 +08:00
|
|
|
vcpkg_restore_env_variables(VARS LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH CPPFLAGS CFLAGS CXXFLAGS RCFLAGS)
|
2022-03-03 05:43:19 +08:00
|
|
|
unset(_VCPKG_MAKE_NO_DEBUG PARENT_SCOPE)
|
2019-10-05 22:51:07 +08:00
|
|
|
endfunction()
|