2017-12-06 05:00:50 +08:00
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 ( )
2018-01-18 14:08:48 +08:00
set ( _bm_DIR ${ CURRENT_INSTALLED_DIR } /share/boost-build )
2017-12-06 05:00:50 +08:00
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 \ n e x e h a s _ a t o m i c _ f l a g _ l o c k f r e e "
" \ n \ n e x p l i c i t h a s _ a t o m i c _ f l a g _ l o c k f r e e ; \ n e x e h a s _ a t o m i c _ f l a g _ l o c k f r e e "
_ c o n t e n t s
" $ { _ c o n t e n t s } "
)
string ( REPLACE "\nimport ../../config/checks/config : requires ;" "\n# import ../../config/checks/config : requires ;" _contents "${_contents}" )
string ( REGEX REPLACE
" \ . \ . / \ . \ . / ( [ ^ / ] + ) / b u i l d / / ( b o o s t _ [ ^ / ] + ) "
" / b o o s t / \ \ 1 / / \ \ 2 "
_ c o n t e n t s
" $ { _ c o n t e n t s } "
)
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
" \ n p r o j e c t . l o a d [ p a t h . j o i n [ p a t h . m a k e $ ( h e r e : D ) ] . . / . . / c o n f i g / c h e c k s / a r c h i t e c t u r e ] ; "
" \ n # project.load [ path.join [ path.make $(here:D) ] ../../config/checks/architecture ] ;"
_ c o n t e n t s " $ { _ c o n t e n t s } " )
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
$ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - d b g
$ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - r e l
)
######################
# Generate configuration
######################
list ( APPEND _bm_OPTIONS
- j $ E N V { N U M B E R _ O F _ P R O C E S S O R S }
- - d e b u g - c o n f i g u r a t i o n
- - d e b u g - b u i l d i n g
- - d e b u g - g e n e r a t o r s
- - d i s a b l e - i c u
- - i g n o r e - s i t e - c o n f i g
- - h a s h
- q
2018-01-17 05:26:13 +08:00
- s Z L I B _ I N C L U D E = " $ { C U R R E N T _ I N S T A L L E D _ D I R } \ \ i n c l u d e "
- s B Z I P 2 _ I N C L U D E = " $ { C U R R E N T _ I N S T A L L E D _ D I R } \ \ i n c l u d e "
2017-12-06 05:00:50 +08:00
t h r e a d a p i = w i n 3 2
t h r e a d i n g = m u l t i
)
2018-01-17 05:26:13 +08:00
set ( _bm_OPTIONS_DBG
- s Z L I B _ B I N A R Y = z l i b d
- s Z L I B _ L I B P A T H = " $ { C U R R E N T _ I N S T A L L E D _ D I R } \ \ d e b u g \ \ l i b "
- s B Z I P 2 _ B I N A R Y = b z 2 d
- s B Z I P 2 _ L I B P A T H = " $ { C U R R E N T _ I N S T A L L E D _ D I R } \ \ d e b u g \ \ l i b "
)
set ( _bm_OPTIONS_REL
- s Z L I B _ B I N A R Y = z l i b
- s Z L I B _ L I B P A T H = " $ { C U R R E N T _ I N S T A L L E D _ D I R } \ \ l i b "
- s B Z I P 2 _ B I N A R Y = b z 2
- s B Z I P 2 _ L I B P A T H = " $ { C U R R E N T _ I N S T A L L E D _ D I R } \ \ l i b "
)
2017-12-06 05:00:50 +08:00
# 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
2017-12-21 18:37:25 +08:00
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 " )
2017-12-06 05:00:50 +08:00
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" )
2017-12-20 14:19:18 +08:00
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 (
C O M M A N D " $ { B 2 _ E X E } "
- - s t a g e d i r = $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - r e l / s t a g e
- - b u i l d - d i r = $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - r e l
- - u s e r - c o n f i g = $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - r e l / u s e r - c o n f i g . j a m
$ { _ b m _ O P T I O N S }
2018-01-17 05:26:13 +08:00
$ { _ b m _ O P T I O N S _ R E L }
2017-12-20 14:19:18 +08:00
v a r i a n t = r e l e a s e
d e b u g - s y m b o l s = o n
W O R K I N G _ D I R E C T O R Y $ { _ b m _ S O U R C E _ P A T H }
L O G N A M E b u i l d - $ { T A R G E T _ T R I P L E T } - r e l
)
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 (
C O M M A N D " $ { B 2 _ E X E } "
- - s t a g e d i r = $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - d b g / s t a g e
- - b u i l d - d i r = $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - d b g
- - u s e r - c o n f i g = $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - d b g / u s e r - c o n f i g . j a m
$ { _ b m _ O P T I O N S }
2018-01-17 05:26:13 +08:00
$ { _ b m _ O P T I O N S _ D B G }
2017-12-20 14:19:18 +08:00
v a r i a n t = d e b u g
W O R K I N G _ D I R E C T O R Y $ { _ b m _ S O U R C E _ P A T H }
L O G N A M E b u i l d - $ { T A R G E T _ T R I P L E T } - d b g
)
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 }
D E S T I N A T I O N $ { C U R R E N T _ P A C K A G E S _ D I R } / l i b
F I L E S _ M A T C H I N G P A T T E R N " * . l i b " )
if ( VCPKG_LIBRARY_LINKAGE STREQUAL dynamic )
file ( GLOB REL_DLLS ${ CURRENT_BUILDTREES_DIR } / ${ TARGET_TRIPLET } -rel/boost/build/*/*.dll )
file ( COPY ${ REL_DLLS }
D E S T I N A T I O N $ { C U R R E N T _ P A C K A G E S _ D I R } / b i n
F I L E S _ M A T C H I N G P A T T E R N " * . d l l " )
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 }
D E S T I N A T I O N $ { C U R R E N T _ P A C K A G E S _ D I R } / d e b u g / l i b
F I L E S _ M A T C H I N G P A T T E R N " * . l i b " )
if ( VCPKG_LIBRARY_LINKAGE STREQUAL dynamic )
file ( GLOB DBG_DLLS ${ CURRENT_BUILDTREES_DIR } / ${ TARGET_TRIPLET } -dbg/boost/build/*/*.dll )
file ( COPY ${ DBG_DLLS }
D E S T I N A T I O N $ { C U R R E N T _ P A C K A G E S _ D I R } / d e b u g / b i n
F I L E S _ M A T C H I N G P A T T E R N " * . d l l " )
endif ( )
message ( STATUS "Packaging ${TARGET_TRIPLET}-dbg done" )
endif ( )
2017-12-06 05:00:50 +08:00
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
2018-01-18 14:08:48 +08:00
string ( REPLACE "-1_66" "" NEW_FILENAME ${ NEW_FILENAME } ) # To enable CMake > 3.10 to locate the binaries
2017-12-06 05:00:50 +08:00
string ( REPLACE "_python3-" "_python-" NEW_FILENAME ${ NEW_FILENAME } )
2018-01-18 14:08:48 +08:00
if ( "${DIRECTORY_OF_LIB_FILE}/${NEW_FILENAME}" STREQUAL "${DIRECTORY_OF_LIB_FILE}/${OLD_FILENAME}" )
2017-12-06 05:00:50 +08:00
# nothing to do
2018-01-18 14:08:48 +08:00
elseif ( EXISTS ${ DIRECTORY_OF_LIB_FILE } / ${ NEW_FILENAME } )
2017-12-06 05:00:50 +08:00
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 ( )
2018-02-02 05:49:59 +08:00
vcpkg_copy_pdbs ( )
2017-12-06 05:00:50 +08:00
endfunction ( )