2020-12-02 05:37:26 +08:00
|
|
|
#[===[.md:
|
|
|
|
# vcpkg_build_make
|
|
|
|
|
|
|
|
Build a linux makefile project.
|
|
|
|
|
|
|
|
## Usage:
|
|
|
|
```cmake
|
|
|
|
vcpkg_build_make([BUILD_TARGET <target>]
|
|
|
|
[ADD_BIN_TO_PATH]
|
|
|
|
[ENABLE_INSTALL]
|
|
|
|
[MAKEFILE <makefileName>]
|
|
|
|
[LOGFILE_ROOT <logfileroot>])
|
|
|
|
```
|
|
|
|
|
|
|
|
### BUILD_TARGET
|
|
|
|
The target passed to the make build command (`./make <target>`). If not specified, the 'all' target will
|
|
|
|
be passed.
|
|
|
|
|
|
|
|
### ADD_BIN_TO_PATH
|
|
|
|
Adds the appropriate Release and Debug `bin\` directories to the path during the build such that executables can run against the in-tree DLLs.
|
|
|
|
|
|
|
|
### ENABLE_INSTALL
|
|
|
|
IF the port supports the install target use vcpkg_install_make() instead of vcpkg_build_make()
|
|
|
|
|
|
|
|
### MAKEFILE
|
|
|
|
Specifies the Makefile as a relative path from the root of the sources passed to `vcpkg_configure_make()`
|
|
|
|
|
|
|
|
### BUILD_TARGET
|
2020-12-19 04:00:45 +08:00
|
|
|
The target passed to the make build command (`./make <target>`). Defaults to 'all'.
|
|
|
|
|
|
|
|
### INSTALL_TARGET
|
|
|
|
The target passed to the make build command (`./make <target>`) if `ENABLE_INSTALL` is used. Defaults to 'install'.
|
2020-12-02 05:37:26 +08:00
|
|
|
|
|
|
|
### DISABLE_PARALLEL
|
|
|
|
The underlying buildsystem will be instructed to not parallelize
|
|
|
|
|
|
|
|
### SUBPATH
|
|
|
|
Additional subdir to invoke make in. Useful if only parts of a port should be built.
|
|
|
|
|
|
|
|
## Notes:
|
2021-05-10 01:48:42 +08:00
|
|
|
This command should be preceded by a call to [`vcpkg_configure_make()`](vcpkg_configure_make.md).
|
2021-01-06 04:37:19 +08:00
|
|
|
You can use the alias [`vcpkg_install_make()`](vcpkg_install_make.md) function if your makefile supports the
|
2020-12-02 05:37:26 +08:00
|
|
|
"install" target
|
|
|
|
|
|
|
|
## 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)
|
|
|
|
#]===]
|
|
|
|
|
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}")
|
|
|
|
vcpkg_list(SET make_opts ${arg_OPTIONS} ${arg_MAKE_OPTIONS} -j ${VCPKG_CONCURRENCY} --trace -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
|
|
|
|
vcpkg_list(SET no_parallel_make_opts ${arg_OPTIONS} ${arg_MAKE_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})
|
2020-05-22 01:46:07 +08:00
|
|
|
#TODO: optimize for install-data (release) and install-exec (release/debug)
|
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}")
|
|
|
|
vcpkg_list(SET make_opts ${arg_MAKE_OPTIONS} V=1 -j ${VCPKG_CONCURRENCY} -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
|
|
|
|
vcpkg_list(SET no_parallel_make_opts ${arg_MAKE_OPTIONS} V=1 -j 1 -f ${arg_MAKEFILE} ${arg_BUILD_TARGET})
|
|
|
|
vcpkg_list(SET install_opts -j ${VCPKG_CONCURRENCY} -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
|
2021-10-21 05:12:58 +08:00
|
|
|
vcpkg_backup_env_variables(VARS LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)
|
|
|
|
|
|
|
|
foreach(buildtype IN ITEMS "debug" "release")
|
|
|
|
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-10-21 05:12:58 +08:00
|
|
|
set(working_directory "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}${short_buildtype}${arg_SUBPATH}")
|
|
|
|
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")
|
2021-10-21 05:12:58 +08:00
|
|
|
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_STATIC_LINKER_FLAGS_${cmake_buildtype}}")
|
2020-11-11 01:52:02 +08:00
|
|
|
else() # dynamic
|
2021-10-21 05:12:58 +08:00
|
|
|
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_SHARED_LINKER_FLAGS_${cmake_buildtype}}")
|
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(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}}")
|
2020-11-11 01:52:02 +08:00
|
|
|
else()
|
2021-10-21 05:12:58 +08:00
|
|
|
set(LDFLAGS_${cmake_buildtype} "-L${Z_VCPKG_INSTALLED}${path_suffix}/lib -L${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link ${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}}")
|
|
|
|
vcpkg_host_path_list(PREPEND ENV{LIB} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/" "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link/")
|
|
|
|
vcpkg_host_path_list(PREPEND ENV{LIBPATH} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/" "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link/")
|
|
|
|
vcpkg_host_path_list(PREPEND ENV{LIBRARY_PATH} "${Z_VCPKG_INSTALLED}${path_suffix_${buildtype}}/lib/" "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link/")
|
|
|
|
#vcpkg_host_path_list(PREPEND ENV{LD_LIBRARY_PATH} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/" "${Z_VCPKG_INSTALLED}${path_suffix_${buildtype}}/lib/manual-link/")
|
2020-08-14 04:32:55 +08:00
|
|
|
|
2020-11-11 01:52:02 +08:00
|
|
|
if(LINK_ENV_${_VAR_SUFFIX})
|
2021-10-21 05:12:58 +08:00
|
|
|
set(config_link_backup "$ENV{_LINK_}")
|
2020-11-11 01:52:02 +08:00
|
|
|
set(ENV{_LINK_} "${LINK_ENV_${_VAR_SUFFIX}}")
|
|
|
|
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})
|
2020-05-22 01:46:07 +08:00
|
|
|
vcpkg_execute_build_process(
|
2021-10-21 05:12:58 +08:00
|
|
|
COMMAND ${make_cmd_line}
|
|
|
|
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()
|
|
|
|
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
|
|
|
|
2021-10-21 05:12:58 +08:00
|
|
|
vcpkg_restore_env_variables(VARS LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)
|
2019-10-05 22:51:07 +08:00
|
|
|
endfunction()
|