Convert build_fmt.ps1 to build_fmt_win.py

Also fix release build
This commit is contained in:
John Colvin committed 2022-02-23 14:16:38 -05:00
1 parent aacb371837
commit 091f8805f3
2 files changed
+108 -47

No files matched your search

-47
View File
@@ -1,47 +0,0 @@
$fmt = "fmt_at-commit-215f21a0382d325efa66df53fbfbfddb020a2234"
$root = Resolve-Path "../.."
$work = Join-Path $root "work"
$src = Join-Path $root src
$target = Join-Path $root "windows"
Push-Location
if (Test-Path $work) {
Remove-Item -Force -Recurse $work
}
# clean
Remove-Item $target\lib\debug\libfmt.*
Remove-Item $target\lib\release\libfmt.*
if (Test-Path $target\include\fmt) {
Remove-Item -Force -Recurse $target\include\fmt
}
# expand
unzip -q $src\fmt\$fmt -d $work
# configure
$cmake_dir $fmt
$install_dir $work\$fmt\install
$build_dir $work\$fmt\build
New-Item -ItemType Directory -Path $build_dir
Set-Location $build_dir
cmake -DCMAKE_INSTALL_PREFIX=$install_dir -DCMAKE_CXX_STANDARD=17 -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug -DFMT_TEST=no -G "Visual Studio 16 2019" $cmake_dir
## For Debug
# build
msbuild /m /p:platform=x64 /p:Configuration=Debug /p:debugtype=portable /clp:summary /clp:verbosity=minimal $build_dir/FMT.sln
# copy libs and symbols
Copy-Item $build_dir\Debug\fmtd.lib $target\lib\debug\libfmt.lib
Copy-Item $build_dir\Debug\fmtd.pdb $target\lib\debug\fmtd.pdb
## For Release
# build
msbuild /m /p:platform=x64 /p:Configuration=Release /clp:summary /clp:verbosity=minimal $build_dir/FMT.sln
msbuild /m /p:platform=x64 /p:Configuration=Release /clp:summary /clp:verbosity=minimal $build_dir/INSTALL.vcxproj
# copy libs and headers
Copy-Item $build_dir\Release\fmt.lib $target\lib\release\libfmt.lib
Copy-Item -Recurse $install_dir\include\fmt $target\include\
cd $root
Remove-Item -Force -Recurse $work
Pop-Location
+108
View File
@@ -0,0 +1,108 @@
import os
import shutil
import subprocess
from zipfile import ZipFile
class CWD:
def __init__(self, push_path, pop_path=os.getcwd()):
self.push_path = push_path
self.pop_path = pop_path
def __enter__(self):
if self.push_path is not None:
os.chdir(self.push_path)
def __exit__(self, exc_type, exc_val, exc_tb):
if self.pop_path is not None:
os.chdir(self.pop_path)
def build(
configuration: str, msvc_runtime_lib: str, debugtype: str, cmake_dir,
build_dir, install_dir):
os.makedirs(build_dir)
with CWD(build_dir):
cmake_cmd = (
f'cmake -DCMAKE_INSTALL_PREFIX={install_dir} '
'-DCMAKE_CXX_STANDARD=17 '
f'-DCMAKE_MSVC_RUNTIME_LIBRARY={msvc_runtime_lib} '
'-DFMT_TEST=no '
f'-G "Visual Studio 16 2019" {cmake_dir}')
msbuild_cmd = (
'msbuild /m '
'/p:platform=x64 '
f'/p:Configuration={configuration} '
f'/p:debugtype={debugtype} '
'/clp:summary '
'/clp:verbosity=minimal '
f'{os.path.join(build_dir, "FMT.sln")}')
for cmd in [cmake_cmd, msbuild_cmd]:
print(f'running build step: {cmd}')
subprocess.run(cmd)
def build_debug(cmake_dir, build_dir, install_dir):
build(
'debug', 'MultiThreadedDebug', 'Portable', cmake_dir, build_dir,
install_dir)
def build_release(cmake_dir, build_dir, install_dir):
build(
'release', 'MultiThreaded', 'None', cmake_dir, build_dir, install_dir)
def install_debug(build_dir, target_dir):
# copy lib and pdb to target
target_lib_dir = os.path.join(target_dir, 'lib', 'debug')
for file in ['fmtd.lib', 'fmtd.pdb']:
shutil.copy(os.path.join(build_dir, 'debug', file), target_lib_dir)
def install_release(build_dir, target_dir):
# copy lib to target
target_lib_dir = os.path.join(target_dir, 'lib', 'release')
for file in ['fmt.lib']:
shutil.copy(os.path.join(build_dir, 'release', file), target_lib_dir)
# copy include to target
target_include_dir = os.path.join(target_dir, 'include', 'fmt')
if os.path.exists(target_include_dir):
shutil.rmtree(target_include_dir)
shutil.copytree(
os.path.join(build_dir, '..', 'include', 'fmt'), target_include_dir)
def _main():
fmt_dirname = "fmt_at-commit-215f21a0382d325efa66df53fbfbfddb020a2234"
externals_root_dir = os.path.abspath("../..")
fmt_zip_path = os.path.join(
externals_root_dir, 'src', 'fmt', f'{fmt_dirname}.zip')
work_dir = os.path.join(externals_root_dir, "work")
target_dir = os.path.join(externals_root_dir, "windows")
cmake_dir = os.path.join(work_dir, fmt_dirname)
if os.path.exists(work_dir):
shutil.rmtree(work_dir)
os.makedirs(work_dir)
with ZipFile(fmt_zip_path) as zip_ref:
zip_ref.extractall(work_dir)
with CWD(cmake_dir):
# debug
dbg_build_dir = os.path.join(work_dir, fmt_dirname, 'build_debug')
build_debug(cmake_dir, dbg_build_dir, target_dir)
install_debug(dbg_build_dir, target_dir)
# release
rel_build_dir = os.path.join(work_dir, fmt_dirname, 'build_release')
build_release(cmake_dir, rel_build_dir, target_dir)
install_release(rel_build_dir, target_dir)
shutil.rmtree(work_dir)
if __name__ == '__main__':
_main()