mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-27 09:49:02 +08:00
282 lines
13 KiB
CMake
282 lines
13 KiB
CMake
|
|
function(boost_modular_build)
|
|
cmake_parse_arguments(_bm "" "SOURCE_PATH;REQUIREMENTS" "OPTIONS" ${ARGN})
|
|
|
|
if(NOT DEFINED _bm_SOURCE_PATH)
|
|
message(FATAL_ERROR "SOURCE_PATH is a required argument to boost_modular_build.")
|
|
endif()
|
|
|
|
# Todo: this serves too similar a purpose as vcpkg_find_acquire_program()
|
|
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" OR VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
|
|
set(BOOST_BUILD_PATH "${CURRENT_INSTALLED_DIR}/tools/boost-build")
|
|
else()
|
|
get_filename_component(BOOST_BUILD_PATH "${CURRENT_INSTALLED_DIR}/../x86-windows/tools/boost-build" ABSOLUTE)
|
|
endif()
|
|
|
|
if(NOT EXISTS "${BOOST_BUILD_PATH}")
|
|
message(FATAL_ERROR "The x86 boost-build tools must be installed to build for non-x86/x64 platforms. Please run `vcpkg install boost-build:x86-windows`.")
|
|
endif()
|
|
|
|
if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
|
list(APPEND _bm_OPTIONS windows-api=store)
|
|
endif()
|
|
|
|
set(_bm_DIR ${CURRENT_INSTALLED_DIR}/share/boost-vcpkg-helpers)
|
|
|
|
if(EXISTS "${_bm_SOURCE_PATH}/Jamfile.v2")
|
|
file(REMOVE_RECURSE "${_bm_SOURCE_PATH}/Jamfile.v2")
|
|
endif()
|
|
|
|
set(REQUIREMENTS ${_bm_REQUIREMENTS})
|
|
|
|
configure_file(${_bm_DIR}/Jamroot.jam ${_bm_SOURCE_PATH}/Jamroot.jam @ONLY)
|
|
|
|
# boost thread superfluously builds has_atomic_flag_lockfree on windows.
|
|
if(EXISTS "${_bm_SOURCE_PATH}/build/Jamfile.v2")
|
|
file(READ ${_bm_SOURCE_PATH}/build/Jamfile.v2 _contents)
|
|
string(REPLACE
|
|
"\n\nexe has_atomic_flag_lockfree"
|
|
"\n\nexplicit has_atomic_flag_lockfree ;\nexe has_atomic_flag_lockfree"
|
|
_contents
|
|
"${_contents}"
|
|
)
|
|
string(REPLACE "\nimport ../../config/checks/config : requires ;" "\n# import ../../config/checks/config : requires ;" _contents "${_contents}")
|
|
string(REGEX REPLACE
|
|
"\.\./\.\./([^/ ]+)/build//(boost_[^/ ]+)"
|
|
"/boost/\\1//\\2"
|
|
_contents
|
|
"${_contents}"
|
|
)
|
|
string(REGEX REPLACE " /boost//([^/ ]+)" " /boost/\\1//boost_\\1" _contents "${_contents}")
|
|
file(WRITE ${_bm_SOURCE_PATH}/build/Jamfile.v2 "${_contents}")
|
|
endif()
|
|
|
|
if(EXISTS "${_bm_SOURCE_PATH}/build/log-architecture.jam")
|
|
file(READ ${_bm_SOURCE_PATH}/build/log-architecture.jam _contents)
|
|
string(REPLACE
|
|
"\nproject.load [ path.join [ path.make $(here:D) ] ../../config/checks/architecture ] ;"
|
|
"\n# project.load [ path.join [ path.make $(here:D) ] ../../config/checks/architecture ] ;"
|
|
_contents "${_contents}")
|
|
file(WRITE ${_bm_SOURCE_PATH}/build/log-architecture.jam "${_contents}")
|
|
endif()
|
|
|
|
#####################
|
|
# Cleanup previous builds
|
|
######################
|
|
file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
|
|
if(EXISTS ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
|
|
# It is possible for a file in this folder to be locked due to antivirus or vctip
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
|
|
file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
|
|
if(EXISTS ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
|
|
message(FATAL_ERROR "Unable to remove directory: ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel\n Files are likely in use.")
|
|
endif()
|
|
endif()
|
|
|
|
file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
|
|
if(EXISTS ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
|
|
# It is possible for a file in this folder to be locked due to antivirus or vctip
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
|
|
file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
|
|
if(EXISTS ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
|
|
message(FATAL_ERROR "Unable to remove directory: ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg\n Files are likely in use.")
|
|
endif()
|
|
endif()
|
|
|
|
if(EXISTS ${CURRENT_PACKAGES_DIR}/debug)
|
|
message(FATAL_ERROR "Error: directory exists: ${CURRENT_PACKAGES_DIR}/debug\n The previous package was not fully cleared. This is an internal error.")
|
|
endif()
|
|
file(MAKE_DIRECTORY
|
|
${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg
|
|
${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
|
|
)
|
|
|
|
######################
|
|
# Generate configuration
|
|
######################
|
|
list(APPEND _bm_OPTIONS
|
|
-j$ENV{NUMBER_OF_PROCESSORS}
|
|
--debug-configuration
|
|
--debug-building
|
|
--debug-generators
|
|
--disable-icu
|
|
--ignore-site-config
|
|
--hash
|
|
-q
|
|
|
|
threadapi=win32
|
|
threading=multi
|
|
)
|
|
|
|
# Add build type specific options
|
|
if(VCPKG_CRT_LINKAGE STREQUAL "dynamic")
|
|
list(APPEND _bm_OPTIONS runtime-link=shared)
|
|
else()
|
|
list(APPEND _bm_OPTIONS runtime-link=static)
|
|
endif()
|
|
|
|
if (VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
|
|
list(APPEND _bm_OPTIONS link=shared)
|
|
else()
|
|
list(APPEND _bm_OPTIONS link=static)
|
|
endif()
|
|
|
|
if(VCPKG_TARGET_ARCHITECTURE MATCHES "x64")
|
|
list(APPEND _bm_OPTIONS address-model=64 architecture=x86)
|
|
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
|
|
list(APPEND _bm_OPTIONS address-model=32 architecture=arm)
|
|
else()
|
|
list(APPEND _bm_OPTIONS address-model=32 architecture=x86)
|
|
endif()
|
|
|
|
file(TO_CMAKE_PATH "${_bm_DIR}/nothing.bat" NOTHING_BAT)
|
|
set(TOOLSET_OPTIONS " <cxxflags>/EHsc <compileflags>-Zm800 <compileflags>-nologo")
|
|
if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
|
if(VCPKG_PLATFORM_TOOLSET MATCHES "v141")
|
|
find_path(PATH_TO_CL cl.exe)
|
|
find_path(PLATFORM_WINMD_DIR platform.winmd PATHS "${PATH_TO_CL}/../../../lib/x86/store/references" NO_DEFAULT_PATH)
|
|
if(PLATFORM_WINMD_DIR MATCHES "NOTFOUND")
|
|
message(FATAL_ERROR "Could not find `platform.winmd` in VS2017. Do you have the Universal Windows Platform development workload installed?")
|
|
endif()
|
|
else()
|
|
find_path(PLATFORM_WINMD_DIR platform.winmd PATHS "$ENV{VS140COMNTOOLS}/../../VC/LIB/store/references")
|
|
if(PLATFORM_WINMD_DIR MATCHES "NOTFOUND")
|
|
message(FATAL_ERROR "Could not find `platform.winmd` in VS2015.")
|
|
endif()
|
|
endif()
|
|
file(TO_NATIVE_PATH "${PLATFORM_WINMD_DIR}" PLATFORM_WINMD_DIR)
|
|
string(REPLACE "\\" "\\\\" PLATFORM_WINMD_DIR ${PLATFORM_WINMD_DIR}) # escape backslashes
|
|
|
|
set(TOOLSET_OPTIONS "${TOOLSET_OPTIONS} <cflags>-Zl <compileflags>\"/AI\"${PLATFORM_WINMD_DIR}\"\" <linkflags>WindowsApp.lib <cxxflags>/ZW <compileflags>-DVirtualAlloc=VirtualAllocFromApp <compileflags>-D_WIN32_WINNT=0x0A00")
|
|
else()
|
|
set(TOOLSET_OPTIONS "${TOOLSET_OPTIONS} <compileflags>-D_WIN32_WINNT=0x0602")
|
|
endif()
|
|
|
|
configure_file(${_bm_DIR}/user-config.jam ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/user-config.jam @ONLY)
|
|
configure_file(${_bm_DIR}/user-config.jam ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/user-config.jam @ONLY)
|
|
|
|
if(VCPKG_PLATFORM_TOOLSET MATCHES "v141")
|
|
list(APPEND _bm_OPTIONS toolset=msvc-14.1)
|
|
elseif(VCPKG_PLATFORM_TOOLSET MATCHES "v140")
|
|
list(APPEND _bm_OPTIONS toolset=msvc-14.0)
|
|
else()
|
|
message(FATAL_ERROR "Unsupported value for VCPKG_PLATFORM_TOOLSET: '${VCPKG_PLATFORM_TOOLSET}'")
|
|
endif()
|
|
|
|
######################
|
|
# Perform build + Package
|
|
######################
|
|
set(B2_EXE "${BOOST_BUILD_PATH}/b2.exe")
|
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
|
|
message(STATUS "Building ${TARGET_TRIPLET}-rel")
|
|
set(ENV{BOOST_BUILD_PATH} "${BOOST_BUILD_PATH}")
|
|
vcpkg_execute_required_process(
|
|
COMMAND "${B2_EXE}"
|
|
--stagedir=${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/stage
|
|
--build-dir=${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
|
|
--user-config=${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/user-config.jam
|
|
${_bm_OPTIONS}
|
|
variant=release
|
|
debug-symbols=on
|
|
WORKING_DIRECTORY ${_bm_SOURCE_PATH}
|
|
LOGNAME build-${TARGET_TRIPLET}-rel
|
|
)
|
|
message(STATUS "Building ${TARGET_TRIPLET}-rel done")
|
|
endif()
|
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
|
|
message(STATUS "Building ${TARGET_TRIPLET}-dbg")
|
|
set(ENV{BOOST_BUILD_PATH} "${BOOST_BUILD_PATH}")
|
|
vcpkg_execute_required_process(
|
|
COMMAND "${B2_EXE}"
|
|
--stagedir=${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/stage
|
|
--build-dir=${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg
|
|
--user-config=${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/user-config.jam
|
|
${_bm_OPTIONS}
|
|
variant=debug
|
|
WORKING_DIRECTORY ${_bm_SOURCE_PATH}
|
|
LOGNAME build-${TARGET_TRIPLET}-dbg
|
|
)
|
|
message(STATUS "Building ${TARGET_TRIPLET}-dbg done")
|
|
endif()
|
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
|
|
message(STATUS "Packaging ${TARGET_TRIPLET}-rel")
|
|
file(GLOB REL_LIBS ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/boost/build/*/*.lib)
|
|
file(COPY ${REL_LIBS}
|
|
DESTINATION ${CURRENT_PACKAGES_DIR}/lib
|
|
FILES_MATCHING PATTERN "*.lib")
|
|
if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
|
|
file(GLOB REL_DLLS ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/boost/build/*/*.dll)
|
|
file(COPY ${REL_DLLS}
|
|
DESTINATION ${CURRENT_PACKAGES_DIR}/bin
|
|
FILES_MATCHING PATTERN "*.dll")
|
|
endif()
|
|
message(STATUS "Packaging ${TARGET_TRIPLET}-rel done")
|
|
endif()
|
|
|
|
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
|
|
message(STATUS "Packaging ${TARGET_TRIPLET}-dbg")
|
|
file(GLOB DBG_LIBS ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/boost/build/*/*.lib)
|
|
file(COPY ${DBG_LIBS}
|
|
DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib
|
|
FILES_MATCHING PATTERN "*.lib")
|
|
if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
|
|
file(GLOB DBG_DLLS ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/boost/build/*/*.dll)
|
|
file(COPY ${DBG_DLLS}
|
|
DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin
|
|
FILES_MATCHING PATTERN "*.dll")
|
|
endif()
|
|
message(STATUS "Packaging ${TARGET_TRIPLET}-dbg done")
|
|
endif()
|
|
|
|
file(GLOB INSTALLED_LIBS ${CURRENT_PACKAGES_DIR}/debug/lib/*.lib ${CURRENT_PACKAGES_DIR}/lib/*.lib)
|
|
foreach(LIB ${INSTALLED_LIBS})
|
|
get_filename_component(OLD_FILENAME ${LIB} NAME)
|
|
get_filename_component(DIRECTORY_OF_LIB_FILE ${LIB} DIRECTORY)
|
|
string(REPLACE "libboost_" "boost_" NEW_FILENAME ${OLD_FILENAME})
|
|
string(REPLACE "-s-" "-" NEW_FILENAME ${NEW_FILENAME}) # For Release libs
|
|
string(REPLACE "-vc141-" "-vc140-" NEW_FILENAME ${NEW_FILENAME}) # To merge VS2017 and VS2015 binaries
|
|
string(REPLACE "-sgd-" "-gd-" NEW_FILENAME ${NEW_FILENAME}) # For Debug libs
|
|
string(REPLACE "-sgyd-" "-gyd-" NEW_FILENAME ${NEW_FILENAME}) # For Debug libs
|
|
string(REPLACE "-x32-" "-" NEW_FILENAME ${NEW_FILENAME}) # To enable CMake 3.10 and earlier to locate the binaries
|
|
string(REPLACE "-x64-" "-" NEW_FILENAME ${NEW_FILENAME}) # To enable CMake 3.10 and earlier to locate the binaries
|
|
string(REPLACE "-a32-" "-" NEW_FILENAME ${NEW_FILENAME}) # To enable CMake 3.10 and earlier to locate the binaries
|
|
string(REPLACE "-a64-" "-" NEW_FILENAME ${NEW_FILENAME}) # To enable CMake 3.10 and earlier to locate the binaries
|
|
string(REPLACE "_python3-" "_python-" NEW_FILENAME ${NEW_FILENAME})
|
|
if ("${DIRECTORY_OF_LIB_FILE}/${NEW_FILENAME}" STREQUAL "${DIRECTORY_OF_LIB_FILE}/${OLD_FILENAME}")
|
|
# nothing to do
|
|
elseif (EXISTS ${DIRECTORY_OF_LIB_FILE}/${NEW_FILENAME})
|
|
file(REMOVE ${DIRECTORY_OF_LIB_FILE}/${OLD_FILENAME})
|
|
else()
|
|
file(RENAME ${DIRECTORY_OF_LIB_FILE}/${OLD_FILENAME} ${DIRECTORY_OF_LIB_FILE}/${NEW_FILENAME})
|
|
endif()
|
|
endforeach()
|
|
endfunction()
|
|
|
|
function(boost_modular_headers)
|
|
cmake_parse_arguments(_bm "" "SOURCE_PATH" "" ${ARGN})
|
|
|
|
if(NOT DEFINED _bm_SOURCE_PATH)
|
|
message(FATAL_ERROR "SOURCE_PATH is a required argument to boost_modular_headers.")
|
|
endif()
|
|
|
|
message(STATUS "Packaging headers")
|
|
|
|
file(
|
|
COPY ${_bm_SOURCE_PATH}/include/boost
|
|
DESTINATION ${CURRENT_PACKAGES_DIR}/include
|
|
)
|
|
|
|
message(STATUS "Packaging headers done")
|
|
|
|
vcpkg_download_distfile(ARCHIVE
|
|
URLS "https://raw.githubusercontent.com/boostorg/boost/boost-1.65.1/LICENSE_1_0.txt"
|
|
FILENAME "boost_LICENSE_1_0.txt"
|
|
SHA512 d6078467835dba8932314c1c1e945569a64b065474d7aced27c9a7acc391d52e9f234138ed9f1aa9cd576f25f12f557e0b733c14891d42c16ecdc4a7bd4d60b8
|
|
)
|
|
|
|
file(INSTALL ${ARCHIVE} DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
|
|
endfunction()
|