[env]: Change hard-code settings to be generated by py

This commit is contained in:
fanlumaster
2025-06-02 10:12:09 +08:00
parent 01514100a1
commit 5cd5964351
13 changed files with 288 additions and 27 deletions

View File

@ -0,0 +1,11 @@
CompileFlags:
Add: [
-DUNICODE,
-D_UNICODE,
"-std=c++17",
"-IC:/Users/19833/EDisk/CppCodes/ImeCodes/googlepinyinime-rev/build/vcpkg_installed/x64-windows/include",
# -Wno-unused-value,
] # ignore some specific warnings
CompilationDatabase: build/ # Search build/ directory for compile_commands.json
# Diagnostics:
# UnusedIncludes: None # ignore unused includes

View File

@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.15)
project(pinyinime VERSION 1.0 LANGUAGES CXX)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/include)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
add_definitions(
/D_UNICODE=1
/DUNICODE=1
)
# For utf8cpp, make it use C++11 and later
add_compile_options(/Zc:__cplusplus)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# For pure-header libs installed by vcpkg like utf8cpp
include_directories("./build/vcpkg_installed/x64-windows/include")
set(HEADERS
./src/include/atomdictbase.h
./src/include/dictbuilder.h
./src/include/dictdef.h
./src/include/dictlist.h
./src/include/dicttrie.h
./src/include/lpicache.h
./src/include/matrixsearch.h
./src/include/mystdlib.h
./src/include/ngram.h
./src/include/pinyinime.h
./src/include/searchutility.h
./src/include/spellingtable.h
./src/include/spellingtrie.h
./src/include/splparser.h
./src/include/sync.h
./src/include/userdict.h
./src/include/utf16char.h
./src/include/utf16reader.h
)
set(SOURCES
./src/share/dictbuilder.cpp
./src/share/dictlist.cpp
./src/share/dicttrie.cpp
./src/share/lpicache.cpp
./src/share/matrixsearch.cpp
./src/share/mystdlib.cpp
./src/share/ngram.cpp
./src/share/pinyinime.cpp
./src/share/searchutility.cpp
./src/share/spellingtable.cpp
./src/share/spellingtrie.cpp
./src/share/splparser.cpp
./src/share/sync.cpp
./src/share/userdict.cpp
./src/share/utf16char.cpp
./src/share/utf16reader.cpp
./tests/main.cpp
)
set(MY_EXECUTABLE_NAME "pinyinime")
add_executable(pinyinime ${SOURCES} ${HEADERS})

View File

@ -0,0 +1,17 @@
{
"version": 2,
"configurePresets": [
{
"name": "vcpkg",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/build",
"environment": {
"VCPKG_ROOT": "C:/Users/19833/scoop/apps/vcpkg/current/"
},
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "C:/Users/19833/scoop/apps/vcpkg/current/scripts/buildsystems/vcpkg.cmake",
"CMAKE_BUILD_TYPE": "Debug"
}
}
]
}

View File

@ -2,25 +2,23 @@
$currentDirectory = Get-Location
$cmakeListsPath = Join-Path -Path $currentDirectory -ChildPath "CMakeLists.txt"
if (-not (Test-Path $cmakeListsPath))
{
Write-Host("No CMakeLists.txt in current directory, please check.")
return
if (-not (Test-Path $cmakeListsPath)) {
Write-Host("No CMakeLists.txt in current directory, please check.")
return
}
Write-Host "Start generating and compiling..."
$buildFolderPath = ".\build"
if (-not (Test-Path $buildFolderPath))
{
New-Item -ItemType Directory -Path $buildFolderPath | Out-Null
Write-Host "build folder created."
if (-not (Test-Path $buildFolderPath)) {
New-Item -ItemType Directory -Path $buildFolderPath | Out-Null
Write-Host "build folder created."
}
cmake -G "Visual Studio 17 2022" -A x64 -S . -B ./build/
# cmake -G "Visual Studio 17 2022" -A x64 -S . -B ./build/
cmake --preset=default
if ($LASTEXITCODE -eq 0)
{
cmake --build ./build/ --config DEBUG
if ($LASTEXITCODE -eq 0) {
cmake --build build
}

View File

@ -31,10 +31,11 @@ if (-not (Test-Path $buildFolderPath)) {
Write-Host "build folder created."
}
cmake -G "Visual Studio 17 2022" -A x64 -S . -B ./build/
# cmake -G -A x64 -DCMAKE_TOOLCHAIN_FILE=C:/Users/SonnyCalcr/scoop/apps/vcpkg/current/scripts/buildsystems/vcpkg.cmake -S . -B ./build/
cmake --preset=default
if ($LASTEXITCODE -eq 0) {
cmake --build ./build/ --config DEBUG
cmake --build build
if ($LASTEXITCODE -eq 0) {
$exePath = getExePathFromCMakeLists
Write-Host "start running as follows..."
@ -42,4 +43,3 @@ if ($LASTEXITCODE -eq 0) {
Invoke-Expression $exePath
}
}

96
scripts/prepare_env.py Normal file
View File

@ -0,0 +1,96 @@
import os
def normpath(path):
return path.replace("\\", "/")
local_app_data_dir = os.environ.get("LOCALAPPDATA")
home_dir = os.path.expanduser("~")
cur_file_path = os.path.dirname(os.path.abspath(__file__))
project_root_path = os.path.dirname(cur_file_path)
user_home = os.path.expanduser("~")
googlepinyinime_rev_root_path = normpath(project_root_path)
googlepinyinime_rev_src_path = normpath(
os.path.join(googlepinyinime_rev_root_path, "src")
)
vcpkg_include_path = normpath(
os.path.join(
googlepinyinime_rev_root_path,
"build",
"vcpkg_installed",
"x64-windows",
"include",
)
)
webview2_path = normpath(
os.path.join(
user_home,
".nuget",
"packages",
"microsoft.web.webview2",
"1.0.3240.44",
"build",
"native",
"include",
)
)
wim_path = normpath(
os.path.join(
user_home,
".nuget",
"packages",
"microsoft.windows.implementationlibrary",
"1.0.240803.1",
"include",
)
)
boost_path = normpath(os.path.join(user_home, "scoop", "apps", "boost", "current"))
#
# project_root/.clangd
#
dot_clangd_file = os.path.join(
googlepinyinime_rev_root_path, "scripts", "config_files", ".clangd"
)
dot_clangd_output_file = os.path.join(googlepinyinime_rev_root_path, ".clangd")
with open(dot_clangd_file, "r", encoding="utf-8") as f:
lines = f.readlines()
lines[5] = (
f' "-I{googlepinyinime_rev_root_path}/build/vcpkg_installed/x64-windows/include",\n'
)
with open(dot_clangd_output_file, "w", encoding="utf-8") as f:
f.writelines(lines)
#
# project_root/tests/CMakeLists.txt
#
CMakeLists_file = os.path.join(
googlepinyinime_rev_root_path, "scripts", "config_files", "CMakeLists.txt"
)
CMakeLists_output_file = os.path.join(googlepinyinime_rev_root_path, "CMakeLists.txt")
with open(CMakeLists_file, "r", encoding="utf-8") as f:
lines = f.readlines()
with open(CMakeLists_output_file, "w", encoding="utf-8") as f:
f.writelines(lines)
#
# CMakePresets.json
#
CMakePresets_file = os.path.join(
googlepinyinime_rev_root_path, "scripts", "config_files", "CMakePresets.json"
)
CMakePresets_file_output_file = os.path.join(
googlepinyinime_rev_root_path, "CMakePresets.json"
)
with open(CMakePresets_file, "r", encoding="utf-8") as f:
lines = f.readlines()
lines[8] = f' "VCPKG_ROOT": "{normpath(user_home)}/scoop/apps/vcpkg/current/"\n'
lines[11] = (
f' "CMAKE_TOOLCHAIN_FILE": "{normpath(user_home)}/scoop/apps/vcpkg/current/scripts/buildsystems/vcpkg.cmake",\n'
)
with open(CMakePresets_file_output_file, "w", encoding="utf-8") as f:
f.writelines(lines)