@@ -10,34 +10,67 @@ endif()
1010project (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 ()
4275endif ()
4376
@@ -79,7 +112,7 @@ endif()
79112
80113# Include cmake-js
81114if (CMAKE_JS_INC)
82- include_directories (${CMAKE_JS_INC} )
115+ include_directories (${CMAKE_JS_INC} )
83116endif ()
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
94127if (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 )
184228else ()
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+ )
192236endif ()
193237
194238# Define LIBRARIES_FROM_REFERENCES for wsjtx_lib submodule
195239if (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 )
199252else ()
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+ )
204257endif ()
205258
206259# Platform-specific library setup
@@ -292,8 +345,8 @@ add_subdirectory(wsjtx_lib)
292345
293346# Link directories (must be before creating target)
294347if (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 ()
298351endif ()
299352
@@ -325,7 +378,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
325378
326379# Set Node.js addon include directories
327380if (CMAKE_JS_INC)
328- target_include_directories (${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} )
381+ target_include_directories (${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC} )
329382endif ()
330383
331384# Compiler-specific options
@@ -336,8 +389,8 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
336389
337390# Add compile flags
338391if (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 ()
342395endif ()
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 )
361424else ()
0 commit comments