diff --git a/CMakeLists.txt b/CMakeLists.txt index 438fe7a..0864c87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,8 @@ set(CMAKE_AUTOUIC ON) # macros for linking both prebuilt artifactory libraries and locally built ones include(CMakeLinkUtilities) -# Test hardware avx capabilities -include(CMakeSetOptimizationAndAVX) +# set optimization in release mode +include(CMakeSetOptimizationLevel) if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32 /EHsc /MP /permissive- /Zc:__cplusplus") diff --git a/cmake/CMakeHsneProject.cmake b/cmake/CMakeHsneProject.cmake index 63d0509..b0cac08 100644 --- a/cmake/CMakeHsneProject.cmake +++ b/cmake/CMakeHsneProject.cmake @@ -68,7 +68,7 @@ set_HDILib_project_link_libraries(${HSNE_PLUGIN}) set_lz4_project_link_libraries(${HSNE_PLUGIN}) set_optimization_level(${HSNE_PLUGIN} ${MV_SNE_OPTIMIZATION_LEVEL}) -check_and_set_AVX(${HSNE_PLUGIN} ${MV_SNE_USE_AVX}) +mv_check_and_set_AVX(${HSNE_PLUGIN} ${MV_SNE_USE_AVX}) silence_opengl_deprecation(${HSNE_PLUGIN}) diff --git a/cmake/CMakeSetOptimizationAndAVX.cmake b/cmake/CMakeSetOptimizationAndAVX.cmake deleted file mode 100644 index bbb0039..0000000 --- a/cmake/CMakeSetOptimizationAndAVX.cmake +++ /dev/null @@ -1,53 +0,0 @@ -# ----------------------------------------------------------------------------- -# Check for and link to AVX instruction sets -# ----------------------------------------------------------------------------- -macro(check_and_set_AVX target useavx) - message(STATUS "Set instruction sets for ${target}, MV_USE_AVX is ${useavx}") - - if(${useavx}) - # Use cmake hardware checks to see whether AVX should be activated - include(CheckCXXCompilerFlag) - - if(MSVC) - set(AXV_CompileOption "/arch:AVX") - set(AXV2_CompileOption "/arch:AVX2") - else() - set(AXV_CompileOption "-DUSE_AVX") - set(AXV2_CompileOption "-DUSE_AVX2") - endif() - - if(NOT DEFINED COMPILER_OPT_AVX_SUPPORTED OR NOT DEFINED COMPILER_OPT_AVX2_SUPPORTED) - check_cxx_compiler_flag(${AXV_CompileOption} COMPILER_OPT_AVX_SUPPORTED) - check_cxx_compiler_flag(${AXV2_CompileOption} COMPILER_OPT_AVX2_SUPPORTED) - endif() - - if(COMPILER_OPT_AVX2_SUPPORTED) - message( STATUS "Use AXV2 for ${target}") - target_compile_options(${target} PRIVATE ${AXV2_CompileOption}) - elseif(COMPILER_OPT_AVX_SUPPORTED) - message( STATUS "Use AXV for ${target}") - target_compile_options(${target} PRIVATE ${AXV_CompileOption}) - endif() - endif() -endmacro() - -# ----------------------------------------------------------------------------- -# Sets the optimization level -# ----------------------------------------------------------------------------- -macro(set_optimization_level target level) - message(STATUS "Set optimization level in release for ${target} to ${level}") - - if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") - set(OPTIMIZATION_LEVEL_FLAG "-O${level}") - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - if(${level} EQUAL 0) - set(OPTIMIZATION_LEVEL_FLAG "/Od") - else() - set(OPTIMIZATION_LEVEL_FLAG "/O${level}") - endif() - endif() - - target_compile_options(${target} PRIVATE "$<$:${OPTIMIZATION_LEVEL_FLAG}>") - - message( STATUS "Optimization level for ${target} (release) is ${OPTIMIZATION_LEVEL_FLAG}") -endmacro() diff --git a/cmake/CMakeSetOptimizationLevel.cmake b/cmake/CMakeSetOptimizationLevel.cmake new file mode 100644 index 0000000..01a03f6 --- /dev/null +++ b/cmake/CMakeSetOptimizationLevel.cmake @@ -0,0 +1,20 @@ +# ----------------------------------------------------------------------------- +# Sets the optimization level +# ----------------------------------------------------------------------------- +macro(set_optimization_level target level) + message(STATUS "Set optimization level in release for ${target} to ${level}") + + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") + set(OPTIMIZATION_LEVEL_FLAG "-O${level}") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + if(${level} EQUAL 0) + set(OPTIMIZATION_LEVEL_FLAG "/Od") + else() + set(OPTIMIZATION_LEVEL_FLAG "/O${level}") + endif() + endif() + + target_compile_options(${target} PRIVATE "$<$:${OPTIMIZATION_LEVEL_FLAG}>") + + message( STATUS "Optimization level for ${target} (release) is ${OPTIMIZATION_LEVEL_FLAG}") +endmacro() diff --git a/cmake/CMakeTsneProject.cmake b/cmake/CMakeTsneProject.cmake index 3d3d57c..e944325 100644 --- a/cmake/CMakeTsneProject.cmake +++ b/cmake/CMakeTsneProject.cmake @@ -64,7 +64,7 @@ set_HDILib_project_link_libraries(${TSNE_PLUGIN}) set_lz4_project_link_libraries(${TSNE_PLUGIN}) set_optimization_level(${TSNE_PLUGIN} ${MV_SNE_OPTIMIZATION_LEVEL}) -check_and_set_AVX(${TSNE_PLUGIN} ${MV_SNE_USE_AVX}) +mv_check_and_set_AVX(${TSNE_PLUGIN} ${MV_SNE_USE_AVX}) silence_opengl_deprecation(${TSNE_PLUGIN})