diff --git a/CMakeLists.txt b/CMakeLists.txt index 29b1d57dfc06d511bf460bc86738bc1891edd7cc..50eaa95913f2542c9332c9ad4c51aaa844166c82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,8 @@ list(APPEND CMAKE_PREFIX_PATH option(BUILD_SHARED_LIBS "Create shared libraries?" OFF) set(CMAKE_LIBRARY_SEARCH_PATH "" CACHE PATH "Additional library installation path, e.g. /opt/local or C:/libs") -set(OGS_CPU_ARCHITECTURE "native" CACHE STRING "Processor architecture, defaults to native.") +set(OGS_CPU_ARCHITECTURE "native" CACHE STRING "Processor architecture, defaults to native (*nix) / blend (MSVC).") +option(OGS_ENABLE_AVX2 "Enable the use of AVX2 instructions" OFF) option(OGS_BUILD_TESTS "Should the test executables be built?" ON) ### CMake includes ### diff --git a/scripts/cmake/CompilerSetup.cmake b/scripts/cmake/CompilerSetup.cmake index da29fca3cf5b720508b2eaf7029a73a17d8d86b9..b048f0b63af370556e186194d81659db3d62fc5b 100644 --- a/scripts/cmake/CompilerSetup.cmake +++ b/scripts/cmake/CompilerSetup.cmake @@ -26,7 +26,9 @@ endif() # Set additional user-given compiler flags set(CMAKE_CXX_FLAGS ${OGS_CXX_FLAGS}) -if(OGS_CPU_ARCHITECTURE STREQUAL "generic") +if(OGS_ENABLE_AVX2) + set(CPU_FLAGS "-mavx2 -march=core-avx2") +elseif(OGS_CPU_ARCHITECTURE STREQUAL "generic") set(CPU_FLAGS "-mtune=generic") else() set(CPU_FLAGS "-march=${OGS_CPU_ARCHITECTURE}") @@ -93,6 +95,14 @@ endif () if (WIN32) ## For Visual Studio compiler if (MSVC) + if(OGS_CPU_ARCHITECTURE STREQUAL "generic") + set(CPU_FLAGS "/favor:blend") + else() + set(CPU_FLAGS "/favor:${OGS_CPU_ARCHITECTURE}") + endif() + if(OGS_ENABLE_AVX2) + set(CPU_FLAGS "${CPU_FLAGS} /arch:AVX2") + endif() add_definitions( -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS @@ -101,7 +111,7 @@ if (WIN32) -DNOMINMAX # This fixes compile errors with std::numeric_limits<T>::min() / max() ) # Sets warning level 3 and ignores some warnings - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /wd4290 /wd4267 /wd4996") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPU_FLAGS} /W3 /wd4290 /wd4267 /wd4996") # Allow big object files generated for template heavy code set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /ZI /Od /Ob0")