Skip to content

Commit 38e90d7

Browse files
committed
Adjust MSVC detection/support in CMakeLists.txt
1 parent 9e51acb commit 38e90d7

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${BUILD_TYPE}")
3939
set(XMR-STAK_COMPILE "native" CACHE STRING "select CPU compute architecture")
4040
set_property(CACHE XMR-STAK_COMPILE PROPERTY STRINGS "native;generic")
4141
if(XMR-STAK_COMPILE STREQUAL "native")
42-
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
42+
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
43+
#intentionally appending due to how MSVC collects options
44+
# this forces these three flags to override any previous
45+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox /GL /EHsc")
46+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ox /GL /EHsc")
47+
else()
48+
# GCC and all other compilers
4349
set(CMAKE_CXX_FLAGS "-march=native -mtune=native ${CMAKE_CXX_FLAGS}")
4450
set(CMAKE_C_FLAGS "-march=native -mtune=native ${CMAKE_C_FLAGS}")
4551
endif()
@@ -147,9 +153,11 @@ if(CUDA_ENABLE)
147153
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} --cuda-gpu-arch=sm_${CUDA_ARCH_ELEM}")
148154
endforeach()
149155
elseif(CUDA_COMPILER STREQUAL "nvcc")
150-
# add c++11 for cuda
151-
if(NOT CMAKE_CXX_FLAGS MATCHES "-std=c\\+\\+11")
152-
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
156+
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
157+
# add c++11 for cuda, except Windows
158+
if(NOT CMAKE_CXX_FLAGS MATCHES "-std=c\\+\\+11")
159+
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
160+
endif()
153161
endif()
154162

155163
# avoid that nvcc in CUDA 8 complains about sm_20 pending removal
@@ -425,6 +433,10 @@ include_directories(BEFORE .)
425433
set (CMAKE_POSITION_INDEPENDENT_CODE TRUE)
426434

427435
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
436+
# optimize linking
437+
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG")
438+
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO /OPT:REF")
439+
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO /OPT:REF")
428440
# remove warnings that f_open() is not save and f_open_s should be used
429441
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
430442
# disable min define to allow usage of std::min
@@ -587,4 +599,5 @@ if( NOT CMAKE_INSTALL_PREFIX STREQUAL PROJECT_BINARY_DIR )
587599
else()
588600
# this rule is used if the install prefix is the build directory
589601
install(CODE "MESSAGE(\"xmr-stak installed to folder 'bin'\")")
590-
endif()
602+
endif()
603+
# vim: et sw=4 sts=4 ts=4:

0 commit comments

Comments
 (0)