Advertisement
ShalokShalom

cmake/CompilerFlags.cmake

Jul 5th, 2024
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 0.88 KB | None | 0 0
  1. include(CheckCCompilerFlag)
  2.  
  3. # Set C standard
  4. set(CMAKE_C_STANDARD 17)
  5. set(CMAKE_C_STANDARD_REQUIRED ON)
  6.  
  7. # Set C++ standard
  8. set(CMAKE_CXX_STANDARD 17)
  9. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  10.  
  11. # Common flags
  12. set(COMMON_FLAGS
  13.     -Wall
  14.     -Wextra
  15.     -Wpedantic
  16.     -ffast-math
  17.     -DPIC
  18.     -freciprocal-math
  19.     -fsingle-precision-constant
  20.     -ftree-vectorize
  21.     -funroll-loops
  22. )
  23.  
  24. # Add flags conditionally
  25. if(EXTRA_OPTIMIZATIONS)
  26.     list(APPEND COMMON_FLAGS -march=native -mtune=native)
  27. endif()
  28.  
  29. if(EXTRA_DEBUG_INFO)
  30.     list(APPEND COMMON_FLAGS -g3)
  31. endif()
  32.  
  33. # Apply flags
  34. add_compile_options(${COMMON_FLAGS})
  35.  
  36. # Strict flags (can be enabled with an option)
  37. if(STRICT_FLAGS)
  38.     add_compile_options(-Werror)
  39. endif()
  40.  
  41. # OS-specific flags
  42. if(WIN32)
  43.     add_compile_options(-mms-bitfields -mwindows)
  44.     add_link_options(-Wl,-Bdynamic -Wl,-as-needed)
  45. endif()
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement