diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a91fc17a..b325c2763 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,6 @@ project(Generators LANGUAGES C CXX) # All Options should be defined in cmake/options.cmake include(cmake/options.cmake) include(cmake/external/onnxruntime_external_deps.cmake) -include(cmake/util_func.cmake) file(READ "VERSION_INFO" ver) set(VERSION_INFO ${ver} CACHE STRING "Set the onnxruntime-genai version info.") @@ -107,7 +106,10 @@ add_library(onnxruntime-genai-static STATIC ${generator_srcs}) target_include_directories(onnxruntime-genai PRIVATE ${ORT_HEADER_DIR}) target_include_directories(onnxruntime-genai-static PRIVATE ${ORT_HEADER_DIR}) -genai_set_target_compile_options(onnxruntime-genai) +if(CMAKE_GENERATOR_TOOLSET MATCHES "Visual Studio") + target_link_options(onnxruntime-genai PRIVATE "/CETCOMPAT") + target_compile_options(onnxruntime-genai PRIVATE "/sdl") +endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set_target_properties(onnxruntime-genai-static PROPERTIES POSITION_INDEPENDENT_CODE ON) diff --git a/cmake/util_func.cmake b/cmake/util_func.cmake deleted file mode 100644 index 80847da7f..000000000 --- a/cmake/util_func.cmake +++ /dev/null @@ -1,15 +0,0 @@ -function(genai_set_target_compile_options target) - if (MSVC) - check_cxx_compiler_flag(-sdl HAS_SDL) - check_cxx_compiler_flag(-Qspectre HAS_QSPECTRE) - if (HAS_SDL) - target_compile_options(${target} PRIVATE "/sdl") - endif () - if (HAS_QSPECTRE) - target_compile_options(${target} PRIVATE "/Qspectre") - endif () - if (NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm" AND NOT USE_CUDA) - target_compile_options(${target} PRIVATE "/CETCOMPAT") - endif () - endif () -endfunction() \ No newline at end of file diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index fdbe33023..e2175039a 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -1,5 +1,5 @@ include(${CMAKE_SOURCE_DIR}/cmake/cxx_standard.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/util_func.cmake) + file(GLOB python_srcs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" @@ -14,7 +14,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") endif() set_target_properties(python PROPERTIES OUTPUT_NAME "onnxruntime_genai") -genai_set_target_compile_options(python) +if(CMAKE_GENERATOR_TOOLSET MATCHES "Visual Studio") + target_link_options(python PRIVATE "/CETCOMPAT") + target_compile_options(python PRIVATE "/sdl" PRIVATE "/Qspectre") +endif() if(USE_CUDA AND CMAKE_CUDA_COMPILER) cmake_policy(SET CMP0104 OLD)