Skip to content

Commit

Permalink
update src/cmakelists for MSVC options
Browse files Browse the repository at this point in the history
  • Loading branch information
s2496214 committed Sep 6, 2024
1 parent d579b5d commit 7b19beb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
10 changes: 1 addition & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,6 @@ endif()

##############################################

if(MSVC)
set(NCNN_THREADS OFF)
if(NCNN_OPENMP AND NCNN_SIMPLEOMP)
# try to use /openmp in cl.exe instead -fopenmp
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
endif()
endif()

# set cmake default folder name
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "cmake")
Expand All @@ -660,7 +652,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s FORCE_FILESYSTEM=1 -s INITIAL_MEMORY=256MB -s EXIT_RUNTIME=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s FORCE_FILESYSTEM=1 -s INITIAL_MEMORY=256MB -s EXIT_RUNTIME=1")
set(CMAKE_EXECUTBLE_LINKER_FLAGS "${CMAKE_EXECUTBLE_LINKER_FLAGS} -s FORCE_FILESYSTEM=1 -s INITIAL_MEMORY=256MB -s EXIT_RUNTIME=1")

if(NCNN_OPENMP AND NCNN_SIMPLEOMP)
# TODO better flags for emscripten
# node --experimental-wasm-threads xxx.js
Expand Down
22 changes: 14 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ function(ncnn_src_group ncnn_src_string folder)
string(REGEX REPLACE "/" "\\\\" _target_folder "${folder}")

foreach(_file IN LISTS ${_ncnn_src_list})
source_group ("${_target_folder}" FILES "${_file}")
endforeach ()
source_group("${_target_folder}" FILES "${_file}")
endforeach()
endfunction()

set(ncnn_SRCS
Expand Down Expand Up @@ -215,11 +215,11 @@ endif()

target_include_directories(ncnn
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/ncnn>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/ncnn>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/layer>)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/layer>)

if(NCNN_OPENMP)
if(NOT NCNN_SIMPLEOMP)
Expand All @@ -237,6 +237,8 @@ if(NCNN_OPENMP)
if(NCNN_SIMPLEOMP)
if(IOS OR APPLE)
target_compile_options(ncnn PRIVATE -Xpreprocessor -fopenmp)
elseif(WIN32 OR MSVC)
target_compile_options(ncnn PRIVATE /openmp)
else()
target_compile_options(ncnn PRIVATE -fopenmp)
endif()
Expand All @@ -262,7 +264,11 @@ if(NCNN_THREADS)
target_link_libraries(ncnn PUBLIC Threads::Threads)
endif()
if(NCNN_SIMPLEOMP OR NCNN_SIMPLESTL)
target_link_libraries(ncnn PUBLIC pthread)
if(MSVC OR WIN32)
message(STATUS "Using Native WIN32 THREAD MODEL")
else()
target_link_libraries(ncnn PUBLIC pthread)
endif()
endif()
endif()

Expand Down Expand Up @@ -398,7 +404,7 @@ if(NCNN_TARGET_ARCH STREQUAL "x86")
else()
if(NOT CMAKE_SYSTEM_NAME MATCHES "WASI")
target_compile_options(ncnn PRIVATE -msse2 -msse)
endif ()
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Emscripten|WASI")
target_compile_options(ncnn PRIVATE -msimd128)
endif()
Expand Down

0 comments on commit 7b19beb

Please sign in to comment.