Merged PR 15561: Properly compile FBGEMM in CMake MSVC build

This fixes compilation of FBGEMM on Windows using CMake:
1. Compiling FBGEMM and cpuinfo statically
2. Forcing USE_STATIC_LIBS if USE_FBGEMM is set
This commit is contained in:
Roman Grundkiewicz 2020-09-25 15:50:56 +00:00 committed by Martin Junczys-Dowmunt
parent 244cfaa07e
commit ae866af035
2 changed files with 20 additions and 2 deletions

View File

@ -98,13 +98,22 @@ if(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} /MTd /Od /Ob0 ${INTRINSICS} /RTC1 /Zi /D_DEBUG")
# ignores warning LNK4049: locally defined symbol free imported - this comes from zlib
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /LTCG:incremental /INCREMENTAL:NO /ignore:4049")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /LTCG:incremental /INCREMENTAL:NO /ignore:4049")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:MSVCRT")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:MSVCRTD")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /LTCG:incremental")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /LTCG:incremental")
find_library(SHLWAPI Shlwapi.lib)
set(EXT_LIBS ${EXT_LIBS} SHLWAPI)
if(USE_FBGEMM)
if(NOT USE_STATIC_LIBS) # FBGEMM on Windows can be compiled only statically via CMake
message(FATAL_ERROR "FATAL ERROR: FBGEMM must be compiled statically on Windows, \
add -DUSE_STATIC_LIBS=on to the cmake command")
endif()
set(EXT_LIBS ${EXT_LIBS} fbgemm)
add_definitions(-DUSE_FBGEMM=1 -DFBGEMM_STATIC=1)
endif(USE_FBGEMM)
else(MSVC)
# Check we are using at least g++ 5.0

View File

@ -23,6 +23,15 @@ if(USE_FBGEMM)
# Do not compile cpuinfo executables due to a linker error, and they are not needed
set(CPUINFO_BUILD_TOOLS OFF CACHE BOOL "Build command-line tools")
# Do not build cpuinfo tests and benchmarks
set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "Do not build cpuinfo unit tests")
set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "Do not build cpuinfo mock tests")
set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "Do not build cpuinfo benchmarks")
if(MSVC)
# Force static compilation of cpuinfo on Windows
SET(CPUINFO_LIBRARY_TYPE "static" CACHE STRING "Type of cpuinfo library (shared, static, or default) to build")
SET(CPUINFO_RUNTIME_TYPE "static" CACHE STRING "Type of runtime library (shared, static, or default) to use")
endif(MSVC)
set(FBGEMM_BUILD_TESTS OFF CACHE BOOL "Disable fbgemm tests")
set(FBGEMM_BUILD_BENCHMARKS OFF CACHE BOOL "Disable fbgemm benchmark")