Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scripts-audit] Make buildsystem #20165

Merged
merged 29 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 102 additions & 94 deletions scripts/cmake/vcpkg_build_make.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,193 +55,201 @@ function(vcpkg_build_make)
include("${cmake_vars_file}")

# parse parameters such that semicolons in options arguments to COMMAND don't get erased
cmake_parse_arguments(PARSE_ARGV 0 _bc "ADD_BIN_TO_PATH;ENABLE_INSTALL;DISABLE_PARALLEL" "LOGFILE_ROOT;BUILD_TARGET;SUBPATH;MAKEFILE;INSTALL_TARGET" "")
cmake_parse_arguments(PARSE_ARGV 0 arg
"ADD_BIN_TO_PATH;ENABLE_INSTALL;DISABLE_PARALLEL"
"LOGFILE_ROOT;BUILD_TARGET;SUBPATH;MAKEFILE;INSTALL_TARGET"
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
""
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
)

if(DEFINED arg_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "vcpkg_make_build was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
endif()

if(NOT _bc_LOGFILE_ROOT)
set(_bc_LOGFILE_ROOT "build")
if(NOT DEFINED arg_LOGFILE_ROOT)
set(arg_LOGFILE_ROOT "build")
endif()

if(NOT _bc_BUILD_TARGET)
set(_bc_BUILD_TARGET "all")
if(NOT DEFINED arg_BUILD_TARGET)
set(arg_BUILD_TARGET "all")
endif()

if (NOT _bc_MAKEFILE)
set(_bc_MAKEFILE Makefile)
if (NOT DEFINED arg_MAKEFILE)
set(arg_MAKEFILE Makefile)
endif()

if(NOT _bc_INSTALL_TARGET)
set(_bc_INSTALL_TARGET "install")
if(NOT DEFINED arg_INSTALL_TARGET)
set(arg_INSTALL_TARGET "install")
endif()

if(WIN32)
set(_VCPKG_PREFIX ${CURRENT_PACKAGES_DIR})
set(_VCPKG_INSTALLED ${CURRENT_INSTALLED_DIR})
set(Z_VCPKG_PREFIX ${CURRENT_PACKAGES_DIR})
set(Z_VCPKG_INSTALLED ${CURRENT_INSTALLED_DIR})
else()
string(REPLACE " " "\ " _VCPKG_PREFIX "${CURRENT_PACKAGES_DIR}")
string(REPLACE " " "\ " _VCPKG_INSTALLED "${CURRENT_INSTALLED_DIR}")
string(REPLACE " " "\ " Z_VCPKG_PREFIX "${CURRENT_PACKAGES_DIR}")
string(REPLACE " " "\ " Z_VCPKG_INSTALLED "${CURRENT_INSTALLED_DIR}")
endif()
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved

set(MAKE_OPTS )
set(INSTALL_OPTS )
set(make_opts )
set(install_opts )
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
if (CMAKE_HOST_WIN32)
set(PATH_GLOBAL "$ENV{PATH}")
set(path_global "$ENV{PATH}")
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
vcpkg_add_to_path(PREPEND "${SCRIPTS}/buildsystems/make_wrapper")
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()
set(MAKE_COMMAND "${Z_VCPKG_MAKE}")
set(MAKE_OPTS ${_bc_MAKE_OPTIONS} -j ${VCPKG_CONCURRENCY} --trace -f ${_bc_MAKEFILE} ${_bc_BUILD_TARGET})
set(NO_PARALLEL_MAKE_OPTS ${_bc_MAKE_OPTIONS} -j 1 --trace -f ${_bc_MAKEFILE} ${_bc_BUILD_TARGET})
set(make_command "${Z_VCPKG_MAKE}")
set(make_opts ${arg_MAKE_OPTIONS} -j ${VCPKG_CONCURRENCY} --trace -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
set(no_parallel_make_opts ${arg_MAKE_OPTIONS} -j 1 --trace -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved

string(REPLACE " " "\\\ " _VCPKG_PACKAGE_PREFIX ${CURRENT_PACKAGES_DIR})
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_PACKAGE_PREFIX "${_VCPKG_PACKAGE_PREFIX}")
set(INSTALL_OPTS -j ${VCPKG_CONCURRENCY} --trace -f ${_bc_MAKEFILE} ${_bc_INSTALL_TARGET} DESTDIR=${_VCPKG_PACKAGE_PREFIX})
string(REPLACE " " "\\\ " Z_VCPKG_PACKAGE_PREFIX ${CURRENT_PACKAGES_DIR})
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" Z_VCPKG_PACKAGE_PREFIX "${Z_VCPKG_PACKAGE_PREFIX}")
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
set(install_opts -j ${VCPKG_CONCURRENCY} --trace -f ${arg_MAKEFILE} ${arg_INSTALL_TARGET} DESTDIR=${Z_VCPKG_PACKAGE_PREFIX})
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
#TODO: optimize for install-data (release) and install-exec (release/debug)
else()
if(VCPKG_HOST_IS_OPENBSD)
find_program(Z_VCPKG_MAKE gmake REQUIRED)
else()
find_program(Z_VCPKG_MAKE make REQUIRED)
endif()
set(MAKE_COMMAND "${Z_VCPKG_MAKE}")
set(MAKE_OPTS ${_bc_MAKE_OPTIONS} V=1 -j ${VCPKG_CONCURRENCY} -f ${_bc_MAKEFILE} ${_bc_BUILD_TARGET})
set(NO_PARALLEL_MAKE_OPTS ${_bc_MAKE_OPTIONS} V=1 -j 1 -f ${_bc_MAKEFILE} ${_bc_BUILD_TARGET})
set(INSTALL_OPTS -j ${VCPKG_CONCURRENCY} -f ${_bc_MAKEFILE} ${_bc_INSTALL_TARGET} DESTDIR=${CURRENT_PACKAGES_DIR})
set(make_command "${Z_VCPKG_MAKE}")
set(make_opts ${arg_MAKE_OPTIONS} V=1 -j ${VCPKG_CONCURRENCY} -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
set(no_parallel_make_opts ${arg_MAKE_OPTIONS} V=1 -j 1 -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
set(install_opts -j ${VCPKG_CONCURRENCY} -f ${arg_MAKEFILE} ${arg_INSTALL_TARGET} DESTDIR=${CURRENT_PACKAGES_DIR})
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
endif()

# Since includes are buildtype independent those are setup by vcpkg_configure_make
_vcpkg_backup_env_variables(LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)
z_vcpkg_backup_env_variables(LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)

foreach(BUILDTYPE "debug" "release")
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL BUILDTYPE)
if(BUILDTYPE STREQUAL "debug")
foreach(buildtype IN ITEMS "debug" "release")
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL buildtype)
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
if(buildtype STREQUAL "debug")
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
# Skip debug generate
if (_VCPKG_NO_DEBUG)
if (Z_VCPKG_NO_DEBUG)
continue()
endif()
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
set(SHORT_BUILDTYPE "-dbg")
set(CMAKE_BUILDTYPE "DEBUG")
set(PATH_SUFFIX "/debug")
set(short_buildtype "-dbg")
set(cmake_buildtype "DEBUG")
set(path_suffix "/debug")
else()
# In NO_DEBUG mode, we only use ${TARGET_TRIPLET} directory.
if (_VCPKG_NO_DEBUG)
set(SHORT_BUILDTYPE "")
if (Z_VCPKG_NO_DEBUG)
set(short_buildtype "")
else()
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
set(SHORT_BUILDTYPE "-rel")
set(short_buildtype "-rel")
endif()
set(CMAKE_BUILDTYPE "RELEASE")
set(PATH_SUFFIX "")
set(cmake_buildtype "RELEASE")
set(path_suffix "")
endif()

set(WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}${SHORT_BUILDTYPE}${_bc_SUBPATH}")
message(STATUS "Building ${TARGET_TRIPLET}${SHORT_BUILDTYPE}")
set(working_directory "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}${short_buildtype}${arg_SUBPATH}")
message(STATUS "Building ${TARGET_TRIPLET}${short_buildtype}")

_vcpkg_extract_cpp_flags_and_set_cflags_and_cxxflags(${CMAKE_BUILDTYPE})
z_vcpkg_extract_cpp_flags_and_set_cflags_and_cxxflags(${cmake_buildtype})
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
set(LINKER_FLAGS_${CMAKE_BUILDTYPE} "${VCPKG_DETECTED_STATIC_LINKER_FLAGS_${CMAKE_BUILDTYPE}}")
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_STATIC_LINKER_FLAGS_${cmake_buildtype}}")
else() # dynamic
set(LINKER_FLAGS_${CMAKE_BUILDTYPE} "${VCPKG_DETECTED_SHARED_LINKER_FLAGS_${CMAKE_BUILDTYPE}}")
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_SHARED_LINKER_FLAGS_${cmake_buildtype}}")
endif()
if (CMAKE_HOST_WIN32 AND VCPKG_DETECTED_C_COMPILER MATCHES "cl.exe")
set(LDFLAGS_${CMAKE_BUILDTYPE} "-L${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib -L${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib/manual-link")
set(LINK_ENV_${CMAKE_BUILDTYPE} "$ENV{_LINK_} ${LINKER_FLAGS_${CMAKE_BUILDTYPE}}")
set(LDFLAGS_${cmake_buildtype} "-L${Z_VCPKG_INSTALLED}${path_suffix}/lib -L${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
set(LINK_ENV_${cmake_buildtype} "$ENV{_LINK_} ${LINKER_FLAGS_${cmake_buildtype}}")
else()
set(LDFLAGS_${CMAKE_BUILDTYPE} "-L${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib -L${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib/manual-link ${LINKER_FLAGS_${CMAKE_BUILDTYPE}}")
set(LDFLAGS_${cmake_buildtype} "-L${Z_VCPKG_INSTALLED}${path_suffix}/lib -L${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link ${LINKER_FLAGS_${cmake_buildtype}}")
endif()

# Setup environment
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}}")
set(ENV{LIB} "${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib/${VCPKG_HOST_PATH_SEPARATOR}${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib/manual-link/${LIB_PATHLIKE_CONCAT}")
set(ENV{LIBPATH} "${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib/${VCPKG_HOST_PATH_SEPARATOR}${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib/manual-link/${LIBPATH_PATHLIKE_CONCAT}")
set(ENV{LIBRARY_PATH} "${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib/${VCPKG_HOST_PATH_SEPARATOR}${_VCPKG_INSTALLED}${PATH_SUFFIX}/lib/manual-link/${LIBRARY_PATH_PATHLIKE_CONCAT}")
#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}")
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}}")
set(ENV{LIB} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/${VCPKG_HOST_PATH_SEPARATOR}${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link/${LIB_PATHLIKE_CONCAT}")
set(ENV{LIBPATH} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/${VCPKG_HOST_PATH_SEPARATOR}${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link/${LIBPATH_PATHLIKE_CONCAT}")
set(ENV{LIBRARY_PATH} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/${VCPKG_HOST_PATH_SEPARATOR}${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link/${LIBRARY_PATH_PATHLIKE_CONCAT}")
#set(ENV{LD_LIBRARY_PATH} "${Z_VCPKG_INSTALLED}${path_suffix_${buildtype}}/lib/${VCPKG_HOST_PATH_SEPARATOR}${Z_VCPKG_INSTALLED}${path_suffix_${buildtype}}/lib/manual-link/${LD_LIBRARY_PATH_PATHLIKE_CONCAT}")

if(LINK_ENV_${_VAR_SUFFIX})
set(_LINK_CONFIG_BACKUP "$ENV{_LINK_}")
set(config_link_backup "$ENV{_LINK_}")
set(ENV{_LINK_} "${LINK_ENV_${_VAR_SUFFIX}}")
endif()

if(_bc_ADD_BIN_TO_PATH)
set(_BACKUP_ENV_PATH "$ENV{PATH}")
vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}${PATH_SUFFIX}/bin")
if(arg_ADD_BIN_TO_PATH)
set(env_backup_path "$ENV{PATH}")
vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}${path_suffix}/bin")
endif()

if(MAKE_BASH)
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
set(MAKE_CMD_LINE "${MAKE_COMMAND} ${MAKE_OPTS}")
set(NO_PARALLEL_MAKE_CMD_LINE "${MAKE_COMMAND} ${NO_PARALLEL_MAKE_OPTS}")
set(make_cmd_line "${make_command} ${make_opts}")
set(no_parallel_make_cmd_line "${make_command} ${no_parallel_make_opts}")
else()
set(MAKE_CMD_LINE ${MAKE_COMMAND} ${MAKE_OPTS})
set(NO_PARALLEL_MAKE_CMD_LINE ${MAKE_COMMAND} ${NO_PARALLEL_MAKE_OPTS})
set(make_cmd_line ${make_command} ${make_opts})
set(no_parallel_make_cmd_line ${make_command} ${no_parallel_make_opts})
endif()

if (_bc_DISABLE_PARALLEL)
if (arg_DISABLE_PARALLEL)
vcpkg_execute_build_process(
COMMAND ${MAKE_BASH} ${NO_PARALLEL_MAKE_CMD_LINE}
WORKING_DIRECTORY "${WORKING_DIRECTORY}"
LOGNAME "${_bc_LOGFILE_ROOT}-${TARGET_TRIPLET}${SHORT_BUILDTYPE}"
COMMAND "${MAKE_BASH}" ${no_parallel_make_cmd_line}
WORKING_DIRECTORY "${working_directory}"
LOGNAME "${arg_LOGFILE_ROOT}-${TARGET_TRIPLET}${short_buildtype}"
)
else()
vcpkg_execute_build_process(
COMMAND ${MAKE_BASH} ${MAKE_CMD_LINE}
NO_PARALLEL_COMMAND ${MAKE_BASH} ${NO_PARALLEL_MAKE_CMD_LINE}
WORKING_DIRECTORY "${WORKING_DIRECTORY}"
LOGNAME "${_bc_LOGFILE_ROOT}-${TARGET_TRIPLET}${SHORT_BUILDTYPE}"
COMMAND "${MAKE_BASH}" ${make_cmd_line}
NO_PARALLEL_COMMAND "${MAKE_BASH}" ${no_parallel_make_cmd_line}
WORKING_DIRECTORY "${working_directory}"
LOGNAME "${arg_LOGFILE_ROOT}-${TARGET_TRIPLET}${short_buildtype}"
)
endif()

file(READ "${CURRENT_BUILDTREES_DIR}/${_bc_LOGFILE_ROOT}-${TARGET_TRIPLET}${SHORT_BUILDTYPE}-out.log" LOGDATA)
if(LOGDATA MATCHES "Warning: linker path does not have real file for library")
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")
message(FATAL_ERROR "libtool could not find a file being linked against!")
endif()

if (_bc_ENABLE_INSTALL)
message(STATUS "Installing ${TARGET_TRIPLET}${SHORT_BUILDTYPE}")
if (arg_ENABLE_INSTALL)
message(STATUS "Installing ${TARGET_TRIPLET}${short_buildtype}")
if(MAKE_BASH)
set(MAKE_CMD_LINE "${MAKE_COMMAND} ${INSTALL_OPTS}")
set(make_cmd_line "${make_command} ${install_opts}")
else()
set(MAKE_CMD_LINE ${MAKE_COMMAND} ${INSTALL_OPTS})
set(make_cmd_line ${make_command} ${install_opts})
endif()
vcpkg_execute_build_process(
COMMAND ${MAKE_BASH} ${MAKE_CMD_LINE}
WORKING_DIRECTORY "${WORKING_DIRECTORY}"
LOGNAME "install-${TARGET_TRIPLET}${SHORT_BUILDTYPE}"
COMMAND "${MAKE_BASH}" ${make_cmd_line}
WORKING_DIRECTORY "${working_directory}"
LOGNAME "install-${TARGET_TRIPLET}${short_buildtype}"
)
endif()

if(_LINK_CONFIG_BACKUP)
set(ENV{_LINK_} "${_LINK_CONFIG_BACKUP}")
unset(_LINK_CONFIG_BACKUP)
if(config_link_backup)
set(ENV{_LINK_} "${config_link_backup}")
unset(config_link_backup)
endif()

if(_bc_ADD_BIN_TO_PATH)
set(ENV{PATH} "${_BACKUP_ENV_PATH}")
if(arg_ADD_BIN_TO_PATH)
set(ENV{PATH} "${env_backup_path}")
endif()
endif()
endforeach()

if (_bc_ENABLE_INSTALL)
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_INSTALL_PREFIX "${CURRENT_INSTALLED_DIR}")
if (arg_ENABLE_INSTALL)
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" Z_VCPKG_INSTALL_PREFIX "${CURRENT_INSTALLED_DIR}")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}_tmp")
file(RENAME "${CURRENT_PACKAGES_DIR}" "${CURRENT_PACKAGES_DIR}_tmp")
file(RENAME "${CURRENT_PACKAGES_DIR}_tmp${_VCPKG_INSTALL_PREFIX}" "${CURRENT_PACKAGES_DIR}")
file(RENAME "${CURRENT_PACKAGES_DIR}_tmp${Z_VCPKG_INSTALL_PREFIX}" "${CURRENT_PACKAGES_DIR}")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}_tmp")
endif()

# Remove libtool files since they contain absolute paths and are not necessary.
file(GLOB_RECURSE LIBTOOL_FILES "${CURRENT_PACKAGES_DIR}/**/*.la")
if(LIBTOOL_FILES)
file(REMOVE ${LIBTOOL_FILES})
file(GLOB_RECURSE libtool_files "${CURRENT_PACKAGES_DIR}/**/*.la")
if(libtool_files)
file(REMOVE ${libtool_files})
endif()

if (CMAKE_HOST_WIN32)
set(ENV{PATH} "${PATH_GLOBAL}")
set(ENV{PATH} "${path_global}")
endif()

_vcpkg_restore_env_variables(LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)
z_vcpkg_restore_env_variables(LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)
endfunction()
Loading