11cmake_minimum_required (VERSION 3.15)
2- project (wsjtx_lib_nodejs)
2+
3+ # 禁用 vcpkg Manifest 模式,使用经典模式
4+ if (DEFINED CMAKE_TOOLCHAIN_FILE AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg" )
5+ set (VCPKG_MANIFEST_MODE OFF CACHE BOOL "Disable vcpkg manifest mode" FORCE)
6+ set (VCPKG_MANIFEST_INSTALL OFF CACHE BOOL "Disable vcpkg manifest install" FORCE)
7+ message (STATUS "Detected vcpkg toolchain, disabling manifest mode" )
8+ endif ()
9+
10+ project (wsjtx_lib_nodejs LANGUAGES C CXX Fortran)
11+
12+ # Use MSVC on Windows by default, else keep existing
13+ if (MSVC )
14+ message (STATUS "Using MSVC toolchain on Windows" )
15+ # Enable Fortran support via Intel oneAPI if available
16+ # vcpkg toolchain file should be passed to CMake invocation
17+ endif ()
318
419# Set C++ standard
520set (CMAKE_CXX_STANDARD 17)
@@ -38,7 +53,9 @@ elseif(APPLE)
3853endif ()
3954
4055# Include cmake-js
41- include_directories (${CMAKE_JS_INC} )
56+ if (CMAKE_JS_INC)
57+ include_directories (${CMAKE_JS_INC} )
58+ endif ()
4259
4360# Add Node.js include path for node_api.h
4461execute_process (
@@ -49,7 +66,30 @@ execute_process(
4966include_directories (${NODE_INCLUDE_DIR} )
5067
5168# Platform-specific package finding
52- if (WIN32 )
69+ if (WIN32 AND MSVC )
70+ # Windows with MSVC: Use vcpkg for FFTW3
71+ find_package (FFTW3F CONFIG REQUIRED)
72+ find_package (FFTW3 CONFIG REQUIRED)
73+
74+ # Set CMake policy for newer Boost versions
75+ if (POLICY CMP0167)
76+ cmake_policy (SET CMP0167 NEW)
77+ endif ()
78+
79+ # Find Boost
80+ find_package (Boost QUIET )
81+ if (Boost_FOUND)
82+ message (STATUS "Boost found: ${Boost_VERSION} " )
83+ set (BOOST_LIBRARIES ${Boost_LIBRARIES} )
84+ else ()
85+ message (WARNING "Boost not found via find_package, continuing..." )
86+ set (BOOST_LIBRARIES "" )
87+ endif ()
88+
89+ # MSVC doesn't need separate threads library for FFTW
90+ set (FFTW_HAS_THREADS FALSE )
91+ set (FFTW_THREADS_LIBRARIES "" )
92+ elseif (WIN32 )
5393 # Windows with MSYS2: Use pkg-config like Unix systems
5494 find_package (PkgConfig REQUIRED)
5595
@@ -111,19 +151,34 @@ else()
111151endif ()
112152
113153# Include directories
114- include_directories (
115- ${CMAKE_SOURCE_DIR} /wsjtx_lib
116- ${CMAKE_SOURCE_DIR} /native
117- ${CMAKE_SOURCE_DIR} /node_modules/node-addon-api
118- ${FFTW3F_INCLUDE_DIRS}
119- ${Boost_INCLUDE_DIRS}
120- )
154+ if (WIN32 AND MSVC )
155+ include_directories (
156+ ${CMAKE_SOURCE_DIR} /wsjtx_lib
157+ ${CMAKE_SOURCE_DIR} /native
158+ ${CMAKE_SOURCE_DIR} /node_modules/node-addon-api
159+ )
160+ else ()
161+ include_directories (
162+ ${CMAKE_SOURCE_DIR} /wsjtx_lib
163+ ${CMAKE_SOURCE_DIR} /native
164+ ${CMAKE_SOURCE_DIR} /node_modules/node-addon-api
165+ ${FFTW3F_INCLUDE_DIRS}
166+ ${Boost_INCLUDE_DIRS}
167+ )
168+ endif ()
121169
122170# Define LIBRARIES_FROM_REFERENCES for wsjtx_lib submodule
123- set (LIBRARIES_FROM_REFERENCES
124- ${FFTW3F_LIBRARIES}
125- ${FFTW_THREADS_LIBRARIES}
126- )
171+ if (WIN32 AND MSVC )
172+ set (LIBRARIES_FROM_REFERENCES
173+ FFTW3F::fftw3f
174+ FFTW3::fftw3
175+ )
176+ else ()
177+ set (LIBRARIES_FROM_REFERENCES
178+ ${FFTW3F_LIBRARIES}
179+ ${FFTW_THREADS_LIBRARIES}
180+ )
181+ endif ()
127182
128183# Platform-specific library setup
129184if (APPLE )
@@ -150,10 +205,7 @@ if(APPLE)
150205 if (GFORTRAN_EXECUTABLE)
151206 message (STATUS "Found gfortran: ${GFORTRAN_EXECUTABLE} " )
152207
153- # Set the Fortran compiler for the project
154- set (CMAKE_Fortran_COMPILER ${GFORTRAN_EXECUTABLE} )
155-
156- # Get library path
208+ # Get library path (but don't set CMAKE_Fortran_COMPILER here to avoid cache conflicts)
157209 execute_process (
158210 COMMAND ${GFORTRAN_EXECUTABLE} --print-file-name =libgfortran.dylib
159211 OUTPUT_VARIABLE GFORTRAN_LIB_PATH
@@ -203,7 +255,7 @@ elseif(UNIX)
203255 if (FFTW_HAS_THREADS)
204256 list (APPEND LIBRARIES_FROM_REFERENCES fftw3f_threads)
205257 endif ()
206- elseif (WIN32 )
258+ elseif (WIN32 AND NOT MSVC )
207259 # Windows specific libraries - MSYS2/MinGW environment
208260 list (APPEND LIBRARIES_FROM_REFERENCES
209261 gfortran
@@ -216,8 +268,10 @@ endif()
216268add_subdirectory (wsjtx_lib)
217269
218270# Link directories (must be before creating target)
219- if (NOT WIN32 )
220- link_directories (${FFTW3F_LIBRARY_DIRS} )
271+ if (NOT WIN32 OR NOT MSVC )
272+ if (NOT WIN32 )
273+ link_directories (${FFTW3F_LIBRARY_DIRS} )
274+ endif ()
221275endif ()
222276
223277# Source files for the Node.js addon
@@ -231,7 +285,7 @@ if(MINGW)
231285 # Exclude CMAKE_JS_SRC for MinGW
232286 )
233287else ()
234- # For other platforms (or if not MINGW, though cmake-js might handle this differently )
288+ # For other platforms (MSVC, Linux, macOS )
235289 add_library (${PROJECT_NAME} SHARED
236290 ${NATIVE_SOURCES}
237291 ${CMAKE_JS_SRC}
@@ -247,7 +301,9 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
247301)
248302
249303# Set Node.js addon include directories
250- target_include_directories (${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} )
304+ if (CMAKE_JS_INC)
305+ target_include_directories (${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} )
306+ endif ()
251307
252308# Compiler-specific options
253309target_compile_definitions (${PROJECT_NAME} PRIVATE
@@ -256,8 +312,10 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
256312)
257313
258314# Add compile flags
259- if (NOT WIN32 )
260- target_compile_options (${PROJECT_NAME} PRIVATE ${FFTW3F_CFLAGS_OTHER} )
315+ if (NOT WIN32 OR NOT MSVC )
316+ if (NOT WIN32 )
317+ target_compile_options (${PROJECT_NAME} PRIVATE ${FFTW3F_CFLAGS_OTHER} )
318+ endif ()
261319endif ()
262320
263321# Link libraries
@@ -267,6 +325,17 @@ if(MINGW)
267325 wsjtx_lib
268326 # Potentially add -lnode or the path to libnode.dll.a if needed
269327 )
328+ elseif (WIN32 AND MSVC )
329+ # MSVC linking
330+ if (CMAKE_JS_LIB)
331+ target_link_libraries (${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB} )
332+ endif ()
333+ target_link_libraries (${PROJECT_NAME} PRIVATE
334+ wsjtx_lib
335+ FFTW3F::fftw3f
336+ FFTW3::fftw3
337+ ${BOOST_LIBRARIES}
338+ )
270339else ()
271340 target_link_libraries (${PROJECT_NAME}
272341 ${CMAKE_JS_LIB}
@@ -304,7 +373,7 @@ elseif(UNIX)
304373 target_link_options (${PROJECT_NAME} PRIVATE
305374 -Wl,--as-needed
306375 )
307- elseif (WIN32 )
376+ elseif (WIN32 AND NOT MSVC )
308377 # Windows linking - MSYS2/MinGW environment
309378 target_link_libraries (${PROJECT_NAME}
310379 ${FFTW3F_LIBRARIES}
0 commit comments