Commit 87fdc289 authored by Tom Finegan's avatar Tom Finegan

Add MSVC support to the cmake build.

BUG=https://bugs.chromium.org/p/aomedia/issues/detail?id=76

Change-Id: Iced0b69e669aa39ff33a6ffa1dfc804d7ec9345f
parent 2b3496f4
......@@ -792,17 +792,17 @@ set(AOM_LIB_TARGETS aom_rtcd aom_util aom_dsp aom_encoder_stats aom_mem
# Assembly and intrinsic targets.
#
if ("${AOM_TARGET_CPU}" STREQUAL "x86" OR "${AOM_TARGET_CPU}" STREQUAL "x86_64")
add_asm_build("aom_util" "AOM_PORTS_ASM_X86")
add_asm_library("aom_util_x86" "AOM_PORTS_ASM_X86" "aom")
endif ()
if (HAVE_MMX)
add_asm_build("aom_util" "AOM_PORTS_ASM_MMX")
add_asm_library("aom_util_mmx" "AOM_PORTS_ASM_MMX" "aom")
endif ()
if (HAVE_SSE2)
add_asm_build("aom_dsp" "AOM_DSP_ASM_SSE2")
add_asm_build("aom_av1_encoder" "AOM_AV1_ENCODER_SSE2_ASM")
require_flag("-msse2" NO)
add_asm_library("aom_dsp_sse2" "AOM_DSP_ASM_SSE2" "aom")
add_asm_library("aom_av1_encoder_sse2" "AOM_AV1_ENCODER_SSE2_ASM" "aom")
require_flag_nomsvc("-msse2" NO)
add_intrinsics_object_library("-msse2" "sse2" "aom_dsp" "AOM_DSP_INTRIN_SSE2")
add_intrinsics_object_library("-msse2" "sse2" "aom_av1_common"
"AOM_AV1_COMMON_SSE2_INTRIN")
......@@ -811,16 +811,16 @@ if (HAVE_SSE2)
endif ()
if (HAVE_SSE3)
add_asm_build("aom_dsp" "AOM_DSP_INTRIN_SSE3")
add_asm_library("aom_dsp_sse3" "AOM_DSP_INTRIN_SSE3" "aom")
endif ()
if (HAVE_SSSE3)
if ("${AOM_TARGET_CPU}" STREQUAL "x86_64")
list(APPEND AOM_DSP_ASM_SSSE3 ${AOM_DSP_ASM_SSSE3_X86_64})
endif ()
add_asm_build("aom_dsp" "AOM_DSP_ASM_SSSE3")
add_asm_build("aom_av1_encoder" "AOM_AV1_ENCODER_SSSE3_ASM")
require_flag("-mssse3" NO)
add_asm_library("aom_dsp_ssse3" "AOM_DSP_ASM_SSSE3" "aom")
add_asm_library("aom_av1_encoder_ssse3" "AOM_AV1_ENCODER_SSSE3_ASM" "aom")
require_flag_nomsvc("-mssse3" NO)
add_intrinsics_object_library("-mssse3" "ssse3" "aom_dsp"
"AOM_DSP_INTRIN_SSSE3")
add_intrinsics_object_library("-mssse3" "ssse3" "aom_av1_common"
......@@ -830,8 +830,8 @@ if (HAVE_SSSE3)
endif ()
if (HAVE_SSE4_1)
add_asm_build("aom_dsp" "AOM_DSP_ASM_SSE4_1")
require_flag("-msse4.1" NO)
add_asm_library("aom_dsp_sse4_1" "AOM_DSP_ASM_SSE4_1" "aom")
require_flag_nomsvc("-msse4.1" NO)
add_intrinsics_object_library("-msse4.1" "sse4_1" "aom_dsp"
"AOM_DSP_INTRIN_SSE4_1")
add_intrinsics_object_library("-msse4.1" "sse4" "aom_av1_common"
......@@ -843,10 +843,10 @@ if (HAVE_SSE4_1)
endif ()
if (HAVE_AVX)
add_asm_build("aom_dsp" "AOM_DSP_AVX_ASM")
add_asm_library("aom_dsp_avx" "AOM_DSP_AVX_ASM" "aom")
endif ()
if (HAVE_AVX2)
require_flag("-mavx2" NO)
require_flag_nomsvc("-mavx2" NO)
add_intrinsics_object_library("-mavx2" "avx2" "aom_dsp" "AOM_DSP_AVX2_INTRIN")
add_intrinsics_object_library("-mavx2" "avx2" "aom_av1_common"
"AOM_AV1_COMMON_AVX2_INTRIN")
......@@ -928,7 +928,9 @@ endforeach ()
if (CONFIG_LIBYUV)
add_library(yuv OBJECT ${AOM_LIBYUV_SOURCES})
target_compile_options(yuv PRIVATE -Wno-unused-parameter)
if (NOT MSVC)
target_compile_options(yuv PRIVATE -Wno-unused-parameter)
endif ()
include_directories("${AOM_ROOT}/third_party/libyuv/include")
# Add to existing targets.
......@@ -941,7 +943,10 @@ endif ()
if (CONFIG_WEBM_IO)
add_library(webm OBJECT ${AOM_LIBWEBM_SOURCES})
include_directories("${AOM_ROOT}/third_party/libwebm")
target_compile_options(webm PRIVATE -Wno-shadow)
if (NOT MSVC)
target_compile_options(webm PRIVATE -Wno-shadow)
endif ()
# Add to existing targets.
target_sources(aom_decoder_app_util PUBLIC ${AOM_WEBM_DECODER_SOURCES})
......@@ -954,6 +959,10 @@ if (CONFIG_WEBM_IO)
endif ()
if (CONFIG_UNIT_TESTS)
if (MSVC)
# Force static run time to avoid collisions with googletest.
include("${AOM_ROOT}/build/cmake/msvc_runtime.cmake")
endif ()
include_directories(
"${AOM_ROOT}/third_party/googletest/src/googletest/src"
"${AOM_ROOT}/third_party/googletest/src/googletest/include")
......
......@@ -19,6 +19,9 @@ if (NOT AOM_TARGET_CPU)
# TODO(tomfinegan): This will not work for a cross compile. Target CPU and
# system will have to come from a toolchain file or the cmake command line.
set(AOM_TARGET_CPU ${CMAKE_SYSTEM_PROCESSOR})
if (AOM_TARGET_CPU STREQUAL "AMD64")
set(AOM_TARGET_CPU "x86_64")
endif ()
set(AOM_TARGET_SYSTEM ${CMAKE_SYSTEM_NAME})
if (NOT EXISTS "${AOM_ROOT}/build/cmake/targets/${AOM_TARGET_CPU}.cmake")
message("No RTCD template for ${AOM_TARGET_CPU}, using generic.")
......@@ -69,23 +72,19 @@ else ()
endif ()
# Test compiler support.
if (MSVC)
else ()
AomCheckSourceCompiles("inline_check" "static inline void function(void) {}"
HAVE_INLINE)
if (HAVE_INLINE EQUAL 1)
set(INLINE "inline")
endif ()
# TODO(tomfinegan): aom_ports_check is legacy; HAVE_AOM_PORTS is not used
# anywhere in the aom sources. To be removed after parity with the legacy
# build system stops being important.
AomCheckSourceCompiles("aom_ports_check"
"#include \"${AOM_ROOT}/aom/aom_integer.h\""
HAVE_AOM_PORTS)
AomCheckSourceCompiles("pthread_check" "#include <pthread.h>" HAVE_PTHREAD_H)
AomCheckSourceCompiles("unistd_check" "#include <unistd.h>" HAVE_UNISTD_H)
AomCheckSourceCompiles("inline_check" "static inline void function(void) {}"
HAVE_INLINE)
if (HAVE_INLINE EQUAL 1)
set(INLINE "inline")
endif ()
# TODO(tomfinegan): aom_ports_check is legacy; HAVE_AOM_PORTS is not used
# anywhere in the aom sources. To be removed after parity with the legacy
# build system stops being important.
AomCheckSourceCompiles("aom_ports_check"
"#include \"${AOM_ROOT}/aom/aom_integer.h\""
HAVE_AOM_PORTS)
AomCheckSourceCompiles("pthread_check" "#include <pthread.h>" HAVE_PTHREAD_H)
AomCheckSourceCompiles("unistd_check" "#include <unistd.h>" HAVE_UNISTD_H)
# TODO(tomfinegan): consume trailing whitespace after configure_file() when
# target platform check produces empty INLINE and RESTRICT values (aka empty
......
......@@ -9,6 +9,19 @@
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
##
# Translate $flag to one which MSVC understands, and write the new flag to the
# variable named by $translated_flag (or unset it, when MSVC needs no flag).
function (get_msvc_intrinsic_flag flag translated_flag)
if ("${flag}" STREQUAL "-msse2")
# MSVC does not require a flag for SSE2 (as of MSVS 14).
unset(${translated_flag} PARENT_SCOPE)
elseif ("${flag}" STREQUAL "-mavx2")
set(${translated_flag} "/arch:AVX2" PARENT_SCOPE)
else ()
set(${translated_flag} "/arch:AVX" PARENT_SCOPE)
endif ()
endfunction ()
# Adds an object library target. Terminates generation if $flag is not supported
# by the current compiler. $flag is the intrinsics flag required by the current
# compiler, and is added to the compile flags for all sources in $sources.
......@@ -19,12 +32,17 @@
# that disallow the direct addition of .o files to them as dependencies. Static
# libraries do not have this limitation.
function (add_intrinsics_object_library flag opt_name target_to_update sources)
if (MSVC)
message(FATAL_ERROR "MSVC instrinics support not implemented.")
endif ()
set(target_name ${target_to_update}_${opt_name}_intrinsics)
add_library(${target_name} OBJECT ${${sources}})
target_compile_options(${target_name} PUBLIC ${flag})
if (MSVC)
get_msvc_intrinsic_flag(${flag} "flag")
endif ()
if (flag)
target_compile_options(${target_name} PUBLIC ${flag})
endif ()
target_sources(aom PUBLIC $<TARGET_OBJECTS:${target_name}>)
# Add the new lib target to the global list of aom library targets.
......@@ -35,44 +53,60 @@ endfunction ()
# Adds sources in list named by $sources to $target and adds $flag to the
# compile flags for each source file.
function (add_intrinsics_source_to_target flag target sources)
target_sources(${target} PUBLIC ${${sources}})
if (MSVC)
message(FATAL_ERROR "MSVC instrinics support not implemented.")
get_msvc_intrinsic_flag(${flag} "flag")
endif ()
target_sources(${target} PUBLIC ${${sources}})
foreach (source ${${sources}})
set_property(SOURCE ${source} APPEND PROPERTY COMPILE_FLAGS ${flag})
endforeach ()
endfunction ()
# Adds build commands for ASM files in $sources and uses $asm_build_name to
# build an output directory path. Adds ASM objects to libaom directly. $sources
# must be the name of a variable containing a list of sources.
#
# Note: the libaom target is always updated because OBJECT libraries have rules
# that disallow the direct addition of .o files to them as dependencies. Static
# libraries do not have this limitation.
function (add_asm_build asm_build_name sources)
set(AOM_ASM_OBJECTS_DIR "${AOM_CONFIG_DIR}/asm_objects/${asm_build_name}")
if (NOT EXISTS "${AOM_ASM_OBJECTS_DIR}")
file(MAKE_DIRECTORY "${AOM_ASM_OBJECTS_DIR}")
if (flag)
foreach (source ${${sources}})
set_property(SOURCE ${source} APPEND PROPERTY COMPILE_FLAGS ${flag})
endforeach ()
endif ()
endfunction ()
# TODO(tomfinegan): This might get rather lengthy; probably best to move it
# out into its own function or macro.
if ("${AOM_TARGET_CPU}" STREQUAL "x86_64" AND
"${AOM_TARGET_SYSTEM}" STREQUAL "Darwin")
set(objformat "macho64")
elseif ("${AOM_TARGET_CPU}" STREQUAL "x86_64" AND
"${AOM_TARGET_SYSTEM}" STREQUAL "Linux")
set(objformat "elf64")
# Writes object format for the current target to the var named by $out_format,
# or terminates the build when the object format for the current target is
# unknown.
function (get_asm_obj_format out_format)
if ("${AOM_TARGET_CPU}" STREQUAL "x86_64")
if ("${AOM_TARGET_SYSTEM}" STREQUAL "Darwin")
set(objformat "macho64")
elseif ("${AOM_TARGET_SYSTEM}" STREQUAL "Linux")
set(objformat "elf64")
elseif ("${AOM_TARGET_SYSTEM}" STREQUAL "Windows")
set(objformat "win64")
else ()
message(FATAL_ERROR "Unknown obj format: ${AOM_TARGET_SYSTEM}")
endif ()
else ()
message(FATAL_ERROR
"Unknown obj format: ${AOM_TARGET_CPU}-${AOM_TARGET_SYSTEM}")
endif ()
foreach (asm_source ${${sources}})
set(${out_format} ${objformat} PARENT_SCOPE)
endfunction ()
# Adds library target named $lib_name for ASM files in variable named by
# $asm_sources. Builds an output directory path from $lib_name. Links $lib_name
# into $dependent_target. Generates a dummy C file with a dummy function to
# ensure that all cmake generators can determine the linker language, and that
# build tools don't complain that an object exposes no symbols.
function (add_asm_library lib_name asm_sources dependent_target)
set(asm_lib_obj_dir "${AOM_CONFIG_DIR}/asm_objects/${lib_name}")
if (NOT EXISTS "${asm_lib_obj_dir}")
file(MAKE_DIRECTORY "${asm_lib_obj_dir}")
endif ()
# TODO(tomfinegan): If cmake ever allows addition of .o files to OBJECT lib
# targets, make this OBJECT instead of STATIC to hide the target from
# consumers of the AOM cmake build.
add_library(${lib_name} STATIC ${${asm_sources}})
get_asm_obj_format("objformat")
foreach (asm_source ${${asm_sources}})
get_filename_component(asm_source_name "${asm_source}" NAME)
set(asm_object "${AOM_ASM_OBJECTS_DIR}/${asm_source_name}.o")
set(asm_object "${asm_lib_obj_dir}/${asm_source_name}.o")
add_custom_command(OUTPUT "${asm_object}"
COMMAND ${YASM_EXECUTABLE}
ARGS -f ${objformat}
......@@ -82,6 +116,20 @@ function (add_asm_build asm_build_name sources)
COMMENT "Building ASM object ${asm_object}"
WORKING_DIRECTORY "${AOM_CONFIG_DIR}"
VERBATIM)
target_sources(aom PUBLIC "${asm_source}" "${asm_object}")
target_sources(${lib_name} PRIVATE "${asm_object}")
endforeach ()
# The above created a target containing only ASM sources. Cmake needs help
# here to determine the linker language. Add a dummy C file to force the
# linker language to C. We don't bother with setting the LINKER_LANGUAGE
# property on the library target because not all generators obey it (looking
# at you, xcode generator).
set(dummy_c_file "${AOM_CONFIG_DIR}/${lib_name}_dummy.c")
file(WRITE "${dummy_c_file}"
"// Generated file. DO NOT EDIT!\n"
"// ${lib_name} needs C file to force link language, ignore me.\n"
"void ${lib_name}_dummy_function(void) {}\n")
target_sources(${lib_name} PUBLIC ${dummy_c_file})
target_link_libraries(${dependent_target} PRIVATE ${lib_name})
endfunction ()
##
## Copyright (c) 2017, Alliance for Open Media. All rights reserved
##
## This source code is subject to the terms of the BSD 2 Clause License and
## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
## was not distributed with this source code in the LICENSE file, you can
## obtain it at www.aomedia.org/license/software. If the Alliance for Open
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
##
if (MSVC)
# CMake defaults to producing code linked to the DLL MSVC runtime. That will
# not work with googletest, and isn't what we want anyway.
if (NOT "${MSVC_RUNTIME}" STREQUAL "dll")
foreach (flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if (${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif (${flag_var} MATCHES "/MD")
endforeach (flag_var)
endif ()
endif ()
......@@ -28,6 +28,7 @@ set(RTCD_CONFIG_SPATIAL_RESAMPLING "yes")
set(RTCD_CONFIG_STATIC "yes")
set(RTCD_CONFIG_OS_SUPPORT "yes")
set(RTCD_CONFIG_TEMPORAL_DENOISING "yes")
set(RTCD_CONFIG_RUNTIME_CPU_DETECT "yes")
if (CONFIG_AOM_HIGHBITDEPTH)
set(RTCD_CONFIG_AOM_HIGHBITDEPTH "yes")
......
......@@ -8,6 +8,7 @@
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
##
ARCH_X86_64=${RTCD_ARCH_X86_64}
HAVE_MMX=${RTCD_HAVE_MMX}
HAVE_SSE=${RTCD_HAVE_SSE}
HAVE_SSE2=${RTCD_HAVE_SSE2}
......@@ -33,6 +34,7 @@ CONFIG_SPATIAL_RESAMPLING=${RTCD_CONFIG_SPATIAL_RESAMPLING}
CONFIG_STATIC=${RTCD_CONFIG_STATIC}
CONFIG_OS_SUPPORT=${RTCD_CONFIG_OS_SUPPORT}
CONFIG_TEMPORAL_DENOISING=${RTCD_CONFIG_TEMPORAL_DENOISING}
CONFIG_RUNTIME_CPU_DETECT=${RTCD_CONFIG_RUNTIME_CPU_DETECT}
CONFIG_AOM_HIGHBITDEPTH=${RTCD_CONFIG_AOM_HIGHBITDEPTH}
CONFIG_CLPF=${RTCD_CONFIG_CLPF}
CONFIG_EXT_INTER=${RTCD_CONFIG_EXT_INTER}
......
......@@ -22,6 +22,7 @@ set(HAVE_AVX 1)
set(HAVE_AVX2 1)
# RTCD versions of assembly flavor flags ("yes" means on in rtcd.pl, not 1).
set(RTCD_ARCH_X86_64 "yes")
set(RTCD_HAVE_MMX "yes")
set(RTCD_HAVE_SSE "yes")
set(RTCD_HAVE_SSE2 "yes")
......@@ -49,6 +50,7 @@ set(RTCD_CONFIG_SPATIAL_RESAMPLING "yes")
set(RTCD_CONFIG_STATIC "yes")
set(RTCD_CONFIG_OS_SUPPORT "yes")
set(RTCD_CONFIG_TEMPORAL_DENOISING "yes")
set(RTCD_CONFIG_RUNTIME_CPU_DETECT "yes")
if (CONFIG_AOM_HIGHBITDEPTH)
set(RTCD_CONFIG_AOM_HIGHBITDEPTH "yes")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment