Skip to content

Commit 1678b75

Browse files
authored
feat(build.bat): customize build settings via environment variables (#178)
* feat(build.bat): customize build settings via environment variables * chore(build.bat): delete variable `CMAKE_TOOLSET` * fix(build.bat): Windows XP compatibility * fix(build.bat): BJAM_TOOLSET means platform toolset, not %VisualStudioVersion% * chore(build.bat): remove duplicate bjam options * fix(build.bat): set WINAPI_VERSION for x64
1 parent 202b01f commit 1678b75

File tree

19 files changed

+122
-129
lines changed

19 files changed

+122
-129
lines changed

README-windows.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ librime is tested to work on Windows with the following build tools and librarie
77
- Visual Studio 2015
88
- [Boost](http://www.boost.org/)>=1.60
99
- [cmake](http://www.cmake.org/)>=2.8
10+
11+
[Python](https://python.org)>=2.7 is needed to build opencc dictionaries.
1012

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

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

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

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

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

3033
Build Boost
3134
---

appveyor.yml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ cache:
2121
init:
2222
- git --version
2323
- cmake --version
24-
- msbuild /version
2524
- git config --global core.autocrlf true
2625

2726
install:

build.bat

+71-17
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
11
@echo off
22
rem Rime build script for msvc toolchain.
3-
rem 2014-12-30 Chen Gong <chen.sst@gmail.com>
3+
rem Maintainer: Chen Gong <chen.sst@gmail.com>
44

55
setlocal
66
set BACK=%CD%
77

88
if exist env.bat call env.bat
99

10+
rem for Windows XP compatibility (Visual Studio 2015+)
11+
set CL=/Zc:threadSafeInit-
12+
1013
set OLD_PATH=%PATH%
11-
if defined DEV_PATH set PATH=%OLD_PATH%;%DEV_PATH%
14+
if defined DEVTOOLS_PATH set PATH=%OLD_PATH%;%DEVTOOLS_PATH%
1215
path
1316
echo.
1417

1518
if not defined RIME_ROOT set RIME_ROOT=%CD%
1619
echo RIME_ROOT=%RIME_ROOT%
1720
echo.
1821

22+
if defined BOOST_ROOT (
23+
if exist "%BOOST_ROOT%\boost" goto boost_found
24+
)
25+
echo Error: Boost not found! Please set BOOST_ROOT in env.bat.
26+
exit /b 1
27+
:boost_found
1928
echo BOOST_ROOT=%BOOST_ROOT%
2029
echo.
2130

22-
if defined CMAKE_INSTALL_PATH set PATH=%PATH%;%CMAKE_INSTALL_PATH%
31+
if not defined BJAM_TOOLSET (
32+
rem the number actually means platform toolset, not %VisualStudioVersion%
33+
set BJAM_TOOLSET=msvc-14.0
34+
)
35+
36+
if not defined CMAKE_GENERATOR (
37+
set CMAKE_GENERATOR="Visual Studio 14 2015"
38+
)
39+
40+
if not defined PLATFORM_TOOLSET (
41+
set PLATFORM_TOOLSET=v140_xp
42+
)
2343

24-
set CMAKE_GENERATOR="Visual Studio 14 2015"
25-
set CMAKE_TOOLSET="v140_xp"
44+
rem used when building marisa
45+
set VS_LATEST=vs2015
2646

2747
set build=build
2848
set build_boost=0
49+
set build_boost_x64=0
2950
set build_thirdparty=0
3051
set build_librime=0
3152
set build_shared=ON
@@ -37,6 +58,7 @@ if "%1" == "" set build_librime=1
3758
:parse_cmdline_options
3859
if "%1" == "" goto end_parsing_cmdline_options
3960
if "%1" == "boost" set build_boost=1
61+
if "%1" == "boost_x64" set build_boost_x64=1
4062
if "%1" == "thirdparty" set build_thirdparty=1
4163
if "%1" == "librime" set build_librime=1
4264
if "%1" == "static" (
@@ -66,22 +88,49 @@ set THIRDPARTY="%RIME_ROOT%"\thirdparty
6688
rem set CURL=%THIRDPARTY%\bin\curl.exe
6789
rem set DOWNLOAD="%CURL%" --remote-name-all
6890

91+
set BOOST_COMPILED_LIBS=--with-date_time^
92+
--with-filesystem^
93+
--with-locale^
94+
--with-regex^
95+
--with-signals^
96+
--with-system^
97+
--with-thread
98+
99+
set BJAM_OPTIONS_COMMON=toolset=%BJAM_TOOLSET%^
100+
variant=release^
101+
link=static^
102+
threading=multi^
103+
runtime-link=static^
104+
cxxflags="/Zc:threadSafeInit- "
105+
106+
set BJAM_OPTIONS_X86=%BJAM_OPTIONS_COMMON%^
107+
define=BOOST_USE_WINAPI_VERSION=0x0501
108+
109+
set BJAM_OPTIONS_X64=%BJAM_OPTIONS_COMMON%^
110+
define=BOOST_USE_WINAPI_VERSION=0x0502^
111+
address-model=64^
112+
--stagedir=stage_x64
113+
69114
if %build_boost% == 1 (
70115
cd /d %BOOST_ROOT%
71116
if not exist bjam.exe call bootstrap.bat
72117
if %ERRORLEVEL% NEQ 0 goto ERROR
73-
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
118+
119+
bjam %BJAM_OPTIONS_X86% stage %BOOST_COMPILED_LIBS%
74120
if %ERRORLEVEL% NEQ 0 goto ERROR
75-
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
76-
rem if %ERRORLEVEL% NEQ 0 goto ERROR
121+
122+
if %build_boost_x64% == 1 (
123+
bjam %BJAM_OPTIONS_X64% stage %BOOST_COMPILED_LIBS%
124+
if %ERRORLEVEL% NEQ 0 goto ERROR
125+
)
77126
)
78127

79128
if %build_thirdparty% == 1 (
80129
cd /d %THIRDPARTY%
81130

82131
echo building glog.
83132
cd %THIRDPARTY%\src\glog
84-
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"
133+
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"
85134
if %ERRORLEVEL% NEQ 0 goto ERROR
86135
cmake --build build --config Release --target glog
87136
if %ERRORLEVEL% NEQ 0 goto ERROR
@@ -104,7 +153,7 @@ if %build_thirdparty% == 1 (
104153

105154
echo building yaml-cpp.
106155
cd %THIRDPARTY%\src\yaml-cpp
107-
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"
156+
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"
108157
if %ERRORLEVEL% NEQ 0 goto ERROR
109158
cmake --build build --config Release --target yaml-cpp
110159
if %ERRORLEVEL% NEQ 0 goto ERROR
@@ -116,7 +165,7 @@ if %build_thirdparty% == 1 (
116165

117166
echo building gtest.
118167
cd %THIRDPARTY%\src\gtest
119-
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"
168+
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"
120169
if %ERRORLEVEL% NEQ 0 goto ERROR
121170
cmake --build build --config Release
122171
if %ERRORLEVEL% NEQ 0 goto ERROR
@@ -127,8 +176,8 @@ if %build_thirdparty% == 1 (
127176
if %ERRORLEVEL% NEQ 0 goto ERROR
128177

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

142191
echo building opencc.
143192
cd %THIRDPARTY%\src\opencc
144-
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"
193+
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"
145194
if %ERRORLEVEL% NEQ 0 goto ERROR
146195
cmake --build build --config Release --target libopencc
147196
if %ERRORLEVEL% NEQ 0 goto ERROR
@@ -168,11 +217,16 @@ if %build_thirdparty% == 1 (
168217

169218
if %build_librime% == 0 goto EXIT
170219

171-
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"
220+
set RIME_CMAKE_FLAGS=-DBUILD_STATIC=ON^
221+
-DBUILD_SHARED_LIBS=%build_shared%^
222+
-DBUILD_TEST=%build_test%^
223+
-DENABLE_LOGGING=%enable_logging%^
224+
-DBOOST_USE_CXX11=ON^
225+
-DCMAKE_CONFIGURATION_TYPES="Release"
172226

173227
cd /d %RIME_ROOT%
174-
echo cmake %RIME_ROOT% -B%build% -G%CMAKE_GENERATOR% -T%CMAKE_TOOLSET% %RIME_CMAKE_FLAGS%
175-
call cmake %RIME_ROOT% -B%build% -G%CMAKE_GENERATOR% -T%CMAKE_TOOLSET% %RIME_CMAKE_FLAGS%
228+
echo cmake %RIME_ROOT% -B%build% -G%CMAKE_GENERATOR% -T%PLATFORM_TOOLSET% %RIME_CMAKE_FLAGS%
229+
call cmake %RIME_ROOT% -B%build% -G%CMAKE_GENERATOR% -T%PLATFORM_TOOLSET% %RIME_CMAKE_FLAGS%
176230
if %ERRORLEVEL% NEQ 0 goto ERROR
177231

178232
echo.

env.bat.template

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
rem environment settings
1+
rem Customize your build environment and save the modified copy to env.bat
2+
23
set RIME_ROOT=%CD%
3-
set BOOST_ROOT=\code\boost_1_60_0
4-
set CMAKE_INSTALL_PATH=C:\Program Files (x86)\CMake
5-
set GIT_INSTALL_PATH=C:\Program Files (x86)\Git
6-
set VS_INSTALL_PATH=%VS140COMNTOOLS%\..\..
4+
5+
rem REQUIRED: path to Boost source directory
6+
set BOOST_ROOT=%USERPROFILE%\source\vendor\boost_1_60_0
7+
8+
rem OPTIONAL: Visual Studio version and platform toolset
9+
rem set BJAM_TOOLSET=msvc-14.0
10+
rem set CMAKE_GENERATOR="Visual Studio 14 2015"
11+
rem set PLATFORM_TOOLSET=v140_xp
12+
13+
rem OPTIONAL: path to additional build tools
14+
rem set DEVTOOLS_PATH=%ProgramFiles%\Git\cmd;%ProgramFiles%\CMake\bin;C:\Python27;

shell.bat

-71
This file was deleted.

thirdparty/src/leveldb-windows/leveldb.vcxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup Label="ProjectConfigurations">
44
<ProjectConfiguration Include="Debug|Win32">
@@ -18,12 +18,12 @@
1818
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
1919
<ConfigurationType>StaticLibrary</ConfigurationType>
2020
<UseDebugLibraries>true</UseDebugLibraries>
21-
<PlatformToolset>v140_xp</PlatformToolset>
21+
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
2222
</PropertyGroup>
2323
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
2424
<ConfigurationType>StaticLibrary</ConfigurationType>
2525
<UseDebugLibraries>false</UseDebugLibraries>
26-
<PlatformToolset>v140_xp</PlatformToolset>
26+
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
2929
<ImportGroup Label="ExtensionSettings">
@@ -171,4 +171,4 @@
171171
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
172172
<ImportGroup Label="ExtensionTargets">
173173
</ImportGroup>
174-
</Project>
174+
</Project>

thirdparty/src/marisa-trie/vs2015/base-test/base-test.vcxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
1919
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
2020
<ConfigurationType>Application</ConfigurationType>
21-
<PlatformToolset>v140_xp</PlatformToolset>
21+
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
2222
<CharacterSet>Unicode</CharacterSet>
2323
<WholeProgramOptimization>true</WholeProgramOptimization>
2424
</PropertyGroup>
2525
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
2626
<ConfigurationType>Application</ConfigurationType>
27-
<PlatformToolset>v140_xp</PlatformToolset>
27+
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
2828
<CharacterSet>Unicode</CharacterSet>
2929
</PropertyGroup>
3030
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

thirdparty/src/marisa-trie/vs2015/io-test/io-test.vcxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
1919
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
2020
<ConfigurationType>Application</ConfigurationType>
21-
<PlatformToolset>v140_xp</PlatformToolset>
21+
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
2222
<CharacterSet>Unicode</CharacterSet>
2323
<WholeProgramOptimization>true</WholeProgramOptimization>
2424
</PropertyGroup>
2525
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
2626
<ConfigurationType>Application</ConfigurationType>
27-
<PlatformToolset>v140_xp</PlatformToolset>
27+
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
2828
<CharacterSet>Unicode</CharacterSet>
2929
</PropertyGroup>
3030
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

thirdparty/src/marisa-trie/vs2015/libmarisa/libmarisa.vcxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
1919
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
2020
<ConfigurationType>StaticLibrary</ConfigurationType>
21-
<PlatformToolset>v140_xp</PlatformToolset>
21+
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
2222
<CharacterSet>Unicode</CharacterSet>
2323
<WholeProgramOptimization>true</WholeProgramOptimization>
2424
</PropertyGroup>
2525
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
2626
<ConfigurationType>StaticLibrary</ConfigurationType>
27-
<PlatformToolset>v140_xp</PlatformToolset>
27+
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
2828
<CharacterSet>Unicode</CharacterSet>
2929
</PropertyGroup>
3030
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

0 commit comments

Comments
 (0)