aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-03-30 21:04:42 +0800
committercrupest <crupest@outlook.com>2019-03-30 21:04:42 +0800
commitee130224147f034e02d1d4d83e3f2d5a59e625c2 (patch)
tree79d73bb5c5b3e29657d31a90d45ff7d20c3c5041
parent88ecaa7f4f82b390cbda838b68121e93f878c299 (diff)
downloadcru-ee130224147f034e02d1d4d83e3f2d5a59e625c2.tar.gz
cru-ee130224147f034e02d1d4d83e3f2d5a59e625c2.tar.bz2
cru-ee130224147f034e02d1d4d83e3f2d5a59e625c2.zip
Link skia.
-rw-r--r--CMakeLists.txt17
-rw-r--r--README.md14
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--tools/build.py30
4 files changed, 47 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index df3e99f9..7f932f0d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,23 @@ cmake_minimum_required(VERSION 3.12) # use 3.12 because VS internal cmake is 3.1
project(CruUI)
+
+if(NOT CRU_CPU_ARCH)
+ set(CRU_CPU_ARCH x64)
+ message(STATUS "CPU arch not specified, use x64.")
+endif()
+
set(CMAKE_CXX_STANDARD 17)
+add_library(skia STATIC IMPORTED)
+if(${CRU_SKIA_USE_CLANG})
+ set_target_properties(skia PROPERTIES IMPORTED_LOCATION_DEBUG ${PROJECT_SOURCE_DIR}/skia/out/Debug_${CRU_CPU_ARCH}_clang/skia.lib
+ IMPORTED_LOCATION_RELEASE ${PROJECT_SOURCE_DIR}/skia/out/Release_${CRU_CPU_ARCH}_clang/skia.lib)
+else()
+ set_target_properties(skia PROPERTIES IMPORTED_LOCATION_DEBUG ${PROJECT_SOURCE_DIR}/skia/out/Debug_${CRU_CPU_ARCH}/skia.lib
+ IMPORTED_LOCATION_RELEASE ${PROJECT_SOURCE_DIR}/skia/out/Release_${CRU_CPU_ARCH}/skia.lib)
+endif()
+
+target_include_directories(skia INTERFACE skia/include)
+
add_subdirectory(src)
diff --git a/README.md b/README.md
index 6037584c..b722e815 100644
--- a/README.md
+++ b/README.md
@@ -4,22 +4,22 @@
## overview
-CruUI is a UI library running on *Windows* platform using *Direct2D* hardware accelaration.
+CruUI is a UI library using [*skia*](https://skia.org/).
It is **under construction**.
-Please using VS2017 open the `CruUI.sln` file in the root directory.
+## build
-## structure of repository
-
-- `CruUI.sln` is *Visual Studio* solution file of the repository.
+Set python2 on path to make skia build tool work. Use python3 to run `tool/build.py`. Run with `-h` to see the options.
- - `CruUI.vcxproj` is a *Visual Studio* vc++ project file that includes the main code in `src/`.
+## structure of repository
- `src/` contains the main codes including headers and sources.
- `tools/` contains some codes of tools like code generators.
- - `tools/cppmerge` contains a *python* script program that merges all cpp headers and sources into one **single** header and source.
+ - `tools/cppmerge` contains a *python* script program that merges all cpp headers and sources into one **single** header and source. **Not use now**.
+
+ - `tools/build.py` is a python3 script to build the source code.
- `snippets/` contains useful snippets file for *Visual Studio*, you can import it.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b89e5202..63faca66 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -25,6 +25,7 @@ add_library(cru_ui STATIC
target_include_directories(cru_ui PUBLIC .)
+target_link_libraries(cru_ui PUBLIC skia)
if(WIN32)
target_link_libraries(cru_ui PRIVATE D3D11 D2d1 DWrite)
diff --git a/tools/build.py b/tools/build.py
index c2829560..0fc23f18 100644
--- a/tools/build.py
+++ b/tools/build.py
@@ -13,27 +13,34 @@ parser.add_argument('--clang-build-skia', action='store_true',
help='whether use clang to build skia')
args = parser.parse_args()
+
class ConflictArgumentError(Exception):
def __init__(self, message):
self.message = message
+
if args.arch == 'x86' and args.clang_build_skia:
raise ConflictArgumentError('clang does not support to build skia in x86')
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
os.chdir(project_root)
+
def detect_ninja():
try:
subprocess.check_call('ninja --version')
except:
print('No ninja, install ninja.')
- subprocess.check_call('choco install ninja', stdout=sys.stdout, stderr=sys.stderr)
+ subprocess.check_call('choco install ninja',
+ stdout=sys.stdout, stderr=sys.stderr)
+
detect_ninja()
+
def build_skia():
- subprocess.check_call('py -2 .\\skia\\tools\\git-sync-deps', stdout=sys.stdout, stderr=sys.stderr)
+ subprocess.check_call('py -2 .\\skia\\tools\\git-sync-deps',
+ stdout=sys.stdout, stderr=sys.stderr)
gn_args = '''
is_debug = {debug}
@@ -49,7 +56,7 @@ def build_skia():
skia_use_lua = false
skia_use_sfntly = false
skia_use_xps = false
- '''.format(debug = 'true' if args.config == 'Debug' else 'false' )
+ '''.format(debug='true' if args.config == 'Debug' else 'false')
if args.arch == 'x86':
gn_args += 'target_cpu="x86"\n'
@@ -62,31 +69,38 @@ def build_skia():
out_dir += '_clang'
os.makedirs("skia/out/{}".format(out_dir), exist_ok=True)
- gn_arg_file_path = os.path.join(project_root, 'skia/out', out_dir, 'args.gn')
+ gn_arg_file_path = os.path.join(
+ project_root, 'skia/out', out_dir, 'args.gn')
with open(gn_arg_file_path, 'w+') as f:
f.write(gn_args)
-
+
os.chdir('./skia')
- subprocess.check_call('.\\bin\\gn.exe gen .\\out\\{}\\'.format(out_dir), stdout=sys.stdout, stderr=sys.stderr)
+ subprocess.check_call('.\\bin\\gn.exe gen .\\out\\{}\\'.format(
+ out_dir), stdout=sys.stdout, stderr=sys.stderr)
subprocess.check_call('ninja -C .\\out\\{} skia'.format(out_dir))
+
build_skia()
os.chdir(project_root)
+
def build_cru_ui():
- os.environ['PreferredToolArchitecture'] = 'x64' # use vs x64 toolchain
+ os.environ['PreferredToolArchitecture'] = 'x64' # use vs x64 toolchain
generater_vs_arch_map = {
'x86': 'Win32',
'x64': 'x64'
}
- subprocess.run('cmake -S . -B build -G "Visual Studio 15 2017" -A {arch}'.format(arch=generater_vs_arch_map[args.arch]),
+ subprocess.run('cmake -S . -B build -G "Visual Studio 15 2017" -A {arch} {clang}'
+ .format(arch=generater_vs_arch_map[args.arch],
+ clang="-DCRU_SKIA_USE_CLANG=TRUE" if args.clang_build_skia else ""),
stdout=sys.stdout, stderr=sys.stderr)
subprocess.run('cmake --build build --target ALL_BUILD --config {config}'.format(config=args.config),
stdout=sys.stdout, stderr=sys.stderr)
+
build_cru_ui()