Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust MSVC detection/support in CMakeLists.txt #1842

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${BUILD_TYPE}")
set(XMR-STAK_COMPILE "native" CACHE STRING "select CPU compute architecture")
set_property(CACHE XMR-STAK_COMPILE PROPERTY STRINGS "native;generic")
if(XMR-STAK_COMPILE STREQUAL "native")
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
#intentionally appending due to how MSVC collects options
# this forces these three flags to override any previous
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox /GL /EHsc")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ox /GL /EHsc")
else()
# GCC and all other compilers
set(CMAKE_CXX_FLAGS "-march=native -mtune=native ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-march=native -mtune=native ${CMAKE_C_FLAGS}")
endif()
Expand Down Expand Up @@ -147,9 +153,11 @@ if(CUDA_ENABLE)
set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} --cuda-gpu-arch=sm_${CUDA_ARCH_ELEM}")
endforeach()
elseif(CUDA_COMPILER STREQUAL "nvcc")
# add c++11 for cuda
if(NOT CMAKE_CXX_FLAGS MATCHES "-std=c\\+\\+11")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# add c++11 for cuda, except Windows
if(NOT CMAKE_CXX_FLAGS MATCHES "-std=c\\+\\+11")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
endif()
endif()

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

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