Skip to content

Commit ff9df09

Browse files
committed
ci fix3
1 parent dc840fc commit ff9df09

File tree

5 files changed

+276
-122
lines changed

5 files changed

+276
-122
lines changed

.github/workflows/build.yml

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
run: |
135135
git clone https://github.com/Microsoft/vcpkg.git
136136
.\vcpkg\bootstrap-vcpkg.bat
137-
.\vcpkg\vcpkg install fftw3:x64-windows boost:x64-windows
137+
.\vcpkg\vcpkg install fftw3[core]:x64-windows boost:x64-windows
138138
shell: cmd
139139

140140
- name: Setup Intel Fortran
@@ -148,28 +148,22 @@ jobs:
148148
if: runner.os == 'Windows'
149149
run: |
150150
echo "=== Verifying Intel Fortran installation ==="
151-
echo "PATH: %PATH%"
152151
echo "Checking for ifort..."
153152
where ifort || echo "ifort not found in PATH"
154153
echo "Checking for ifx..."
155154
where ifx || echo "ifx not found in PATH"
156155
157-
echo "Trying to run ifort (Windows style)..."
158-
ifort /help | findstr "Intel" || echo "ifort help failed"
159-
echo "Trying to run ifx (Windows style)..."
160-
ifx /help | findstr "Intel" || echo "ifx help failed"
161-
162-
echo "Setting environment variables..."
156+
echo "Setting up Intel oneAPI environment..."
163157
if exist "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" (
164-
echo "Found Intel oneAPI setvars.bat"
158+
echo "Calling Intel oneAPI setvars.bat..."
165159
call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
166160
) else (
167161
echo "Intel oneAPI setvars.bat not found"
168162
)
169163
170-
echo "Re-checking after setvars..."
171-
where ifort && echo "ifort found" || echo "ifort still not found"
172-
where ifx && echo "ifx found" || echo "ifx still not found"
164+
echo "Final check - Fortran compilers available:"
165+
where ifort && echo "ifort ready" || echo "ifort not available"
166+
where ifx && echo "ifx ready" || echo "ifx not available"
173167
shell: cmd
174168

175169
# 4. 安装 npm 依赖
@@ -212,20 +206,51 @@ jobs:
212206
call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
213207
)
214208
215-
echo "Verifying Fortran compiler after environment setup..."
209+
echo "Setting up MSVC environment..."
210+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
211+
212+
echo "Verifying compilers after environment setup..."
213+
where cl && echo "MSVC cl available" || echo "MSVC cl not available"
216214
where ifort && echo "ifort available" || echo "ifort not available"
217215
where ifx && echo "ifx available" || echo "ifx not available"
218216
219217
echo "Cleaning build directory..."
220218
rmdir /s /q build 2>nul || echo "No build directory to clean"
221219
222-
echo "Starting cmake-js compilation..."
223-
set IFORT_PATH=C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\bin\intel64\ifort.exe
220+
echo "Starting cmake-js compilation with NMake..."
221+
set "IFORT_PATH=C:/Program Files (x86)/Intel/oneAPI/compiler/latest/windows/bin/intel64/ifort.exe"
222+
223+
echo "Finding MSVC cl.exe..."
224+
for /f "delims=" %%i in ('where cl') do set "MSVC_CL_PATH=%%i"
225+
echo "Found MSVC cl.exe at: %MSVC_CL_PATH%"
226+
227+
echo "Temporarily renaming Node.js rc to avoid conflicts..."
228+
if exist "node_modules\.bin\rc.exe" (
229+
ren "node_modules\.bin\rc.exe" "rc.exe.bak"
230+
echo "Renamed node_modules\.bin\rc.exe to rc.exe.bak"
231+
)
232+
if exist "node_modules\.bin\rc" (
233+
ren "node_modules\.bin\rc" "rc.bak"
234+
echo "Renamed node_modules\.bin\rc to rc.bak"
235+
)
236+
224237
npx cmake-js compile --arch=${{ matrix.cmake_arch }} ^
225-
-G "Visual Studio 17 2022" -A x64 ^
226-
--CDCMAKE_TOOLCHAIN_FILE=vcpkg\scripts\buildsystems\vcpkg.cmake ^
238+
-G "NMake Makefiles" ^
239+
--CDCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake ^
240+
--CDCMAKE_C_COMPILER="%MSVC_CL_PATH%" ^
241+
--CDCMAKE_CXX_COMPILER="%MSVC_CL_PATH%" ^
227242
--CDCMAKE_Fortran_COMPILER="%IFORT_PATH%" ^
228243
--verbose
244+
245+
echo "Restoring Node.js rc tools..."
246+
if exist "node_modules\.bin\rc.exe.bak" (
247+
ren "node_modules\.bin\rc.exe.bak" "rc.exe"
248+
echo "Restored node_modules\.bin\rc.exe"
249+
)
250+
if exist "node_modules\.bin\rc.bak" (
251+
ren "node_modules\.bin\rc.bak" "rc"
252+
echo "Restored node_modules\.bin\rc"
253+
)
229254
shell: cmd
230255

231256
# 7. 运行测试

CMakeLists.txt

Lines changed: 100 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,67 @@ endif()
1010
project(wsjtx_lib_nodejs LANGUAGES C CXX Fortran)
1111

1212
# 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
13+
if(WIN32)
14+
message(STATUS "Windows platform detected")
1715

18-
# Try to find Intel Fortran compiler
16+
# Force use of MSVC compilers for C/C++, Intel for Fortran only
17+
if(NOT CMAKE_C_COMPILER)
18+
find_program(MSVC_C_COMPILER
19+
NAMES cl.exe
20+
PATHS
21+
"C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/*/bin/Hostx64/x64"
22+
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/*/bin/Hostx64/x64"
23+
"C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/*/bin/Hostx64/x64"
24+
"C:/Program Files (x86)/Microsoft Visual Studio/*/VC/Tools/MSVC/*/bin/Hostx64/x64"
25+
DOC "MSVC C Compiler"
26+
)
27+
if(MSVC_C_COMPILER)
28+
set(CMAKE_C_COMPILER ${MSVC_C_COMPILER} CACHE FILEPATH "C compiler" FORCE)
29+
message(STATUS "Found MSVC C compiler: ${MSVC_C_COMPILER}")
30+
endif()
31+
endif()
32+
33+
if(NOT CMAKE_CXX_COMPILER)
34+
find_program(MSVC_CXX_COMPILER
35+
NAMES cl.exe
36+
PATHS
37+
"C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/*/bin/Hostx64/x64"
38+
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/*/bin/Hostx64/x64"
39+
"C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/*/bin/Hostx64/x64"
40+
"C:/Program Files (x86)/Microsoft Visual Studio/*/VC/Tools/MSVC/*/bin/Hostx64/x64"
41+
DOC "MSVC CXX Compiler"
42+
)
43+
if(MSVC_CXX_COMPILER)
44+
set(CMAKE_CXX_COMPILER ${MSVC_CXX_COMPILER} CACHE FILEPATH "CXX compiler" FORCE)
45+
message(STATUS "Found MSVC C++ compiler: ${MSVC_CXX_COMPILER}")
46+
endif()
47+
endif()
48+
49+
# Intel Fortran compiler should be available in PATH after setvars.bat
50+
# Let CMake find it automatically if not explicitly set
1951
if(NOT CMAKE_Fortran_COMPILER)
20-
find_program(IFORT_EXECUTABLE
21-
NAMES ifort.exe ifx.exe ifort ifx
22-
PATHS
52+
message(STATUS "CMAKE_Fortran_COMPILER not set, trying to find Intel Fortran compiler")
53+
54+
# Try to find Intel Fortran compiler in common locations
55+
find_program(INTEL_FORTRAN_COMPILER
56+
NAMES ifort.exe ifort ifx.exe ifx
57+
PATHS
2358
"C:/Program Files (x86)/Intel/oneAPI/compiler/latest/windows/bin/intel64"
2459
"C:/Program Files (x86)/Intel/oneAPI/compiler/latest/windows/bin"
2560
"C:/Program Files/Intel/oneAPI/compiler/latest/windows/bin/intel64"
2661
"C:/Program Files/Intel/oneAPI/compiler/latest/windows/bin"
27-
"C:/Program Files (x86)/Intel/oneAPI/compiler/2023.2.0/windows/bin/intel64"
28-
"C:/Program Files (x86)/Intel/oneAPI/compiler/2023.2.0/windows/bin"
29-
"C:/Program Files (x86)/Intel/oneAPI/compiler/2021.10.0/windows/bin/intel64"
30-
"C:/Program Files (x86)/Intel/oneAPI/compiler/2021.10.0/windows/bin"
3162
DOC "Intel Fortran Compiler"
3263
)
3364

34-
if(IFORT_EXECUTABLE)
35-
message(STATUS "Found Intel Fortran compiler: ${IFORT_EXECUTABLE}")
36-
set(CMAKE_Fortran_COMPILER ${IFORT_EXECUTABLE} CACHE FILEPATH "Fortran compiler" FORCE)
65+
if(INTEL_FORTRAN_COMPILER)
66+
message(STATUS "Found Intel Fortran compiler: ${INTEL_FORTRAN_COMPILER}")
67+
set(CMAKE_Fortran_COMPILER ${INTEL_FORTRAN_COMPILER} CACHE FILEPATH "Fortran compiler" FORCE)
3768
else()
38-
message(WARNING "Intel Fortran compiler not found. Fortran compilation may fail.")
39-
message(STATUS "Please ensure Intel oneAPI HPC Toolkit is installed and setvars.bat has been called.")
69+
message(WARNING "Intel Fortran compiler not found automatically")
70+
message(STATUS "Please ensure Intel oneAPI HPC Toolkit is installed and CMAKE_Fortran_COMPILER is set")
4071
endif()
72+
else()
73+
message(STATUS "Using specified Fortran compiler: ${CMAKE_Fortran_COMPILER}")
4174
endif()
4275
endif()
4376

@@ -79,7 +112,7 @@ endif()
79112

80113
# Include cmake-js
81114
if(CMAKE_JS_INC)
82-
include_directories(${CMAKE_JS_INC})
115+
include_directories(${CMAKE_JS_INC})
83116
endif()
84117

85118
# Add Node.js include path for node_api.h
@@ -93,7 +126,18 @@ include_directories(${NODE_INCLUDE_DIR})
93126
# Platform-specific package finding
94127
if(WIN32 AND MSVC)
95128
# Windows with MSVC: Use vcpkg for FFTW3
96-
find_package(FFTW3 CONFIG REQUIRED)
129+
# Try to find FFTW3 package with lowercase name first
130+
find_package(fftw3 CONFIG REQUIRED)
131+
if(TARGET fftw3::fftw3)
132+
message(STATUS "Found FFTW3 (as fftw3::fftw3)")
133+
# Create alias for consistency if needed
134+
if(NOT TARGET FFTW3::fftw3)
135+
add_library(FFTW3::fftw3 ALIAS fftw3::fftw3)
136+
endif()
137+
set(FFTW3_FOUND TRUE)
138+
else()
139+
message(FATAL_ERROR "FFTW3 not found. Please install via vcpkg: vcpkg install fftw3[core]:x64-windows")
140+
endif()
97141

98142
# Set CMake policy for newer Boost versions
99143
if(POLICY CMP0167)
@@ -182,25 +226,34 @@ if(WIN32 AND MSVC)
182226
${CMAKE_SOURCE_DIR}/node_modules/node-addon-api
183227
)
184228
else()
185-
include_directories(
186-
${CMAKE_SOURCE_DIR}/wsjtx_lib
187-
${CMAKE_SOURCE_DIR}/native
188-
${CMAKE_SOURCE_DIR}/node_modules/node-addon-api
189-
${FFTW3F_INCLUDE_DIRS}
190-
${Boost_INCLUDE_DIRS}
191-
)
229+
include_directories(
230+
${CMAKE_SOURCE_DIR}/wsjtx_lib
231+
${CMAKE_SOURCE_DIR}/native
232+
${CMAKE_SOURCE_DIR}/node_modules/node-addon-api
233+
${FFTW3F_INCLUDE_DIRS}
234+
${Boost_INCLUDE_DIRS}
235+
)
192236
endif()
193237

194238
# Define LIBRARIES_FROM_REFERENCES for wsjtx_lib submodule
195239
if(WIN32 AND MSVC)
240+
# Determine the correct FFTW3 target name for wsjtx_lib
241+
if(TARGET FFTW3::fftw3)
242+
set(FFTW3_LIB_TARGET FFTW3::fftw3)
243+
elseif(TARGET fftw3::fftw3)
244+
set(FFTW3_LIB_TARGET fftw3::fftw3)
245+
else()
246+
message(FATAL_ERROR "No valid FFTW3 target found for wsjtx_lib")
247+
endif()
248+
196249
set(LIBRARIES_FROM_REFERENCES
197-
FFTW3::fftw3
250+
${FFTW3_LIB_TARGET}
198251
)
199252
else()
200-
set(LIBRARIES_FROM_REFERENCES
201-
${FFTW3F_LIBRARIES}
202-
${FFTW_THREADS_LIBRARIES}
203-
)
253+
set(LIBRARIES_FROM_REFERENCES
254+
${FFTW3F_LIBRARIES}
255+
${FFTW_THREADS_LIBRARIES}
256+
)
204257
endif()
205258

206259
# Platform-specific library setup
@@ -292,8 +345,8 @@ add_subdirectory(wsjtx_lib)
292345

293346
# Link directories (must be before creating target)
294347
if(NOT WIN32 OR NOT MSVC)
295-
if(NOT WIN32)
296-
link_directories(${FFTW3F_LIBRARY_DIRS})
348+
if(NOT WIN32)
349+
link_directories(${FFTW3F_LIBRARY_DIRS})
297350
endif()
298351
endif()
299352

@@ -325,7 +378,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
325378

326379
# Set Node.js addon include directories
327380
if(CMAKE_JS_INC)
328-
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
381+
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
329382
endif()
330383

331384
# Compiler-specific options
@@ -336,8 +389,8 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
336389

337390
# Add compile flags
338391
if(NOT WIN32 OR NOT MSVC)
339-
if(NOT WIN32)
340-
target_compile_options(${PROJECT_NAME} PRIVATE ${FFTW3F_CFLAGS_OTHER})
392+
if(NOT WIN32)
393+
target_compile_options(${PROJECT_NAME} PRIVATE ${FFTW3F_CFLAGS_OTHER})
341394
endif()
342395
endif()
343396

@@ -353,9 +406,19 @@ elseif(WIN32 AND MSVC)
353406
if(CMAKE_JS_LIB)
354407
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB})
355408
endif()
409+
410+
# Determine the correct FFTW3 target name
411+
if(TARGET FFTW3::fftw3)
412+
set(FFTW3_TARGET FFTW3::fftw3)
413+
elseif(TARGET fftw3::fftw3)
414+
set(FFTW3_TARGET fftw3::fftw3)
415+
else()
416+
message(FATAL_ERROR "No valid FFTW3 target found")
417+
endif()
418+
356419
target_link_libraries(${PROJECT_NAME} PRIVATE
357420
wsjtx_lib
358-
FFTW3::fftw3
421+
${FFTW3_TARGET}
359422
${BOOST_LIBRARIES}
360423
)
361424
else()

0 commit comments

Comments
 (0)