diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1040725b..a9e1f9b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -340,7 +340,7 @@ jobs: env: EMULATOR_ROOT: ${{github.workspace}}/build/${{matrix.preset}}/artifacts/root EMULATOR_VERBOSE: ${{ github.event.inputs.verbose }} - ANALYSIS_SAMPLE: ${{github.workspace}}/build/${{matrix.preset}}/artifacts/dump-apiset.exe + ANALYSIS_SAMPLE: ${{github.workspace}}/build/${{matrix.preset}}/artifacts/test-sample.exe win-test: name: Windows Test diff --git a/CMakeLists.txt b/CMakeLists.txt index 2168ae43..f430a56c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.26.4) ########################################## +option(MOMO_ENABLE_AVX2 "Enable AVX2 support" ON) option(MOMO_ENABLE_SANITIZER "Enable sanitizer" OFF) option(MOMO_ENABLE_CLANG_TIDY "Enable clang-tidy checks" OFF) option(MOMO_ENABLE_RUST_CODE "Enable code parts written in rust" ON) diff --git a/cmake/compiler-env.cmake b/cmake/compiler-env.cmake index 299ee317..9238fee4 100644 --- a/cmake/compiler-env.cmake +++ b/cmake/compiler-env.cmake @@ -1,4 +1,5 @@ include_guard() +include(CheckCXXCompilerFlag) ########################################## # System identification @@ -114,6 +115,24 @@ endif() ########################################## +if(MOMO_ENABLE_AVX2 AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android")) + set(CMAKE_REQUIRED_FLAGS -Werror) + check_cxx_compiler_flag(-mavx2 COMPILER_SUPPORTS_MAVX2) + set(CMAKE_REQUIRED_FLAGS "") + + check_cxx_compiler_flag(/arch:AVX2 COMPILER_SUPPORTS_ARCH_AVX2) + + if(COMPILER_SUPPORTS_MAVX2) + momo_add_c_and_cxx_compile_options(-mavx2) + endif() + + if (COMPILER_SUPPORTS_ARCH_AVX2) + momo_add_c_and_cxx_compile_options(/arch:AVX2) + endif() +endif() + +########################################## + if(MOMO_ENABLE_SANITIZER) momo_add_c_and_cxx_compile_options(-fsanitize=address) add_link_options(-fsanitize=address) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index ee8c8987..4c9dc09b 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -109,12 +109,16 @@ macro(momo_target_remove_compile_option target option) get_target_property(target_flags ${target} COMPILE_OPTIONS) if(target_flags) list(REMOVE_ITEM target_flags ${option}) + list(REMOVE_ITEM target_flags "$<$:${option}>") + list(REMOVE_ITEM target_flags "$<$:${option}>") set_target_properties(${target} PROPERTIES COMPILE_OPTIONS "${target_flags}") endif() get_target_property(target_interface_flags ${target} INTERFACE_COMPILE_OPTIONS) if(target_interface_flags) list(REMOVE_ITEM target_interface_flags ${option}) + list(REMOVE_ITEM target_interface_flags "$<$:${option}>") + list(REMOVE_ITEM target_interface_flags "$<$:${option}>") set_target_properties(${target} PROPERTIES INTERFACE_COMPILE_OPTIONS "${target_interface_flags}") endif() endmacro() @@ -122,13 +126,21 @@ endmacro() ########################################## macro(momo_target_remove_compile_options target) - foreach(option ${ARGV}) + foreach(option ${ARGN}) momo_target_remove_compile_option(${target} ${option}) endforeach() endmacro() ########################################## +function(momo_targets_remove_compile_options targets) + foreach(target ${targets}) + momo_target_remove_compile_options(${target} ${ARGN}) + endforeach() +endfunction() + +########################################## + function(momo_add_compile_options language) foreach(option ${ARGN}) add_compile_options( diff --git a/src/samples/CMakeLists.txt b/src/samples/CMakeLists.txt index b9067a51..d4839797 100644 --- a/src/samples/CMakeLists.txt +++ b/src/samples/CMakeLists.txt @@ -1,2 +1,12 @@ +momo_get_all_targets(EXISTING_TARGETS) + +########################################## + add_subdirectory(bad-sample) add_subdirectory(test-sample) + +########################################## + +momo_get_all_targets(ALL_TARGETS) +momo_list_difference("${ALL_TARGETS}" "${EXISTING_TARGETS}" SAMPLE_TARGETS) +momo_targets_remove_compile_options("${SAMPLE_TARGETS}" /arch:AVX2 -mavx2) \ No newline at end of file