@@ -14,19 +14,17 @@ elseif (MSVC)
1414endif ()
1515
1616# ============================
17- # Output directories
18- # ============================
19- set (CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR } /build)
20- set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } )
21- set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } )
22- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR } )
23-
24- # ============================
25- # Precision options (scalar only)
17+ # Options
2618# ============================
2719option (NEXT_FP32 "Use 32-bit floats (scalar)" OFF )
2820option (NEXT_FP64 "Use 64-bit floats (scalar)" ON )
2921
22+ # Option: copy final executable to source dir
23+ option (NEXT_COPY_TO_CMAKE_SOURCE_DIR "Copy final executable from build dir to source dir" ON )
24+
25+ # ============================
26+ # Precision modes
27+ # ============================
3028set (NEXT_MODES
3129 NEXT_FP32
3230 NEXT_FP64
@@ -47,9 +45,7 @@ elseif(NEXT_MODE_COUNT GREATER 1)
4745 message (FATAL_ERROR "Enable only one precision mode." )
4846endif ()
4947
50- # ============================
5148# Apply compile definitions
52- # ============================
5349if (NEXT_FP32)
5450 add_compile_definitions (NEXT_FP32 )
5551elseif (NEXT_FP64)
@@ -69,7 +65,7 @@ add_executable(next ${SRC_FILES} ${ARGPARSE_FILES})
6965# ============================
7066# OpenMP
7167# ============================
72- find_package (OpenMP QUIET )
68+ find_package (OpenMP QUIET )
7369if (OpenMP_CXX_FOUND)
7470 message (STATUS "OpenMP detected — enabling multithreading." )
7571 target_link_libraries (next PRIVATE OpenMP::OpenMP_CXX )
@@ -80,7 +76,6 @@ endif()
8076# ============================
8177# HDF5 detection
8278# ============================
83-
8479# MSVC: use vcpkg or prebuilt binaries
8580if (USING_MSVC AND DEFINED ENV{HDF5_DIR})
8681 set (HDF5_ROOT "$ENV{HDF5_DIR} " )
@@ -98,3 +93,14 @@ find_package(HDF5 REQUIRED COMPONENTS C HL)
9893include_directories (${HDF5_INCLUDE_DIRS} )
9994target_link_libraries (next PRIVATE ${HDF5_LIBRARIES} )
10095
96+ # ============================
97+ # Optional: Copy executable to source dir
98+ # ============================
99+ if (NEXT_COPY_TO_CMAKE_SOURCE_DIR )
100+ add_custom_command (TARGET next POST_BUILD
101+ COMMAND ${CMAKE_COMMAND } -E copy
102+ $<TARGET_FILE :next >
103+ ${CMAKE_SOURCE_DIR } /$<TARGET_FILE_NAME:next>
104+ COMMENT "Copying executable to CMake source directory"
105+ )
106+ endif ()
0 commit comments