2020-12-01 13:37:26 -08:00
|
|
|
#[===[.md:
|
|
|
|
# vcpkg_build_nmake
|
|
|
|
|
|
|
|
Build a msvc makefile project.
|
|
|
|
|
|
|
|
## Usage:
|
|
|
|
```cmake
|
|
|
|
vcpkg_build_nmake(
|
|
|
|
SOURCE_PATH <${SOURCE_PATH}>
|
|
|
|
[NO_DEBUG]
|
2021-09-14 23:26:31 +02:00
|
|
|
[ENABLE_INSTALL]
|
2020-12-01 13:37:26 -08:00
|
|
|
[TARGET <all>]
|
|
|
|
[PROJECT_SUBPATH <${SUBPATH}>]
|
|
|
|
[PROJECT_NAME <${MAKEFILE_NAME}>]
|
|
|
|
[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>])
|
|
|
|
```
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
### SOURCE_PATH
|
|
|
|
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.
|
|
|
|
|
|
|
|
### PROJECT_NAME
|
|
|
|
Specifies the name of msvc makefile name.
|
|
|
|
Default is `makefile.vc`
|
|
|
|
|
|
|
|
### ENABLE_INSTALL
|
|
|
|
Install binaries after build.
|
|
|
|
|
|
|
|
### PRERUN_SHELL
|
|
|
|
Script that needs to be called before build
|
|
|
|
|
|
|
|
### PRERUN_SHELL_DEBUG
|
|
|
|
Script that needs to be called before debug build
|
|
|
|
|
|
|
|
### PRERUN_SHELL_RELEASE
|
|
|
|
Script that needs to be called before release build
|
|
|
|
|
|
|
|
### OPTIONS
|
|
|
|
Additional options passed to generate during the generation.
|
|
|
|
|
|
|
|
### OPTIONS_RELEASE
|
|
|
|
Additional options passed to generate during the Release generation. These are in addition to `OPTIONS`.
|
|
|
|
|
|
|
|
### OPTIONS_DEBUG
|
|
|
|
Additional options passed to generate during the Debug generation. 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.
|
|
|
|
|
|
|
|
## Notes:
|
2021-01-06 05:37:19 +09:00
|
|
|
You can use the alias [`vcpkg_install_nmake()`](vcpkg_install_nmake.md) function if your makefile supports the
|
2020-12-01 13:37:26 -08:00
|
|
|
"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)
|
|
|
|
#]===]
|
|
|
|
|
2019-10-05 22:51:07 +08:00
|
|
|
function(vcpkg_build_nmake)
|
2021-11-05 16:55:01 -07:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 arg
|
2019-10-05 22:51:07 +08:00
|
|
|
"ADD_BIN_TO_PATH;ENABLE_INSTALL;NO_DEBUG"
|
|
|
|
"SOURCE_PATH;PROJECT_SUBPATH;PROJECT_NAME;LOGFILE_ROOT"
|
2020-11-20 10:29:25 -08:00
|
|
|
"OPTIONS;OPTIONS_RELEASE;OPTIONS_DEBUG;PRERUN_SHELL;PRERUN_SHELL_DEBUG;PRERUN_SHELL_RELEASE;TARGET"
|
2019-10-05 22:51:07 +08:00
|
|
|
)
|
2021-11-05 16:55:01 -07:00
|
|
|
if(DEFINED arg_UNPARSED_ARGUMENTS)
|
|
|
|
message(WARNING "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2021-11-05 16:55:01 -07:00
|
|
|
if(NOT DEFINED arg_SOURCE_PATH)
|
|
|
|
message(FATAL_ERROR "SOURCE_PATH must be specified")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
|
|
|
|
2021-11-05 16:55:01 -07:00
|
|
|
if(arg_NO_DEBUG)
|
|
|
|
message(WARNING "NO_DEBUG argument to ${CMAKE_CURRENT_FUNCTION} is deprecated")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2021-11-05 16:55:01 -07:00
|
|
|
if(arg_ADD_BIN_TO_PATH)
|
|
|
|
message(WARNING "ADD_BIN_TO_PATH argument to ${CMAKE_CURRENT_FUNCTION} is deprecated - it never did anything")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT VCPKG_HOST_IS_WINDOWS)
|
|
|
|
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} only support windows.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT DEFINED arg_LOGFILE_ROOT)
|
|
|
|
set(arg_LOGFILE_ROOT "build")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2021-11-05 16:55:01 -07:00
|
|
|
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()
|
|
|
|
|
2019-10-05 22:51:07 +08:00
|
|
|
find_program(NMAKE nmake REQUIRED)
|
|
|
|
get_filename_component(NMAKE_EXE_PATH ${NMAKE} DIRECTORY)
|
|
|
|
# Load toolchains
|
|
|
|
if(NOT VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
|
|
|
|
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/windows.cmake")
|
|
|
|
endif()
|
|
|
|
include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
|
|
|
|
# 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
|
2021-11-05 16:55:01 -07:00
|
|
|
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)
|
2020-11-20 10:29:25 -08:00
|
|
|
endif()
|
2021-11-05 16:55:01 -07:00
|
|
|
|
|
|
|
|
2019-10-05 22:51:07 +08:00
|
|
|
# Add subpath to work directory
|
2021-11-05 16:55:01 -07:00
|
|
|
if(DEFINED arg_PROJECT_SUBPATH)
|
|
|
|
set(project_subpath "/${arg_PROJECT_SUBPATH}")
|
2019-10-05 22:51:07 +08:00
|
|
|
else()
|
2021-11-05 16:55:01 -07:00
|
|
|
set(project_subpath "")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2021-11-05 16:55:01 -07:00
|
|
|
|
|
|
|
vcpkg_backup_env_variables(VARS CL)
|
2021-12-20 17:34:01 +01:00
|
|
|
cmake_path(NATIVE_PATH CURRENT_PACKAGES_DIR NORMALIZE install_dir_native)
|
2021-11-05 16:55:01 -07:00
|
|
|
foreach(build_type IN ITEMS debug release)
|
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL build_type)
|
|
|
|
if(build_type STREQUAL "debug")
|
2019-10-05 22:51:07 +08:00
|
|
|
# Generate obj dir suffix
|
2021-11-05 16:55:01 -07:00
|
|
|
set(short_build_type "-dbg")
|
2019-10-05 22:51:07 +08:00
|
|
|
# Add install command and arguments
|
2021-11-05 16:55:01 -07:00
|
|
|
set(make_opts "${make_opts_base}")
|
|
|
|
if (arg_ENABLE_INSTALL)
|
2021-12-20 17:34:01 +01:00
|
|
|
vcpkg_list(APPEND make_opts "INSTALLDIR=${install_dir_native}\\debug")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2021-11-05 16:55:01 -07:00
|
|
|
vcpkg_list(APPEND make_opts ${arg_OPTIONS} ${arg_OPTIONS_DEBUG})
|
|
|
|
set(ENV{CL} "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
|
|
|
|
|
|
|
|
set(prerun_variable_name arg_PRERUN_SHELL_DEBUG)
|
2019-10-05 22:51:07 +08:00
|
|
|
else()
|
2021-11-05 16:55:01 -07:00
|
|
|
set(short_build_type "-rel")
|
2019-10-05 22:51:07 +08:00
|
|
|
# Add install command and arguments
|
2021-11-05 16:55:01 -07:00
|
|
|
set(make_opts "${make_opts_base}")
|
|
|
|
if (arg_ENABLE_INSTALL)
|
2021-12-20 17:34:01 +01:00
|
|
|
vcpkg_list(APPEND make_opts "INSTALLDIR=${install_dir_native}")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2021-11-05 16:55:01 -07:00
|
|
|
vcpkg_list(APPEND make_opts ${arg_OPTIONS} ${arg_OPTIONS_RELEASE})
|
|
|
|
|
|
|
|
set(ENV{CL} "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
set(prerun_variable_name arg_PRERUN_SHELL_RELEASE)
|
2019-10-30 14:23:36 +08:00
|
|
|
endif()
|
2021-11-05 16:55:01 -07:00
|
|
|
|
|
|
|
set(triplet_and_build_type "${TARGET_TRIPLET}${short_build_type}")
|
|
|
|
set(object_dir "${CURRENT_BUILDTREES_DIR}/${triplet_and_build_type}")
|
|
|
|
|
|
|
|
file(REMOVE_RECURSE "${object_dir}")
|
|
|
|
file(COPY "${arg_SOURCE_PATH}/" DESTINATION "${object_dir}")
|
|
|
|
|
|
|
|
if(DEFINED arg_PRERUN_SHELL)
|
|
|
|
message(STATUS "Prerunning ${triplet_and_build_type}")
|
2019-10-30 14:23:36 +08:00
|
|
|
vcpkg_execute_required_process(
|
2021-11-05 16:55:01 -07:00
|
|
|
COMMAND ${arg_PRERUN_SHELL}
|
|
|
|
WORKING_DIRECTORY "${object_dir}${project_subpath}"
|
|
|
|
LOGNAME "prerun-${triplet_and_build_type}"
|
2019-10-30 14:23:36 +08:00
|
|
|
)
|
|
|
|
endif()
|
2021-11-05 16:55:01 -07:00
|
|
|
if(DEFINED "${prerun_variable_name}")
|
|
|
|
message(STATUS "Prerunning ${triplet_and_build_type}")
|
2019-10-30 14:23:36 +08:00
|
|
|
vcpkg_execute_required_process(
|
2021-11-05 16:55:01 -07:00
|
|
|
COMMAND ${${prerun_variable_name}}
|
|
|
|
WORKING_DIRECTORY "${object_dir}${project_subpath}"
|
|
|
|
LOGNAME "prerun-specific-${triplet_and_build_type}"
|
2019-10-30 14:23:36 +08:00
|
|
|
)
|
|
|
|
endif()
|
2019-10-05 22:51:07 +08:00
|
|
|
|
2021-11-05 16:55:01 -07:00
|
|
|
if (NOT arg_ENABLE_INSTALL)
|
|
|
|
message(STATUS "Building ${triplet_and_build_type}")
|
2019-10-05 22:51:07 +08:00
|
|
|
else()
|
2021-11-05 16:55:01 -07:00
|
|
|
message(STATUS "Building and installing ${triplet_and_build_type}")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
|
|
|
|
2019-10-09 20:54:19 +08:00
|
|
|
vcpkg_execute_build_process(
|
2021-11-05 16:55:01 -07:00
|
|
|
COMMAND ${make_command} ${make_opts}
|
|
|
|
WORKING_DIRECTORY "${object_dir}${project_subpath}"
|
|
|
|
LOGNAME "${arg_LOGFILE_ROOT}-${triplet_and_build_type}"
|
2019-10-05 22:51:07 +08:00
|
|
|
)
|
|
|
|
|
2021-11-05 16:55:01 -07:00
|
|
|
vcpkg_restore_env_variables(VARS CL)
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|