Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build.bat): customize build settings via environment variables #178

Merged
merged 6 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ librime is tested to work on Windows with the following build tools and librarie
- Visual Studio 2015
- [Boost](http://www.boost.org/)>=1.60
- [cmake](http://www.cmake.org/)>=2.8

[Python](https://python.org)>=2.7 is needed to build opencc dictionaries.

You may need to update Boost when using a higher version of VS.

You can also build third-party libraries manually without them, by following instructions in the build script.
You can also build third-party libraries manually, by following instructions in the build script.

Get the code
---
Expand All @@ -21,11 +23,12 @@ or [download from GitHub](https://github.com/rime/librime).

Setup a build environment
---
Copy `env.bat` from `env.bat.template` and edit the script according to your setup.
Specifically, make sure `BOOST_ROOT` is set to the path where you extracted Boost source;
modify `*_INSTALL_PATH` if you've installed build tools in a custom location.
Copy `env.bat.template` to `env.bat` and edit the script according to your setup.
Specifically, make sure `BOOST_ROOT` is set to the path to Boost source directory;
modify `CMAKE_GENERATOR` and `PLATFORM_TOOLSET` if using a different version of Visual Studio;
set `DEVTOOLS_PATH` for build tools installed to a custom location.

When finished, run `shell.bat` to complete the following steps in a prepared command prompt.
When prepared, run the following commands in a Developer Command Prompt window.

Build Boost
---
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ cache:
init:
- git --version
- cmake --version
- msbuild /version
- git config --global core.autocrlf true

install:
Expand Down
88 changes: 71 additions & 17 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
@echo off
rem Rime build script for msvc toolchain.
rem 2014-12-30 Chen Gong <chen.sst@gmail.com>
rem Maintainer: Chen Gong <chen.sst@gmail.com>

setlocal
set BACK=%CD%

if exist env.bat call env.bat

rem for Windows XP compatibility (Visual Studio 2015+)
set CL=/Zc:threadSafeInit-

set OLD_PATH=%PATH%
if defined DEV_PATH set PATH=%OLD_PATH%;%DEV_PATH%
if defined DEVTOOLS_PATH set PATH=%OLD_PATH%;%DEVTOOLS_PATH%
path
echo.

if not defined RIME_ROOT set RIME_ROOT=%CD%
echo RIME_ROOT=%RIME_ROOT%
echo.

if defined BOOST_ROOT (
if exist "%BOOST_ROOT%\boost" goto boost_found
)
echo Error: Boost not found! Please set BOOST_ROOT in env.bat.
exit /b 1
:boost_found
echo BOOST_ROOT=%BOOST_ROOT%
echo.

if defined CMAKE_INSTALL_PATH set PATH=%PATH%;%CMAKE_INSTALL_PATH%
if not defined BJAM_TOOLSET (
rem the number actually means platform toolset, not %VisualStudioVersion%
set BJAM_TOOLSET=msvc-14.0
)

if not defined CMAKE_GENERATOR (
set CMAKE_GENERATOR="Visual Studio 14 2015"
)

if not defined PLATFORM_TOOLSET (
set PLATFORM_TOOLSET=v140_xp
)

set CMAKE_GENERATOR="Visual Studio 14 2015"
set CMAKE_TOOLSET="v140_xp"
rem used when building marisa
set VS_LATEST=vs2015

set build=build
set build_boost=0
set build_boost_x64=0
set build_thirdparty=0
set build_librime=0
set build_shared=ON
Expand All @@ -37,6 +58,7 @@ if "%1" == "" set build_librime=1
:parse_cmdline_options
if "%1" == "" goto end_parsing_cmdline_options
if "%1" == "boost" set build_boost=1
if "%1" == "boost_x64" set build_boost_x64=1
if "%1" == "thirdparty" set build_thirdparty=1
if "%1" == "librime" set build_librime=1
if "%1" == "static" (
Expand Down Expand Up @@ -66,22 +88,49 @@ set THIRDPARTY="%RIME_ROOT%"\thirdparty
rem set CURL=%THIRDPARTY%\bin\curl.exe
rem set DOWNLOAD="%CURL%" --remote-name-all

set BOOST_COMPILED_LIBS=--with-date_time^
--with-filesystem^
--with-locale^
--with-regex^
--with-signals^
--with-system^
--with-thread

set BJAM_OPTIONS_COMMON=toolset=%BJAM_TOOLSET%^
variant=release^
link=static^
threading=multi^
runtime-link=static^
cxxflags="/Zc:threadSafeInit- "

set BJAM_OPTIONS_X86=%BJAM_OPTIONS_COMMON%^
define=BOOST_USE_WINAPI_VERSION=0x0501

set BJAM_OPTIONS_X64=%BJAM_OPTIONS_COMMON%^
define=BOOST_USE_WINAPI_VERSION=0x0502^
address-model=64^
--stagedir=stage_x64

if %build_boost% == 1 (
cd /d %BOOST_ROOT%
if not exist bjam.exe call bootstrap.bat
if %ERRORLEVEL% NEQ 0 goto ERROR
bjam toolset=msvc-14.0 variant=release link=static threading=multi runtime-link=static stage --with-date_time --with-filesystem --with-locale --with-regex --with-signals --with-system --with-thread

bjam %BJAM_OPTIONS_X86% stage %BOOST_COMPILED_LIBS%
if %ERRORLEVEL% NEQ 0 goto ERROR
rem bjam toolset=msvc-14.0 variant=release link=static threading=multi runtime-link=static address-model=64 --stagedir=stage_x64 stage --with-date_time --with-filesystem --with-locale --with-regex --with-signals --with-system --with-thread
rem if %ERRORLEVEL% NEQ 0 goto ERROR

if %build_boost_x64% == 1 (
bjam %BJAM_OPTIONS_X64% stage %BOOST_COMPILED_LIBS%
if %ERRORLEVEL% NEQ 0 goto ERROR
)
)

if %build_thirdparty% == 1 (
cd /d %THIRDPARTY%

echo building glog.
cd %THIRDPARTY%\src\glog
cmake . -Bbuild -G%CMAKE_GENERATOR% -T%CMAKE_TOOLSET% -DWITH_GFLAGS=OFF -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG"
cmake . -Bbuild -G%CMAKE_GENERATOR% -T%PLATFORM_TOOLSET% -DWITH_GFLAGS=OFF -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG"
if %ERRORLEVEL% NEQ 0 goto ERROR
cmake --build build --config Release --target glog
if %ERRORLEVEL% NEQ 0 goto ERROR
Expand All @@ -104,7 +153,7 @@ if %build_thirdparty% == 1 (

echo building yaml-cpp.
cd %THIRDPARTY%\src\yaml-cpp
cmake . -Bbuild -G%CMAKE_GENERATOR% -T%CMAKE_TOOLSET% -DMSVC_SHARED_RT=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG"
cmake . -Bbuild -G%CMAKE_GENERATOR% -T%PLATFORM_TOOLSET% -DMSVC_SHARED_RT=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG"
if %ERRORLEVEL% NEQ 0 goto ERROR
cmake --build build --config Release --target yaml-cpp
if %ERRORLEVEL% NEQ 0 goto ERROR
Expand All @@ -116,7 +165,7 @@ if %build_thirdparty% == 1 (

echo building gtest.
cd %THIRDPARTY%\src\gtest
cmake . -Bbuild -G%CMAKE_GENERATOR% -T%CMAKE_TOOLSET% -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG"
cmake . -Bbuild -G%CMAKE_GENERATOR% -T%PLATFORM_TOOLSET% -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG" -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG"
if %ERRORLEVEL% NEQ 0 goto ERROR
cmake --build build --config Release
if %ERRORLEVEL% NEQ 0 goto ERROR
Expand All @@ -127,8 +176,8 @@ if %build_thirdparty% == 1 (
if %ERRORLEVEL% NEQ 0 goto ERROR

echo building marisa.
cd %THIRDPARTY%\src\marisa-trie\vs2015
msbuild.exe vs2015.sln /p:Configuration=Release /p:Platform=Win32
cd %THIRDPARTY%\src\marisa-trie\%VS_LATEST%
msbuild.exe %VS_LATEST%.sln /p:Configuration=Release /p:Platform=Win32
if %ERRORLEVEL% NEQ 0 goto ERROR
echo built. copying artifacts.
xcopy /S /I /Y ..\lib\marisa %THIRDPARTY%\include\marisa\
Expand All @@ -141,7 +190,7 @@ if %build_thirdparty% == 1 (

echo building opencc.
cd %THIRDPARTY%\src\opencc
cmake . -Bbuild -G%CMAKE_GENERATOR% -T%CMAKE_TOOLSET% -DCMAKE_INSTALL_PREFIX="" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG"
cmake . -Bbuild -G%CMAKE_GENERATOR% -T%PLATFORM_TOOLSET% -DCMAKE_INSTALL_PREFIX="" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /D NDEBUG"
if %ERRORLEVEL% NEQ 0 goto ERROR
cmake --build build --config Release --target libopencc
if %ERRORLEVEL% NEQ 0 goto ERROR
Expand All @@ -168,11 +217,16 @@ if %build_thirdparty% == 1 (

if %build_librime% == 0 goto EXIT

set RIME_CMAKE_FLAGS=-DBUILD_STATIC=ON -DBUILD_SHARED_LIBS=%build_shared% -DBUILD_TEST=%build_test% -DENABLE_LOGGING=%enable_logging% -DBOOST_USE_CXX11=ON -DCMAKE_CONFIGURATION_TYPES="Release"
set RIME_CMAKE_FLAGS=-DBUILD_STATIC=ON^
-DBUILD_SHARED_LIBS=%build_shared%^
-DBUILD_TEST=%build_test%^
-DENABLE_LOGGING=%enable_logging%^
-DBOOST_USE_CXX11=ON^
-DCMAKE_CONFIGURATION_TYPES="Release"

cd /d %RIME_ROOT%
echo cmake %RIME_ROOT% -B%build% -G%CMAKE_GENERATOR% -T%CMAKE_TOOLSET% %RIME_CMAKE_FLAGS%
call cmake %RIME_ROOT% -B%build% -G%CMAKE_GENERATOR% -T%CMAKE_TOOLSET% %RIME_CMAKE_FLAGS%
echo cmake %RIME_ROOT% -B%build% -G%CMAKE_GENERATOR% -T%PLATFORM_TOOLSET% %RIME_CMAKE_FLAGS%
call cmake %RIME_ROOT% -B%build% -G%CMAKE_GENERATOR% -T%PLATFORM_TOOLSET% %RIME_CMAKE_FLAGS%
if %ERRORLEVEL% NEQ 0 goto ERROR

echo.
Expand Down
18 changes: 13 additions & 5 deletions env.bat.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
rem environment settings
rem Customize your build environment and save the modified copy to env.bat

set RIME_ROOT=%CD%
set BOOST_ROOT=\code\boost_1_60_0
set CMAKE_INSTALL_PATH=C:\Program Files (x86)\CMake
set GIT_INSTALL_PATH=C:\Program Files (x86)\Git
set VS_INSTALL_PATH=%VS140COMNTOOLS%\..\..

rem REQUIRED: path to Boost source directory
set BOOST_ROOT=%USERPROFILE%\source\vendor\boost_1_60_0

rem OPTIONAL: Visual Studio version and platform toolset
rem set BJAM_TOOLSET=msvc-14.0
rem set CMAKE_GENERATOR="Visual Studio 14 2015"
rem set PLATFORM_TOOLSET=v140_xp

rem OPTIONAL: path to additional build tools
rem set DEVTOOLS_PATH=%ProgramFiles%\Git\cmd;%ProgramFiles%\CMake\bin;C:\Python27;
71 changes: 0 additions & 71 deletions shell.bat

This file was deleted.

8 changes: 4 additions & 4 deletions thirdparty/src/leveldb-windows/leveldb.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
Expand All @@ -18,12 +18,12 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -171,4 +171,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions thirdparty/src/marisa-trie/vs2015/base-test/base-test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/src/marisa-trie/vs2015/io-test/io-test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/src/marisa-trie/vs2015/libmarisa/libmarisa.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down
Loading