diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-19 17:55:54 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-19 17:55:54 +0100 |
commit | b0841e820860d09e0498554a43c01055e99baa57 (patch) | |
tree | c64663a19b6d312143ea790cadfbea1f4a91ce02 /cmake | |
parent | 9c9132225c96db6779712a7e6d5162815a676052 (diff) |
cmake: add toolchain file
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/msvc.cmake | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/cmake/msvc.cmake b/cmake/msvc.cmake new file mode 100644 index 00000000..3889a5f5 --- /dev/null +++ b/cmake/msvc.cmake @@ -0,0 +1,139 @@ +SET(CMAKE_SYSTEM_NAME Windows) +SET(CMAKE_SYSTEM_VERSION 5.01) + +if(NOT DEFINED floormat-64bit) + if ("$ENV{LIBPATH}" MATCHES "lib\\\\x64;") + set(floormat-64bit 1) + elseif("$ENV{LIBPATH}" MATCHES "lib\\\\x86;") + set(floormat-64bit5 0) + endif() +endif() + +if(NOT DEFINED floormat-no-static-crt) + set(floormat-no-static-crt 0) +endif() + +if(DEFINED floormat-64bit) + if(floormat-64bit) + set(CMAKE_SYSTEM_PROCESSOR AMD64) + else() + set(CMAKE_SYSTEM_PROCESSOR x86) + endif() +endif() + +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR CMAKE_INSTALL_PREFIX STREQUAL "") + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "" FORCE) +endif() + +set(CMAKE_C_COMPILER_INIT cl.exe) +set(CMAKE_CXX_COMPILER_INIT cl.exe) +set(CMAKE_ASM_NASM_COMPILER_INIT nasm.exe) + +# search for programs in the host directories +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# don't poison with system compile-time data +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +#add_definitions(-D_ITERATOR_DEBUG_LEVEL=0) +#add_compile_options(-Qvec-report:2) +add_compile_options(-d2cgsummary -Bt) +add_definitions(-D_HAS_EXCEPTIONS=0) + +if(DEFINED CMAKE_TOOLCHAIN_FILE) + # ignore cmake warning: Manually-specified variable not used by the project + set(CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}}") +endif() + +set(CMAKE_POLICY_DEFAULT_CMP0069 NEW CACHE INTERNAL "" FORCE) +#set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) + +set(CMAKE_C_EXTENSIONS FALSE) +set(CMAKE_CXX_EXTENSIONS FALSE) + +set(CMAKE_CROSSCOMPILING 0) + +function(sets type) + set(i 0) + list(LENGTH ARGN max) + math(EXPR foo "${max} % 2") + if(NOT foo EQUAL 0) + message(FATAL_ERROR "argument count not even") + endif() + while(i LESS max) + list(GET ARGN "${i}" name) + math(EXPR i "${i} + 1") + list(GET ARGN "${i}" value) + math(EXPR i "${i} + 1") + set(${name} "${value}" CACHE "${type}" "" FORCE) + endwhile() +endfunction() + +if(DEFINED floormat-64bit) + if(floormat-64bit) + set(floormat-simd "AVX") + else() + set(floormat-simd "SSE2") + endif() +endif() + +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") + +add_link_options(-cgthreads:$ENV{NUMBER_OF_PROCESSORS}) + +set(_CFLAGS "-diagnostics:caret -Zc:inline -Zc:preprocessor -wd4117 -Zi -Zf -Zo -bigobj -cgthreads1 -vd0 -permissive-") +if(NOT floormat-no-static-crt) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded" CACHE INTERNAL "" FORCE) +else() + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL" CACHE INTERNAL "" FORCE) +endif() +set(_CXXFLAGS "${_CFLAGS} -Zc:throwingNew -Zc:lambda") +set(_CFLAGS_RELEASE "-O2 -Oit -Oy- -Ob3 -fp:fast -GS- -GF -GL -Gw -Gy") +if(NOT floormat-simd STREQUAL "") + set(_CFLAGS_RELEASE "${_CFLAGS_RELEASE} -arch:${floormat-simd}") +endif() +set(_CFLAGS_DEBUG "-guard:cf -MTd -Gs0 -RTCs") +set(_CXXFLAGS_RELEASE "${_CFLAGS_RELEASE}") +set(_CXXFLAGS_DEBUG "${_CFLAGS_DEBUG}") + +set(_LDFLAGS "-WX") +set(_LDFLAGS_RELEASE "-OPT:REF,ICF=10 -LTCG:INCREMENTAL -DEBUG:FULL") +set(_LDFLAGS_DEBUG "-DEBUG:FULL") + +set(_LDFLAGS_STATIC "-WX") +set(_LDFLAGS_STATIC_RELEASE "-LTCG:INCREMENTAL") +set(_LDFLAGS_STATIC_DEBUG "") + +set(CMAKE_BUILD_TYPE_INIT "RELEASE" CACHE INTERNAL "") + +string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE) +set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "" FORCE) +if (NOT CMAKE_BUILD_TYPE STREQUAL "RELEASE" AND NOT CMAKE_BUILD_TYPE STREQUAL "DEBUG") + set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "" FORCE) +endif() +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS RELEASE DEBUG) + +foreach(k "" "_${CMAKE_BUILD_TYPE}") + set("FLAGS_CXX${k}" "" CACHE STRING "More CMAKE_CXX_FLAGS${k}") + #set("FLAGS_C${k}" "" CACHE STRING "More CMAKE_C_FLAGS${k} (almost never used)") + set("FLAGS_LD${k}" "" CACHE STRING "More CMAKE_(SHARED|EXE|MODULE)_LINKER_FLAGS${k}") + set("FLAGS_ARCHIVE${k}" "" CACHE STRING "More CMAKE_STATIC_LINKER_FLAGS${k}") +endforeach() + +foreach(k "" _DEBUG _RELEASE) + #set(CMAKE_STATIC_LINKER_FLAGS${k} "${CMAKE_STATIC_LINKER_FLAGS${k}} ${_LDFLAGS_STATIC${k}}") + set(CMAKE_STATIC_LINKER_FLAGS${k} "${_LDFLAGS_STATIC${k}} ${FLAGS_ARCHIVE${k}}" CACHE STRING "" FORCE) +endforeach() +foreach(j "" _DEBUG _RELEASE) + foreach(i MODULE EXE SHARED) + #set(CMAKE_${i}_LINKER_FLAGS${j} "${CMAKE_${i}_LINKER_FLAGS${j}} ${_LDFLAGS${j}}") + set(CMAKE_${i}_LINKER_FLAGS${j} "${_LDFLAGS${j}} ${FLAGS_LD${j}}" CACHE STRING "" FORCE) + endforeach() +endforeach() + +foreach(j C CXX) + foreach(i "" _DEBUG _RELEASE) + #set(CMAKE_${j}_FLAGS${i} "${CMAKE_${j}_FLAGS${i}} ${_${j}FLAGS${i}}") + set(CMAKE_${j}_FLAGS${i} "${_${j}FLAGS${i}} ${FLAGS_${j}${i}}" CACHE STRING "" FORCE) + endforeach() +endforeach() |