2021-03-01 05:17:19 +08:00
|
|
|
#[===[.md:
|
|
|
|
# vcpkg_cmake_build
|
|
|
|
|
|
|
|
Build a cmake project.
|
|
|
|
|
|
|
|
```cmake
|
|
|
|
vcpkg_cmake_build(
|
|
|
|
[TARGET <target>]
|
|
|
|
[LOGFILE_BASE <base>]
|
|
|
|
[DISABLE_PARALLEL]
|
|
|
|
[ADD_BIN_TO_PATH]
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
`vcpkg_cmake_build` builds an already-configured cmake project.
|
|
|
|
You can use the alias [`vcpkg_cmake_install()`] function
|
|
|
|
if your CMake build system supports the `install` TARGET,
|
|
|
|
and this is something we recommend doing whenever possible.
|
|
|
|
Otherwise, you can use `TARGET` to set the target to build.
|
|
|
|
This function defaults to not passing a target to cmake.
|
|
|
|
|
2022-01-29 03:30:37 +08:00
|
|
|
[`vcpkg_cmake_install()`]: vcpkg_cmake_install.md
|
|
|
|
|
2021-03-01 05:17:19 +08:00
|
|
|
`LOGFILE_BASE` is used to set the base of the logfile names;
|
|
|
|
by default, this is `build`, and thus the logfiles end up being something like
|
|
|
|
`build-x86-windows-dbg.log`; if you use `vcpkg_cmake_install`,
|
|
|
|
this is set to `install`, so you'll get log names like `install-x86-windows-dbg.log`.
|
|
|
|
|
|
|
|
For build systems that are buggy when run in parallel,
|
|
|
|
using `DISABLE_PARALLEL` will run the build with only one job.
|
|
|
|
|
|
|
|
Finally, `ADD_BIN_TO_PATH` adds the appropriate (either release or debug)
|
|
|
|
`bin/` directories to the path during the build,
|
|
|
|
such that executables run during the build will be able to access those DLLs.
|
|
|
|
#]===]
|
|
|
|
if(Z_VCPKG_CMAKE_BUILD_GUARD)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
set(Z_VCPKG_CMAKE_BUILD_GUARD ON CACHE INTERNAL "guard variable")
|
|
|
|
|
|
|
|
function(vcpkg_cmake_build)
|
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 "arg" "DISABLE_PARALLEL;ADD_BIN_TO_PATH" "TARGET;LOGFILE_BASE" "")
|
|
|
|
|
|
|
|
if(DEFINED arg_UNPARSED_ARGUMENTS)
|
|
|
|
message(FATAL_ERROR "vcpkg_cmake_build was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED arg_LOGFILE_BASE)
|
|
|
|
set(arg_LOGFILE_BASE "build")
|
|
|
|
endif()
|
|
|
|
|
2022-01-29 03:30:37 +08:00
|
|
|
set(build_args "")
|
|
|
|
set(target_args "")
|
|
|
|
set(parallel_args "")
|
|
|
|
set(no_parallel_args "")
|
2021-03-01 05:17:19 +08:00
|
|
|
|
|
|
|
if(Z_VCPKG_CMAKE_GENERATOR STREQUAL "Ninja")
|
|
|
|
set(build_args "-v") # verbose output
|
|
|
|
set(parallel_args "-j${VCPKG_CONCURRENCY}")
|
|
|
|
set(no_parallel_args "-j1")
|
|
|
|
elseif(Z_VCPKG_CMAKE_GENERATOR MATCHES "^Visual Studio")
|
|
|
|
set(build_args
|
|
|
|
"/p:VCPkgLocalAppDataDisabled=true"
|
|
|
|
"/p:UseIntelMKL=No"
|
|
|
|
)
|
|
|
|
set(parallel_args "/m")
|
|
|
|
elseif(Z_VCPKG_CMAKE_GENERATOR STREQUAL "NMake Makefiles")
|
|
|
|
# No options are currently added for nmake builds
|
2022-01-29 03:30:37 +08:00
|
|
|
elseif(Z_VCPKG_CMAKE_GENERATOR STREQUAL "Unix Makefiles")
|
|
|
|
set(build_args "VERBOSE=1")
|
|
|
|
set(parallel_args "-j${VCPKG_CONCURRENCY}")
|
|
|
|
set(no_parallel_args "")
|
|
|
|
elseif(Z_VCPKG_CMAKE_GENERATOR STREQUAL "Xcode")
|
|
|
|
list(APPEND parallel_args -jobs "${VCPKG_CONCURRENCY}")
|
|
|
|
list(APPEND no_parallel_args -jobs 1)
|
2021-03-01 05:17:19 +08:00
|
|
|
else()
|
2022-01-29 03:30:37 +08:00
|
|
|
message(WARNING "Unrecognized GENERATOR setting from vcpkg_cmake_configure().")
|
2021-03-01 05:17:19 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(DEFINED arg_TARGET)
|
|
|
|
set(target_args "--target" "${arg_TARGET}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
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_config "Debug")
|
|
|
|
else()
|
|
|
|
set(short_buildtype "rel")
|
|
|
|
set(cmake_config "Release")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "Building ${TARGET_TRIPLET}-${short_buildtype}")
|
|
|
|
|
|
|
|
if(arg_ADD_BIN_TO_PATH)
|
|
|
|
set(env_path_backup "$ENV{PATH}")
|
|
|
|
if(buildtype STREQUAL "debug")
|
|
|
|
vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}/debug/bin")
|
|
|
|
else()
|
|
|
|
vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}/bin")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (arg_DISABLE_PARALLEL)
|
|
|
|
vcpkg_execute_build_process(
|
|
|
|
COMMAND "${CMAKE_COMMAND}" --build . --config "${cmake_config}" ${target_args} -- ${build_args} ${no_parallel_args}
|
|
|
|
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${short_buildtype}"
|
|
|
|
LOGNAME "${arg_LOGFILE_BASE}-${TARGET_TRIPLET}-${short_buildtype}"
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
vcpkg_execute_build_process(
|
|
|
|
COMMAND "${CMAKE_COMMAND}" --build . --config "${cmake_config}" ${target_args} -- ${build_args} ${parallel_args}
|
|
|
|
NO_PARALLEL_COMMAND "${CMAKE_COMMAND}" --build . --config "${cmake_config}" ${target_args} -- ${build_args} ${no_parallel_args}
|
|
|
|
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${short_buildtype}"
|
|
|
|
LOGNAME "${arg_LOGFILE_BASE}-${TARGET_TRIPLET}-${short_buildtype}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(arg_ADD_BIN_TO_PATH)
|
|
|
|
set(ENV{PATH} "${env_path_backup}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|