diff options
author | Roman Grundkiewicz <rogrundk@microsoft.com> | 2020-09-25 18:50:56 +0300 |
---|---|---|
committer | Martin Junczys-Dowmunt <Marcin.JunczysDowmunt@microsoft.com> | 2020-09-25 18:50:56 +0300 |
commit | ae866af035806ae978e8e7b3df753f727180f808 (patch) | |
tree | 5da55ce07f4f8e01f0fa977af9a7a9cd270ede70 | |
parent | 244cfaa07e326f5dbd762636a7173699dc81fe52 (diff) |
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
-rw-r--r-- | CMakeLists.txt | 13 | ||||
-rw-r--r-- | src/3rd_party/CMakeLists.txt | 9 |
2 files changed, 20 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a1ff0984..2dea6748 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/3rd_party/CMakeLists.txt b/src/3rd_party/CMakeLists.txt index f4cd9312..a18ea7b1 100644 --- a/src/3rd_party/CMakeLists.txt +++ b/src/3rd_party/CMakeLists.txt @@ -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") |