Skip to content

Commit

Permalink
Fix building on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Apr 1, 2024
1 parent 7295d8f commit 12c57c4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ project(boilerplate)
set(APP_NAME "boilerplate")

# The main executable.
file(GLOB SRC_FILES "src/*.h" "src/*.cc" "src/*.rc" "src/*.xml" "src/*.ico")
file(GLOB SRC_FILES "src/*.h" "src/*.cc")
add_executable(${APP_NAME}
${SRC_FILES} "${CMAKE_CURRENT_BINARY_DIR}/encryption_key.h")
if(WIN32)
target_sources(${APP_NAME} PRIVATE "src/exe.rc" "src/exe.manifest")
endif()

# Link with Yue.
add_subdirectory(libyue)
Expand Down
18 changes: 10 additions & 8 deletions scripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

const path = require('path')

const {targetCpu, cmake, mkdir, spawnSync} = require('./common')
const {targetCpu, mkdir, spawnSync} = require('./common')

const cmake = path.resolve('node_modules', '@yogalayout', 'cmake-bin', 'bin', 'cmake')

mkdir('out')

if (process.platform == 'win32') {
process.exit(spawnSync(cmake,
['-S', '.', '-B', 'out',
'-G', 'Visual Studio 19 2022',
process.exit(spawnSync(process.execPath,
[cmake, '-S', '.', '-B', 'out',
'-G', 'Visual Studio 17 2022',
'-A', targetCpu == 'x64' ? 'x64' : 'Win32']).status)
} else {
mkdir('out/Release')
let code = spawnSync(cmake,
['-D', `CMAKE_BUILD_TYPE=Release`, '../..'],
let code = spawnSync(process.execPath,
[cmake, '-D', `CMAKE_BUILD_TYPE=Release`, '../..'],
{cwd: 'out/Release'}).status
if (code != 0)
process.exit(code)
mkdir('out/Debug')
process.exit(spawnSync(cmake,
['-D', `CMAKE_BUILD_TYPE=Debug`, '../..'],
process.exit(spawnSync(process.execPath,
[cmake, '-D', `CMAKE_BUILD_TYPE=Debug`, '../..'],
{cwd: 'out/Debug'}).status)
}
4 changes: 2 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const config = process.argv[2] ? process.argv[2] : 'Debug'

if (process.platform == 'win32') {
const vsPaths = [
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin',
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\Enterprise\\MSBuild\\Current\\Bin',
'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin',
'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\MSBuild\\Current\\Bin',
process.env.PATH
]
const env = Object.assign(process.env, {PATH: vsPaths.join(path.delimiter)})
Expand Down
6 changes: 0 additions & 6 deletions scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ const targetCpu = {
arm64: 'arm64',
}[narch]

// Find the path of cmake.
let cmake = path.resolve('node_modules', '@yogalayout', 'cmake-bin', 'bin', 'cmake')
if (process.platform == 'win')
cmake += '.exe'

// Make dir and ignore error.
function mkdir(dir) {
if (fs.existsSync(dir)) return
Expand Down Expand Up @@ -52,7 +47,6 @@ const spawnSyncWrapper = (exec, args, options = {}) => {
// Export public APIs.
module.exports = {
targetCpu,
cmake,
mkdir,
execSync: execSyncWrapper,
spawnSync: spawnSyncWrapper,
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/exe.rc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Yue"
VALUE "ProductName", "Muban"
VALUE "ProductName", "Boilerplate"
VALUE "FileDescription", "Build cross-platform desktop apps"
VALUE "OriginalFilename", "muban.exe"
VALUE "InternalName", "muban"
VALUE "OriginalFilename", "boilerplate.exe"
VALUE "InternalName", "boilerplate"
VALUE "LegalCopyright", "Public domain"
END
END
Expand Down

0 comments on commit 12c57c4

Please sign in to comment.