@@ -414,57 +414,102 @@ if (LLAMA_HIPBLAS)
414
414
endif ()
415
415
endif ()
416
416
417
+ function (get_flags CCID CCVER )
418
+ set (C_FLAGS "" )
419
+ set (CXX_FLAGS "" )
420
+
421
+ if (CCID MATCHES "Clang" )
422
+ set (C_FLAGS -Wunreachable-code-break -Wunreachable-code-return )
423
+ set (CXX_FLAGS -Wunreachable-code-break -Wunreachable-code-return -Wmissing-prototypes -Wextra-semi )
424
+
425
+ if (
426
+ (CCID STREQUAL "Clang" AND CCVER VERSION_GREATER_EQUAL 3.8.0 ) OR
427
+ (CCID STREQUAL "AppleClang" AND CCVER VERSION_GREATER_EQUAL 7.3.0 )
428
+ )
429
+ set (C_FLAGS ${C_FLAGS} -Wdouble-promotion )
430
+ endif ()
431
+ elseif (CCID STREQUAL "GNU" )
432
+ set (C_FLAGS -Wdouble-promotion )
433
+ set (CXX_FLAGS -Wno-array-bounds )
434
+
435
+ if (CCVER VERSION_GREATER_EQUAL 7.1.0 )
436
+ set (CXX_FLAGS ${CXX_FLAGS} -Wno-format-truncation )
437
+ endif ()
438
+ if (CCVER VERSION_GREATER_EQUAL 8.1.0 )
439
+ set (CXX_FLAGS ${CXX_FLAGS} -Wextra-semi )
440
+ endif ()
441
+ endif ()
442
+
443
+ set (GF_C_FLAGS ${C_FLAGS} PARENT_SCOPE )
444
+ set (GF_CXX_FLAGS ${CXX_FLAGS} PARENT_SCOPE )
445
+ endfunction ()
446
+
417
447
if (LLAMA_ALL_WARNINGS )
418
448
if (NOT MSVC )
419
- set (warning_flags -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function )
420
- set (c_flags -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int -Werror=implicit-function-declaration )
421
- set (cxx_flags -Wmissing-declarations -Wmissing-noreturn )
422
- set (host_cxx_flags "" )
423
-
424
- if (CMAKE_C_COMPILER_ID MATCHES "Clang" )
425
- set (warning_flags ${warning_flags} -Wunreachable-code-break -Wunreachable-code-return )
426
- set (host_cxx_flags ${host_cxx_flags} -Wmissing-prototypes -Wextra-semi )
427
-
428
- if (
429
- (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.8.0 ) OR
430
- (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3.0 )
431
- )
432
- set (c_flags ${c_flags} -Wdouble-promotion )
433
- endif ()
434
- elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" )
435
- set (c_flags ${c_flags} -Wdouble-promotion )
436
- set (host_cxx_flags ${host_cxx_flags} -Wno-array-bounds )
449
+ set (WARNING_FLAGS -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function )
450
+ set (C_FLAGS -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes
451
+ -Werror=implicit-int -Werror=implicit-function-declaration )
452
+ set (CXX_FLAGS -Wmissing-declarations -Wmissing-noreturn )
437
453
438
- if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.1.0 )
439
- set (host_cxx_flags ${host_cxx_flags} -Wno-format-truncation )
440
- endif ()
441
- if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1.0 )
442
- set ( host_cxx_flags ${host_cxx_flags} -Wextra-semi )
443
- endif ()
444
- endif ( )
454
+ set ( C_FLAGS ${WARNING_FLAGS} ${C_FLAGS} )
455
+ set (CXX_FLAGS ${WARNING_FLAGS} ${CXX_FLAGS} )
456
+
457
+ get_flags ( ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} )
458
+
459
+ add_compile_options ( "$<$<COMPILE_LANGUAGE:C>: ${C_FLAGS} ; ${GF_C_FLAGS} >"
460
+ "$<$<COMPILE_LANGUAGE:CXX>: ${CXX_FLAGS} ; ${GF_CXX_FLAGS} >" )
445
461
else ()
446
462
# todo : msvc
463
+ set (C_FLAGS "" )
464
+ set (CXX_FLAGS "" )
447
465
endif ()
466
+ endif ()
448
467
449
- set ( c_flags ${c_flags} ${warning_flags} )
450
- set (cxx_flags ${cxx_flags} ${warning_flags} )
451
- add_compile_options ( "$<$<COMPILE_LANGUAGE:C>: ${c_flags} >"
452
- "$<$<COMPILE_LANGUAGE:CXX>: ${cxx_flags} >"
453
- "$<$<COMPILE_LANGUAGE:CXX>: ${host_cxx_flags} >" )
468
+ if ( LLAMA_CUBLAS )
469
+ set (CUDA_FLAGS ${CXX_FLAGS} -use_fast_math )
470
+ if ( NOT MSVC )
471
+ set ( CUDA_FLAGS ${CUDA_FLAGS} -Wno-pedantic )
472
+ endif ( )
454
473
455
- endif ()
474
+ if (LLAMA_ALL_WARNINGS AND NOT MSVC )
475
+ set (NVCC_CMD ${CMAKE_CUDA_COMPILER} .c )
476
+ if (NOT CMAKE_CUDA_HOST_COMPILER STREQUAL "" )
477
+ set (NVCC_CMD ${NVCC_CMD} -ccbin ${CMAKE_CUDA_HOST_COMPILER} )
478
+ endif ()
456
479
457
- if (NOT MSVC )
458
- set (cuda_flags -Wno-pedantic )
459
- endif ()
460
- set (cuda_flags ${cxx_flags} -use_fast_math ${cuda_flags} )
480
+ execute_process (
481
+ COMMAND ${NVCC_CMD} -Xcompiler --version
482
+ OUTPUT_VARIABLE CUDA_CCFULLVER
483
+ ERROR_QUIET
484
+ )
461
485
462
- list (JOIN host_cxx_flags " " cuda_host_flags ) # pass host compiler flags as a single argument
463
- if (NOT cuda_host_flags STREQUAL "" )
464
- set (cuda_flags ${cuda_flags} -Xcompiler ${cuda_host_flags} )
465
- endif ()
486
+ if (NOT CUDA_CCFULLVER MATCHES clang )
487
+ set (CUDA_CCID "GNU" )
488
+ execute_process (
489
+ COMMAND ${NVCC_CMD} -Xcompiler "-dumpfullversion -dumpversion"
490
+ OUTPUT_VARIABLE CUDA_CCVER
491
+ ERROR_QUIET
492
+ )
493
+ else ()
494
+ if (CUDA_CCFULLVER MATCHES Apple )
495
+ set (CUDA_CCID "AppleClang" )
496
+ else ()
497
+ set (CUDA_CCID "Clang" )
498
+ endif ()
499
+ string (REGEX REPLACE "^.* version ([0-9.]*).*$" "\\ 1" CUDA_CCVER ${CUDA_CCFULLVER} )
500
+ endif ()
501
+
502
+ message ("-- CUDA host compiler is ${CUDA_CCID} ${CUDA_CCVER} " )
466
503
467
- add_compile_options ("$<$<COMPILE_LANGUAGE:CUDA>:${cuda_flags} >" )
504
+ get_flags (${CUDA_CCID} ${CUDA_CCVER} )
505
+ list (JOIN GF_CXX_FLAGS " " CUDA_CXX_FLAGS ) # pass host compiler flags as a single argument
506
+ if (NOT CUDA_CXX_FLAGS STREQUAL "" )
507
+ set (CUDA_FLAGS ${CUDA_FLAGS} -Xcompiler ${CUDA_CXX_FLAGS} )
508
+ endif ()
509
+ endif ()
510
+
511
+ add_compile_options ("$<$<COMPILE_LANGUAGE:CUDA>:${CUDA_FLAGS} >" )
512
+ endif ()
468
513
469
514
if (WIN32 )
470
515
add_compile_definitions (_CRT_SECURE_NO_WARNINGS )
@@ -488,6 +533,7 @@ endif()
488
533
execute_process (
489
534
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_EXE_LINKER_FLAGS} -Wl,-v
490
535
ERROR_VARIABLE output
536
+ OUTPUT_QUIET
491
537
)
492
538
if (output MATCHES "dyld-1015\. 7" )
493
539
add_compile_definitions (HAVE_BUGGY_APPLE_LINKER )
@@ -610,6 +656,11 @@ else()
610
656
message (STATUS "Unknown architecture" )
611
657
endif ()
612
658
659
+ if (MINGW )
660
+ # Target Windows 8 for PrefetchVirtualMemory
661
+ add_compile_definitions (_WIN32_WINNT=0x602 )
662
+ endif ()
663
+
613
664
#
614
665
# POSIX conformance
615
666
#
0 commit comments