2019-10-05 22:51:07 +08:00
|
|
|
function(vcpkg_build_nmake)
|
2021-11-06 07:55:01 +08: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-21 02: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-06 07:55:01 +08: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-06 07:55:01 +08: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-06 07:55:01 +08: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-06 07:55:01 +08: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-06 07:55:01 +08: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
|
2022-08-20 06:12:14 +08:00
|
|
|
z_vcpkg_get_cmake_vars(cmake_vars_file)
|
|
|
|
debug_message("Including cmake vars from: ${cmake_vars_file}")
|
|
|
|
include("${cmake_vars_file}")
|
2019-10-05 22:51:07 +08:00
|
|
|
# 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-06 07:55:01 +08: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-21 02:29:25 +08:00
|
|
|
endif()
|
2021-11-06 07:55:01 +08:00
|
|
|
|
|
|
|
|
2019-10-05 22:51:07 +08:00
|
|
|
# Add subpath to work directory
|
2021-11-06 07:55:01 +08:00
|
|
|
if(DEFINED arg_PROJECT_SUBPATH)
|
|
|
|
set(project_subpath "/${arg_PROJECT_SUBPATH}")
|
2019-10-05 22:51:07 +08:00
|
|
|
else()
|
2021-11-06 07:55:01 +08:00
|
|
|
set(project_subpath "")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2021-11-06 07:55:01 +08:00
|
|
|
|
2022-08-20 06:12:14 +08:00
|
|
|
vcpkg_backup_env_variables(VARS CL LINK)
|
2021-12-21 00:34:01 +08:00
|
|
|
cmake_path(NATIVE_PATH CURRENT_PACKAGES_DIR NORMALIZE install_dir_native)
|
2021-11-06 07:55:01 +08: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-06 07:55:01 +08:00
|
|
|
set(short_build_type "-dbg")
|
2019-10-05 22:51:07 +08:00
|
|
|
# Add install command and arguments
|
2021-11-06 07:55:01 +08:00
|
|
|
set(make_opts "${make_opts_base}")
|
|
|
|
if (arg_ENABLE_INSTALL)
|
2021-12-21 00:34:01 +08:00
|
|
|
vcpkg_list(APPEND make_opts "INSTALLDIR=${install_dir_native}\\debug")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2021-11-06 07:55:01 +08:00
|
|
|
vcpkg_list(APPEND make_opts ${arg_OPTIONS} ${arg_OPTIONS_DEBUG})
|
2022-08-20 06:12:14 +08:00
|
|
|
set(ENV{_CL_} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_DEBUG}")
|
|
|
|
set(ENV{_LINK_} "${VCPKG_DETECTED_CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
|
2021-11-06 07:55:01 +08:00
|
|
|
|
|
|
|
set(prerun_variable_name arg_PRERUN_SHELL_DEBUG)
|
2019-10-05 22:51:07 +08:00
|
|
|
else()
|
2021-11-06 07:55:01 +08:00
|
|
|
set(short_build_type "-rel")
|
2019-10-05 22:51:07 +08:00
|
|
|
# Add install command and arguments
|
2021-11-06 07:55:01 +08:00
|
|
|
set(make_opts "${make_opts_base}")
|
|
|
|
if (arg_ENABLE_INSTALL)
|
2021-12-21 00:34:01 +08:00
|
|
|
vcpkg_list(APPEND make_opts "INSTALLDIR=${install_dir_native}")
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
2021-11-06 07:55:01 +08:00
|
|
|
vcpkg_list(APPEND make_opts ${arg_OPTIONS} ${arg_OPTIONS_RELEASE})
|
|
|
|
|
2022-08-20 06:12:14 +08:00
|
|
|
set(ENV{_CL_} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
set(ENV{_LINK_} "${VCPKG_DETECTED_CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
|
2021-11-06 07:55:01 +08:00
|
|
|
set(prerun_variable_name arg_PRERUN_SHELL_RELEASE)
|
2019-10-30 14:23:36 +08:00
|
|
|
endif()
|
2021-11-06 07:55:01 +08: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-06 07:55:01 +08: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-06 07:55:01 +08: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-06 07:55:01 +08: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-06 07:55:01 +08:00
|
|
|
if (NOT arg_ENABLE_INSTALL)
|
|
|
|
message(STATUS "Building ${triplet_and_build_type}")
|
2019-10-05 22:51:07 +08:00
|
|
|
else()
|
2021-11-06 07:55:01 +08: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-06 07:55:01 +08: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-06 07:55:01 +08:00
|
|
|
vcpkg_restore_env_variables(VARS CL)
|
2019-10-05 22:51:07 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|