@@ -26,18 +26,19 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2626# Include cmake-js
2727if (CMAKE_JS_INC)
2828 include_directories (${CMAKE_JS_INC} )
29- endif ()
30-
31- # Add Node.js include path
32- execute_process (
33- COMMAND node -p "require('path').dirname(process.execPath) + '/../include/node'"
34- OUTPUT_VARIABLE NODE_INCLUDE_DIR
35- OUTPUT_STRIP_TRAILING_WHITESPACE
36- ERROR_QUIET
37- )
38- if (NODE_INCLUDE_DIR AND EXISTS "${NODE_INCLUDE_DIR} " )
39- include_directories (${NODE_INCLUDE_DIR} )
40- message (STATUS "Node.js include directory: ${NODE_INCLUDE_DIR} " )
29+ message (STATUS "Using cmake-js include directory: ${CMAKE_JS_INC} " )
30+ else ()
31+ # Fallback: Add Node.js include path if cmake-js is not used
32+ execute_process (
33+ COMMAND node -p "require('path').dirname(process.execPath) + '/../include/node'"
34+ OUTPUT_VARIABLE NODE_INCLUDE_DIR
35+ OUTPUT_STRIP_TRAILING_WHITESPACE
36+ ERROR_QUIET
37+ )
38+ if (NODE_INCLUDE_DIR AND EXISTS "${NODE_INCLUDE_DIR} " )
39+ include_directories (${NODE_INCLUDE_DIR} )
40+ message (STATUS "Node.js include directory: ${NODE_INCLUDE_DIR} " )
41+ endif ()
4142endif ()
4243
4344# ==================== 平台特定编译选项 ====================
@@ -90,28 +91,27 @@ endif()
9091
9192# ==================== 依赖库查找 ====================
9293
93- # Boost (header-only)
94- if (WIN32 AND NOT MSVC )
95- # MinGW: 尝试find_package和手动查找
96- find_package (Boost QUIET )
97- if (NOT Boost_FOUND)
98- find_path (Boost_INCLUDE_DIRS
99- NAMES boost/version.hpp
100- PATHS /mingw64/include C:/msys64/mingw64/include
101- NO_DEFAULT_PATH
102- )
103- if (Boost_INCLUDE_DIRS)
104- message (STATUS "Found Boost headers: ${Boost_INCLUDE_DIRS} " )
105- set (Boost_FOUND TRUE )
106- endif ()
107- endif ()
108- else ()
109- # 其他平台
110- find_package (Boost REQUIRED )
111- endif ()
112-
11394# pkg-config 和 FFTW3(仅在构建库时需要)
11495if (WSJTX_BUILD_LIBS)
96+ # Boost (header-only) - 仅在构建wsjtx_lib时需要
97+ if (WIN32 AND NOT MSVC )
98+ # MinGW: 尝试find_package和手动查找
99+ find_package (Boost QUIET )
100+ if (NOT Boost_FOUND)
101+ find_path (Boost_INCLUDE_DIRS
102+ NAMES boost/version.hpp
103+ PATHS /mingw64/include C:/msys64/mingw64/include
104+ NO_DEFAULT_PATH
105+ )
106+ if (Boost_INCLUDE_DIRS)
107+ message (STATUS "Found Boost headers: ${Boost_INCLUDE_DIRS} " )
108+ set (Boost_FOUND TRUE )
109+ endif ()
110+ endif ()
111+ else ()
112+ # 其他平台
113+ find_package (Boost REQUIRED )
114+ endif ()
115115 find_package (PkgConfig REQUIRED )
116116 pkg_check_modules (FFTW3F REQUIRED fftw3f )
117117
@@ -172,16 +172,22 @@ if(NOT NODE_ADDON_API_PATH)
172172 message (FATAL_ERROR "Could not find node-addon-api" )
173173endif ()
174174
175- # Include directories
175+ # Include directories (base paths needed by all targets)
176176include_directories (
177177 ${CMAKE_SOURCE_DIR} /wsjtx_lib
178178 ${CMAKE_SOURCE_DIR} /wsjtx_bridge
179179 ${CMAKE_SOURCE_DIR} /native
180180 ${NODE_ADDON_API_PATH}
181- ${FFTW3F_INCLUDE_DIRS}
182- ${Boost_INCLUDE_DIRS}
183181)
184182
183+ # Only add FFTW and Boost includes when building libs
184+ if (WSJTX_BUILD_LIBS)
185+ include_directories (
186+ ${FFTW3F_INCLUDE_DIRS}
187+ ${Boost_INCLUDE_DIRS}
188+ )
189+ endif ()
190+
185191# ==================== 库依赖定义 ====================
186192
187193set (LIBRARIES_FROM_REFERENCES
@@ -360,10 +366,10 @@ if(WSJTX_BUILD_NODE_ADDON)
360366 target_link_libraries (${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB} )
361367 endif ()
362368
363- # 链接库(仅链接Boost,运行时动态加载wsjtx_bridge )
364- target_link_libraries ( ${PROJECT_NAME} PRIVATE
365- ${ BOOST_LIBRARIES}
366- )
369+ # 链接Boost(仅在构建wsjtx_lib时需要,MSVC模式下不需要 )
370+ if (WSJTX_BUILD_LIBS AND BOOST_LIBRARIES)
371+ target_link_libraries ( ${PROJECT_NAME} PRIVATE ${ BOOST_LIBRARIES})
372+ endif ( )
367373
368374 message (STATUS ".node extension will dynamically load wsjtx_bridge at runtime" )
369375 message (STATUS "Build complete: wsjtx_lib (static) -> wsjtx_bridge (dynamic) -> .node (loads bridge)" )
0 commit comments