Skip to content

Commit

Permalink
Merge pull request #27 from qyot27/dss_deps
Browse files Browse the repository at this point in the history
An assortment of GCC and CMake fixes and enhancements
  • Loading branch information
pinterf authored Mar 16, 2019
2 parents 37841e5 + 3bb92db commit f7c453f
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 188 deletions.
70 changes: 39 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Reset the configurations to what we need" FORCE)
endif()

IF( MSVC_IDE ) # Check for Visual Studio
IF( MSVC ) # Check for Visual Studio

#1800 = VS 12.0 (v120 toolset)
#1900 = VS 14.0 (v140 toolset)
Expand All @@ -30,25 +30,27 @@ IF( MSVC_IDE ) # Check for Visual Studio
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/Output/system")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/Output/c_api")

IF(CMAKE_GENERATOR_TOOLSET STREQUAL "v141_clang_c2")
#1900 is reported
message("v141_clang_c2 toolset was specified via -T. Reported MSVC_VERSION is: ${MSVC_VERSION}")
set(CLANG_IN_VS "1")
ENDIF()
IF(MSVC_IDE)
IF(CMAKE_GENERATOR_TOOLSET STREQUAL "v141_clang_c2")
#1900 is reported
message("v141_clang_c2 toolset was specified via -T. Reported MSVC_VERSION is: ${MSVC_VERSION}")
set(CLANG_IN_VS "1")
ENDIF()

# We want our project to also run on Windows XP
# 1900 (VS2015) is not supported but we leave here
IF(MSVC_VERSION VERSION_LESS 1910 )
IF(NOT CLANG_IN_VS STREQUAL "1")
set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2015
# https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
add_definitions("/Zc:threadSafeInit-")
ENDIF()
ELSE()
IF(NOT CLANG_IN_VS STREQUAL "1")
set(CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2017
# https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
add_definitions("/Zc:threadSafeInit-")
# We want our project to also run on Windows XP
# 1900 (VS2015) is not supported but we leave here
IF(MSVC_VERSION VERSION_LESS 1910 )
IF(NOT CLANG_IN_VS STREQUAL "1")
set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2015
# https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
add_definitions("/Zc:threadSafeInit-")
ENDIF()
ELSE()
IF(NOT CLANG_IN_VS STREQUAL "1")
set(CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2017
# https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
add_definitions("/Zc:threadSafeInit-")
ENDIF()
ENDIF()
ENDIF()

Expand All @@ -58,28 +60,33 @@ IF( MSVC_IDE ) # Check for Visual Studio
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-inconsistent-missing-override")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")
ELSE()
# Enable C++ with SEH exceptions
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /EHa")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHa")
# or add_compile_options( /EHa ) for CMake>=3?
# Enable C++ with SEH exceptions
# Avoid an obnoxious 'overrriding /EHsc with /EHa' warning when
# using something other than MSBuild
STRING( REPLACE "/EHsc" "/EHa" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
STRING( REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ENDIF()
# Prevent VC++ from complaining about not using MS-specific functions
add_definitions("/D _CRT_SECURE_NO_WARNINGS /D _SECURE_SCL=0")

# Enable CRT heap debugging - only effective in debug builds
add_definitions("/D _CRTDBG_MAP_ALLOC")

add_definitions("/D __SSE2__")

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
# VC++ enables the SSE2 instruction set by default even on 32-bits. Step back a bit.
#add_definitions("/arch:SSE")
add_definitions("/arch:SSE2") # Better use this one, it's 2017 now, and helps optimizing hbd stuff still in C
endif()
# CPU_ARCH can be overridden with the corresponding values when using MSVC:
# IA32 (disabled),
# SSE (Pentium III and higher, 1999),
# SSE2 (Pentium 4 and higher, 2000/2001),
# AVX (Sandy Bridge and higher, 2011),
# AVX2 (Haswell and higher, 2013)
set(MSVC_CPU_ARCH "SSE2" CACHE STRING "Set MSVC architecture optimization level (default: SSE2)")
endif()

# Set additional optimization flags
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy /Ot /GS- /Oi")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy /Ot /GS- /Oi")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy /Ot /GS- /Oi /arch:${MSVC_CPU_ARCH}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy /Ot /GS- /Oi /arch:${MSVC_CPU_ARCH}")

# Set C++17 flag
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c++17")
Expand All @@ -89,6 +96,7 @@ ELSE()
# c++17: if constexpr() and others from gcc 7
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17" ) # or -std=c++17 w/o gnu c++17 extensions
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native" )
SET( CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-stdcall-fixup" )

ENDIF()

Expand All @@ -104,4 +112,4 @@ configure_file(
IMMEDIATE @ONLY)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
8 changes: 3 additions & 5 deletions avs_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ elseif (MINGW)

# special AVX2 option for source files with *_avx2.cpp pattern
file(GLOB_RECURSE SRCS_AVX2 "*_avx2.cpp")
set_source_files_properties(${SRCS_AVX2} PROPERTIES COMPILE_FLAGS -mavx2 -mfma)
set_source_files_properties(${SRCS_AVX2} PROPERTIES COMPILE_FLAGS "-mavx2 -mfma")
endif()

# Specify include directories
Expand All @@ -63,10 +63,8 @@ target_include_directories("AvsCore" PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_definitions("AvsCore" PRIVATE BUILDING_AVSCORE)

# Windows DLL dependencies
if (MSVC_IDE)
target_link_libraries("AvsCore" "Winmm.lib" "Vfw32.lib" "Msacm32.lib" "Gdi32.lib" "User32.lib" "Advapi32.lib" "Ole32.lib" "ImageHlp.lib")
elseif (MINGW)
target_link_libraries("AvsCore" "uuid" "winmm" "vfw32" "msacm32" "gdi32" "user32" "advapi32" "ole32" "imagehlp.lib")
if (MSVC OR MINGW)
target_link_libraries("AvsCore" "uuid" "winmm" "vfw32" "msacm32" "gdi32" "user32" "advapi32" "ole32" "imagehlp")
endif()

if (MSVC_IDE)
Expand Down
10 changes: 7 additions & 3 deletions avs_core/Files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ FILE(GLOB AvsCore_Sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"core/*.c"
"core/*.cpp"
"core/*.h"
"core/avisynth.rc"

"core/parser/*.c"
"core/parser/*.cpp"
Expand All @@ -39,12 +38,17 @@ FILE(GLOB AvsCore_Sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"filters/exprfilter/*.h"
)

IF( MSVC_IDE )
IF( MSVC OR MINGW )
# Export definitions in general are not needed on x64 and only cause warnings,
# unfortunately we still must need a .def file for some COM functions.
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
LIST(APPEND AvsCore_Sources "core/avisynth64.def")
else()
LIST(APPEND AvsCore_Sources "core/avisynth.def")
endif()
ENDIF()
ENDIF()

IF( MSVC_IDE )
# Ninja, unfortunately, seems to have some issues with using rc.exe
LIST(APPEND AvsCore_Sources "core/avisynth.rc")
ENDIF()
Loading

0 comments on commit f7c453f

Please sign in to comment.