[scripts|nmake] Add jom option, add language control (#27255)

* Add CL_LANGUAGE option

* Add PREFER_JOM option

* Append install target to targets, not options

* Update vcpkg_install_nmake

* Re-enable nmake UWP builds for C projects

* Use PREFER_JOM

* Update documentation

* Update versions

* Add license fields

* Update versions
This commit is contained in:
Kai Pastor 2022-11-02 19:32:43 +01:00 committed by GitHub
parent cafd398be7
commit 3e35cb0a15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 167 additions and 73 deletions

View file

@ -8,18 +8,20 @@ Build a msvc makefile project.
```cmake
vcpkg_build_nmake(
SOURCE_PATH <${SOURCE_PATH}>
[NO_DEBUG]
[ENABLE_INSTALL]
[TARGET <all>]
[PROJECT_SUBPATH <${SUBPATH}>]
[PROJECT_NAME <${MAKEFILE_NAME}>]
[LOGFILE_ROOT <prefix>]
[CL_LANGUAGE <language-name>]
[PREFER_JOM]
[PRERUN_SHELL <${SHELL_PATH}>]
[PRERUN_SHELL_DEBUG <${SHELL_PATH}>]
[PRERUN_SHELL_RELEASE <${SHELL_PATH}>]
[OPTIONS <-DUSE_THIS_IN_ALL_BUILDS=1>...]
[OPTIONS_RELEASE <-DOPTIMIZE=1>...]
[OPTIONS_DEBUG <-DDEBUGGABLE=1>...]
[TARGET <target>])
[TARGET <all>...]
[ENABLE_INSTALL]
)
```
## Parameters
@ -28,45 +30,60 @@ Specifies the directory containing the source files.
By convention, this is usually set in the portfile as the variable `SOURCE_PATH`.
### PROJECT_SUBPATH
Specifies the sub directory containing the `makefile.vc`/`makefile.mak`/`makefile.msvc` or other msvc makefile.
Specifies the sub directory containing the makefile.
### PROJECT_NAME
Specifies the name of msvc makefile name.
Specifies the name of the makefile.
Default is `makefile.vc`
### ENABLE_INSTALL
Install binaries after build.
### LOGFILE_ROOT
Specifies a log file prefix.
### CL_LANGUAGE
Specifies the language for setting up flags in the `_CL_` environment variable.
The default language is `CXX`.
To disable the modification of `_CL_`, use `NONE`.
### PREFER_JOM
Specifies that a parallel build with `jom` should be attempted.
This is useful for faster builds of makefiles which process many independent targets
and which cannot benefit from the `/MP` cl option.
To mitigate issues with concurrency-unaware makefiles, a normal `nmake` build is run after `jom` errors.
### PRERUN_SHELL
Script that needs to be called before build
Script that needs to be called before build.
### PRERUN_SHELL_DEBUG
Script that needs to be called before debug build
Script that needs to be called before debug build.
### PRERUN_SHELL_RELEASE
Script that needs to be called before release build
Script that needs to be called before release build.
### OPTIONS
Additional options passed to generate during the generation.
Additional options passed to the build command.
### OPTIONS_RELEASE
Additional options passed to generate during the Release generation. These are in addition to `OPTIONS`.
Additional options passed to the build command for the release build. These are in addition to `OPTIONS`.
### OPTIONS_DEBUG
Additional options passed to generate during the Debug generation. These are in addition to `OPTIONS`.
Additional options passed to the build command for the debug build. These are in addition to `OPTIONS`.
### TARGET
The target passed to the nmake build command (`nmake/nmake install`). If not specified, no target will
be passed.
The list of targets passed to the build command.
If not specified, target `all` will be passed.
### ENABLE_INSTALL
Adds `install` to the list of targets passed to the build command,
and passes the install prefix in the `INSTALLDIR` makefile variable.
## Notes:
You can use the alias [`vcpkg_install_nmake()`](vcpkg_install_nmake.md) function if your makefile supports the
"install" target
"install" target.
## Examples
* [tcl](https://github.com/Microsoft/vcpkg/blob/master/ports/tcl/portfile.cmake)
* [freexl](https://github.com/Microsoft/vcpkg/blob/master/ports/freexl/portfile.cmake)
* [librttopo](https://github.com/microsoft/vcpkg/blob/master/ports/librttopo/portfile.cmake)
* [openssl](https://github.com/microsoft/vcpkg/blob/master/ports/openssl/portfile.cmake)
## Source
[scripts/cmake/vcpkg\_build\_nmake.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_build_nmake.cmake)

View file

@ -8,16 +8,18 @@ Build and install a msvc makefile project.
```cmake
vcpkg_install_nmake(
SOURCE_PATH <${SOURCE_PATH}>
[NO_DEBUG]
[TARGET <all>]
PROJECT_SUBPATH <${SUBPATH}>
PROJECT_NAME <${MAKEFILE_NAME}>
[PROJECT_SUBPATH <${SUBPATH}>]
[PROJECT_NAME <${MAKEFILE_NAME}>]
[CL_LANGUAGE <language-name>]
[PREFER_JOM]
[PRERUN_SHELL <${SHELL_PATH}>]
[PRERUN_SHELL_DEBUG <${SHELL_PATH}>]
[PRERUN_SHELL_RELEASE <${SHELL_PATH}>]
[OPTIONS <-DUSE_THIS_IN_ALL_BUILDS=1>...]
[OPTIONS_RELEASE <-DOPTIMIZE=1>...]
[OPTIONS_DEBUG <-DDEBUGGABLE=1>...]
[TARGET <all>...]
)
```
## Parameters
@ -26,43 +28,52 @@ Specifies the directory containing the source files.
By convention, this is usually set in the portfile as the variable `SOURCE_PATH`.
### PROJECT_SUBPATH
Specifies the sub directory containing the `makefile.vc`/`makefile.mak`/`makefile.msvc` or other msvc makefile.
Specifies the sub directory containing the makefile.
### PROJECT_NAME
Specifies the name of msvc makefile name.
Default is makefile.vc
Specifies the name of the makefile.
Default is `makefile.vc`
### NO_DEBUG
This port doesn't support debug mode.
### CL_LANGUAGE
Specifies the language for setting up flags in the `_CL_` environment variable.
The default language is `CXX`.
To disable the modification of `_CL_`, use `NONE`.
### PREFER_JOM
Specifies that a parallel build with `jom` should be attempted.
This is useful for faster builds of makefiles which process many independent targets
and which cannot benefit from the `/MP` cl option.
To mitigate issues with concurrency-unaware makefiles, a normal `nmake` build is run after `jom` errors.
### PRERUN_SHELL
Script that needs to be called before build
Script that needs to be called before build.
### PRERUN_SHELL_DEBUG
Script that needs to be called before debug build
Script that needs to be called before debug build.
### PRERUN_SHELL_RELEASE
Script that needs to be called before release build
Script that needs to be called before release build.
### OPTIONS
Additional options passed to generate during the generation.
Additional options passed to the build command.
### OPTIONS_RELEASE
Additional options passed to generate during the Release generation. These are in addition to `OPTIONS`.
Additional options passed to the build command for the release build. These are in addition to `OPTIONS`.
### OPTIONS_DEBUG
Additional options passed to generate during the Debug generation. These are in addition to `OPTIONS`.
Additional options passed to the build command for the debug build. These are in addition to `OPTIONS`.
## Parameters:
See [`vcpkg_build_nmake()`](vcpkg_build_nmake.md).
### TARGET
The list of targets passed to the build command.
If not specified, target `all` will be passed.
## Notes:
This command transparently forwards to [`vcpkg_build_nmake()`](vcpkg_build_nmake.md), adding `ENABLE_INSTALL`
This command transparently forwards to [`vcpkg_build_nmake()`](vcpkg_build_nmake.md), adding `ENABLE_INSTALL`.
## Examples
* [tcl](https://github.com/Microsoft/vcpkg/blob/master/ports/tcl/portfile.cmake)
* [freexl](https://github.com/Microsoft/vcpkg/blob/master/ports/freexl/portfile.cmake)
* [libspatialite](https://github.com/microsoft/vcpkg/blob/master/ports/libspatialite/portfile.cmake)
* [tcl](https://github.com/microsoft/vcpkg/blob/master/ports/tcl/portfile.cmake)
## Source
[scripts/cmake/vcpkg\_install\_nmake.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_install_nmake.cmake)

View file

@ -27,6 +27,7 @@ if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
vcpkg_build_nmake(
SOURCE_PATH "${SOURCE_PATH}"
TARGET librttopo.lib
CL_LANGUAGE C
OPTIONS
"OPTFLAGS=${OPTFLAGS}"
"CFLAGS=-I. -Iheaders ${OPTFLAGS}"

View file

@ -1,10 +1,10 @@
{
"name": "librttopo",
"version": "1.1.0",
"port-version": 6,
"port-version": 7,
"description": "The RT Topology Library exposes an API to create and manage standard (ISO 13249 aka SQL/MM) topologies using user-provided data stores.",
"homepage": "https://git.osgeo.org/gitea/rttopo/librttopo",
"supports": "!uwp",
"license": "GPL-2.0-or-later",
"dependencies": [
"geos"
]

View file

@ -82,6 +82,8 @@ if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
endif()
vcpkg_install_nmake(
SOURCE_PATH "${SOURCE_PATH}"
PREFER_JOM
CL_LANGUAGE C
OPTIONS_RELEASE
"CL_FLAGS=${CL_FLAGS_RELEASE}"
"INST_DIR=${INST_DIR}"

View file

@ -1,7 +1,7 @@
{
"name": "libspatialite",
"version": "5.0.1",
"port-version": 8,
"port-version": 9,
"description": "SpatiaLite is an open source library intended to extend the SQLite core to support fully fledged Spatial SQL capabilities.",
"homepage": "https://www.gaia-gis.it/gaia-sins/libspatialite-sources",
"license": null,

View file

@ -23,20 +23,20 @@ if (VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
if(VCPKG_TARGET_IS_UWP)
set(UWP_LIBS windowsapp.lib)
set(UWP_LINK_FLAGS /APPCONTAINER)
endif()
file(TO_NATIVE_PATH "${CURRENT_PACKAGES_DIR}" INST_DIR)
vcpkg_install_nmake(
SOURCE_PATH "${SOURCE_PATH}"
PREFER_JOM
CL_LANGUAGE C
OPTIONS_RELEASE
"INSTDIR=${INST_DIR}"
"LINK_FLAGS=${UWP_LINK_FLAGS}"
"LIBS_ALL=${PKGCONFIG_LIBS_RELEASE} ${UWP_LIBS}"
OPTIONS_DEBUG
"INSTDIR=${INST_DIR}\\debug"
"LINK_FLAGS=${UWP_LINK_FLAGS} /debug"
"LINK_FLAGS=/debug"
"LIBS_ALL=${PKGCONFIG_LIBS_DEBUG} ${UWP_LIBS}"
)

View file

@ -1,11 +1,10 @@
{
"name": "readosm",
"version-string": "1.1.0a",
"port-version": 3,
"port-version": 4,
"description": "ReadOSM is an open source library to extract valid data from within an Open Street Map input file (.osm or .osm.pbf)",
"homepage": "https://www.gaia-gis.it/gaia-sins/readosm-sources",
"license": "MPL-1.1",
"supports": "!uwp",
"dependencies": [
"expat",
{

View file

@ -47,6 +47,8 @@ if (VCPKG_TARGET_IS_WINDOWS)
vcpkg_install_nmake(
SOURCE_PATH "${SOURCE_PATH}"
PREFER_JOM
CL_LANGUAGE C
OPTIONS_RELEASE
"INSTDIR=${INST_DIR}"
"LIBS_ALL=/link ${PKGCONFIG_LIBS_RELEASE} ${ICONV_LIBS} ${UWP_LIBS}"

View file

@ -1,9 +1,10 @@
{
"name": "spatialite-tools",
"version": "5.0.1",
"port-version": 1,
"port-version": 2,
"description": "Contains spatialite.exe and other command line tools to work with SpatiaLite databases (import, export, SQL queries)",
"homepage": "https://www.gaia-gis.it/fossil/spatialite-tools/index",
"license": "GPL-3.0-or-later",
"dependencies": [
"expat",
"libiconv",

View file

@ -1,7 +1,7 @@
function(vcpkg_build_nmake)
cmake_parse_arguments(PARSE_ARGV 0 arg
"ADD_BIN_TO_PATH;ENABLE_INSTALL;NO_DEBUG"
"SOURCE_PATH;PROJECT_SUBPATH;PROJECT_NAME;LOGFILE_ROOT"
"ADD_BIN_TO_PATH;ENABLE_INSTALL;NO_DEBUG;PREFER_JOM"
"SOURCE_PATH;PROJECT_SUBPATH;PROJECT_NAME;LOGFILE_ROOT;CL_LANGUAGE"
"OPTIONS;OPTIONS_RELEASE;OPTIONS_DEBUG;PRERUN_SHELL;PRERUN_SHELL_DEBUG;PRERUN_SHELL_RELEASE;TARGET"
)
if(DEFINED arg_UNPARSED_ARGUMENTS)
@ -28,12 +28,20 @@ function(vcpkg_build_nmake)
if(NOT DEFINED arg_PROJECT_NAME)
set(arg_PROJECT_NAME makefile.vc)
endif()
if(NOT DEFINED arg_TARGET)
vcpkg_list(SET arg_TARGET all)
endif()
if(arg_ENABLE_INSTALL)
vcpkg_list(APPEND arg_TARGET install)
endif()
if(NOT DEFINED arg_CL_LANGUAGE)
vcpkg_list(SET arg_CL_LANGUAGE CXX)
endif()
find_program(NMAKE nmake REQUIRED)
get_filename_component(NMAKE_EXE_PATH ${NMAKE} DIRECTORY)
get_filename_component(NMAKE_EXE_PATH "${NMAKE}" DIRECTORY)
# Load toolchains
z_vcpkg_get_cmake_vars(cmake_vars_file)
debug_message("Including cmake vars from: ${cmake_vars_file}")
@ -41,13 +49,20 @@ function(vcpkg_build_nmake)
# Set needed env
set(ENV{PATH} "$ENV{PATH};${NMAKE_EXE_PATH}")
set(ENV{INCLUDE} "${CURRENT_INSTALLED_DIR}/include;$ENV{INCLUDE}")
# Set make command and install command
vcpkg_list(SET make_command ${NMAKE} /NOLOGO /G /U)
vcpkg_list(SET make_opts_base -f "${arg_PROJECT_NAME}" ${arg_TARGET})
if(arg_ENABLE_INSTALL)
vcpkg_list(APPEND make_opts_base install)
endif()
# Set make options
vcpkg_list(SET make_opts_base /NOLOGO /G /U /F "${arg_PROJECT_NAME}" ${arg_TARGET})
if(arg_PREFER_JOM AND VCPKG_CONCURRENCY GREATER "1")
vcpkg_find_acquire_program(JOM)
get_filename_component(JOM_EXE_PATH "${JOM}" DIRECTORY)
vcpkg_add_to_path("${JOM_EXE_PATH}")
if(arg_CL_LANGUAGE AND "${VCPKG_DETECTED_CMAKE_${arg_CL_LANGUAGE}_COMPILER_ID}" STREQUAL "MSVC")
string(REGEX REPLACE " [/-]MP[0-9]* " " " VCPKG_COMBINED_${arg_CL_LANGUAGE}_FLAGS_DEBUG " ${VCPKG_COMBINED_${arg_CL_LANGUAGE}_FLAGS_DEBUG} /FS")
string(REGEX REPLACE " [/-]MP[0-9]* " " " VCPKG_COMBINED_${arg_CL_LANGUAGE}_FLAGS_RELEASE " ${VCPKG_COMBINED_${arg_CL_LANGUAGE}_FLAGS_RELEASE} /FS")
endif()
else()
set(arg_PREFER_JOM FALSE)
endif()
# Add subpath to work directory
if(DEFINED arg_PROJECT_SUBPATH)
@ -56,7 +71,7 @@ function(vcpkg_build_nmake)
set(project_subpath "")
endif()
vcpkg_backup_env_variables(VARS CL LINK)
vcpkg_backup_env_variables(VARS _CL_ LINK)
cmake_path(NATIVE_PATH CURRENT_PACKAGES_DIR NORMALIZE install_dir_native)
foreach(build_type IN ITEMS debug release)
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL build_type)
@ -69,7 +84,9 @@ function(vcpkg_build_nmake)
vcpkg_list(APPEND make_opts "INSTALLDIR=${install_dir_native}\\debug")
endif()
vcpkg_list(APPEND make_opts ${arg_OPTIONS} ${arg_OPTIONS_DEBUG})
set(ENV{_CL_} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_DEBUG}")
if(NOT arg_CL_LANGUAGE STREQUAL "NONE")
set(ENV{_CL_} "${VCPKG_DETECTED_CMAKE_${arg_CL_LANGUAGE}_FLAGS_DEBUG}")
endif()
set(ENV{_LINK_} "${VCPKG_DETECTED_CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
set(prerun_variable_name arg_PRERUN_SHELL_DEBUG)
@ -82,7 +99,9 @@ function(vcpkg_build_nmake)
endif()
vcpkg_list(APPEND make_opts ${arg_OPTIONS} ${arg_OPTIONS_RELEASE})
set(ENV{_CL_} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_RELEASE}")
if(NOT arg_CL_LANGUAGE STREQUAL "NONE")
set(ENV{_CL_} "${VCPKG_DETECTED_CMAKE_${arg_CL_LANGUAGE}_FLAGS_RELEASE}")
endif()
set(ENV{_LINK_} "${VCPKG_DETECTED_CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
set(prerun_variable_name arg_PRERUN_SHELL_RELEASE)
endif()
@ -116,13 +135,32 @@ function(vcpkg_build_nmake)
message(STATUS "Building and installing ${triplet_and_build_type}")
endif()
vcpkg_execute_build_process(
COMMAND ${make_command} ${make_opts}
WORKING_DIRECTORY "${object_dir}${project_subpath}"
LOGNAME "${arg_LOGFILE_ROOT}-${triplet_and_build_type}"
)
set(run_nmake TRUE)
set(tool_suffix "")
if(arg_PREFER_JOM)
execute_process(
COMMAND "${JOM}" /K /J ${VCPKG_CONCURRENCY} ${make_opts}
WORKING_DIRECTORY "${object_dir}${project_subpath}"
OUTPUT_FILE "${CURRENT_BUILDTREES_DIR}/${arg_LOGFILE_ROOT}-${triplet_and_build_type}-jom-out.log"
ERROR_FILE "${CURRENT_BUILDTREES_DIR}/${arg_LOGFILE_ROOT}-${triplet_and_build_type}-jom-err.log"
RESULT_VARIABLE error_code
)
if(error_code EQUAL "0")
set(run_nmake FALSE)
else()
message(STATUS "Restarting build without parallelism")
set(tool_suffix "-nmake")
endif()
endif()
if(run_nmake)
vcpkg_execute_build_process(
COMMAND "${NMAKE}" ${make_opts}
WORKING_DIRECTORY "${object_dir}${project_subpath}"
LOGNAME "${arg_LOGFILE_ROOT}-${triplet_and_build_type}${tool_suffix}"
)
endif()
vcpkg_restore_env_variables(VARS CL)
vcpkg_restore_env_variables(VARS _CL_ LINK)
endif()
endforeach()
endfunction()

View file

@ -5,8 +5,8 @@ function(vcpkg_install_nmake)
PRERUN_SHELL PRERUN_SHELL_DEBUG PRERUN_SHELL_RELEASE)
cmake_parse_arguments(PARSE_ARGV 0 arg
"NO_DEBUG"
"SOURCE_PATH;PROJECT_SUBPATH;PROJECT_NAME"
"NO_DEBUG;PREFER_JOM"
"SOURCE_PATH;PROJECT_SUBPATH;PROJECT_NAME;CL_LANGUAGE"
"${multi_value_args}"
)
if(DEFINED arg_UNPARSED_ARGUMENTS)
@ -31,9 +31,12 @@ function(vcpkg_install_nmake)
if(arg_NO_DEBUG)
vcpkg_list(APPEND extra_args NO_DEBUG)
endif()
if(arg_PREFER_JOM)
vcpkg_list(APPEND extra_args PREFER_JOM)
endif()
# single args
foreach(arg IN ITEMS PROJECT_SUBPATH PROJECT_NAME)
foreach(arg IN ITEMS PROJECT_SUBPATH PROJECT_NAME CL_LANGUAGE)
if(DEFINED "arg_${arg}")
vcpkg_list(APPEND extra_args ${arg} "${arg_${arg}}")
endif()

View file

@ -4150,7 +4150,7 @@
},
"librttopo": {
"baseline": "1.1.0",
"port-version": 6
"port-version": 7
},
"libsamplerate": {
"baseline": "0.2.2",
@ -4218,7 +4218,7 @@
},
"libspatialite": {
"baseline": "5.0.1",
"port-version": 8
"port-version": 9
},
"libspnav": {
"baseline": "0.2.3",
@ -6498,7 +6498,7 @@
},
"readosm": {
"baseline": "1.1.0a",
"port-version": 3
"port-version": 4
},
"realsense2": {
"baseline": "2.51.1",
@ -7042,7 +7042,7 @@
},
"spatialite-tools": {
"baseline": "5.0.1",
"port-version": 1
"port-version": 2
},
"spdk": {
"baseline": "19.01.1",

View file

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "d7e9514837d372d0a952762f6e7ea600c8a625f9",
"version": "1.1.0",
"port-version": 7
},
{
"git-tree": "83f4858afee7a92ece5923344f556b3900894eaf",
"version": "1.1.0",

View file

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "b68031f4e06a096cf94f5b1c685f97b642667818",
"version": "5.0.1",
"port-version": 9
},
{
"git-tree": "f13da82a42aca5aa182c22cf8d582cc9019e91fc",
"version": "5.0.1",

View file

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "e91f30f55adfa57ccb0b2787e57991e5f3039921",
"version-string": "1.1.0a",
"port-version": 4
},
{
"git-tree": "e04328cccd78bf8d4ec57d70059d49501b361292",
"version-string": "1.1.0a",

View file

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "480ac025b9ad7cecc2cf17f935115a13c0de31a0",
"version": "5.0.1",
"port-version": 2
},
{
"git-tree": "1e91990a5c6a01d86cc1b4cb84bbea812e62b450",
"version": "5.0.1",