From 260f0cb5a31bf7be170faf6feeb52c3aeac2a33f Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Thu, 26 Dec 2024 23:19:34 +0800 Subject: [PATCH] :memo: add doc about how to build on windows --- .gitignore | 3 ++- CMakeLists.txt | 29 +++++++++++++++++------------ README.md | 2 +- doc/README_zh.md | 1 + doc/windows-build.md | 27 +++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 doc/windows-build.md diff --git a/.gitignore b/.gitignore index 7ccf091..76f7285 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ build/ out/ dist/ -cmake-build-*/ +cmake-build-* +cmake-windows-* # IDE and editor files .vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 69c03f8..40d3f42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ set(CMAKE_CXX_FLAGS_RELEASE_INIT "-Wshadow -Wall") add_compile_options(-fPIC) # MSVC needs this command option to really enable utf-8 output -if(MSVC) +if (MSVC) add_compile_options(/utf-8) endif() @@ -103,16 +103,21 @@ target_link_libraries(mat module-used-object) add_library(nasock SHARED ${CMAKE_SOURCE_DIR}/module/nasocket.cpp) target_include_directories(nasock PRIVATE ${CMAKE_SOURCE_DIR}/src) +if (WIN32) + target_link_libraries(nasock ws2_32) +endif() target_link_libraries(nasock module-used-object) -# Add web library -add_library(nasal-web SHARED - src/nasal_web.cpp - ${NASAL_OBJECT_SOURCE_FILE} -) -target_include_directories(nasal-web PRIVATE ${CMAKE_SOURCE_DIR}/src) -set_target_properties(nasal-web PROPERTIES - C_VISIBILITY_PRESET hidden - CXX_VISIBILITY_PRESET hidden - VISIBILITY_INLINES_HIDDEN ON -) +# Add web library, not for MSVC now +if (NOT MSVC) + add_library(nasal-web SHARED + src/nasal_web.cpp + ${NASAL_OBJECT_SOURCE_FILE} + ) + target_include_directories(nasal-web PRIVATE ${CMAKE_SOURCE_DIR}/src) + set_target_properties(nasal-web PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON + ) +endif() \ No newline at end of file diff --git a/README.md b/README.md index 119dbf4..bf26763 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Make sure thread model is `posix thread model`, otherwise no thread library exis ### __Windows (Visual Studio)__ -There is a [__CMakelists.txt__](./CMakeLists.txt) to create project. +There is a [__CMakelists.txt__](./CMakeLists.txt) to create project. Recently we find how to build it with command line tools: [__Build Nasal-Interpreter on Windows]__(./doc/windows-build.md). ### __Linux / macOS / Unix__ diff --git a/doc/README_zh.md b/doc/README_zh.md index b750837..ccefecb 100644 --- a/doc/README_zh.md +++ b/doc/README_zh.md @@ -81,6 +81,7 @@ Windows 平台的预览版解释器现在还没配置相关流水线, ### __Windows 平台 (Vistual Studio)__ 项目提供了 [__CMakeLists.txt__](../CMakeLists.txt) 用于在`Visual Studio`中创建项目。 +最近我们总结了命令行编译的方法 [__如何在 Windows 平台编译 Nasal-Interpreter__](./windows-build.md)。 ### __Linux / macOS / Unix 平台__ diff --git a/doc/windows-build.md b/doc/windows-build.md new file mode 100644 index 0000000..665ba49 --- /dev/null +++ b/doc/windows-build.md @@ -0,0 +1,27 @@ +# Build Nasal-Interpreter on Windows + +## MSVC / Visual Studio + +Need CMake and Visual Studio 2022. Remember to add MSBuild.exe to Path. + +Valid on powershell: + +```sh +mkdir cmake-windows-msvc +cd cmake-windows-msvc +cmake .. -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 17 2022" +MSbuild.exe nasal.sln /p:Configuration=Release /p:Platform=x64 +``` + +## MingW-W64 + +Need CMake and MingW-W64. Remember to add MingW-W64 bin to Path. + +Valid on powershell: + +```sh +mkdir cmake-windows-mingw +cd cmake-windows-mingw +cmake .. -DCMAKE_BUILD_TYPE=Release -G "MinGW Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ +mingw32-make.exe -j6 +```