Skip to content

Commit f7c453f

Browse files
authored
Merge pull request #27 from qyot27/dss_deps
An assortment of GCC and CMake fixes and enhancements
2 parents 37841e5 + 3bb92db commit f7c453f

File tree

12 files changed

+247
-188
lines changed

12 files changed

+247
-188
lines changed

CMakeLists.txt

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if(CMAKE_CONFIGURATION_TYPES)
1616
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Reset the configurations to what we need" FORCE)
1717
endif()
1818

19-
IF( MSVC_IDE ) # Check for Visual Studio
19+
IF( MSVC ) # Check for Visual Studio
2020

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

33-
IF(CMAKE_GENERATOR_TOOLSET STREQUAL "v141_clang_c2")
34-
#1900 is reported
35-
message("v141_clang_c2 toolset was specified via -T. Reported MSVC_VERSION is: ${MSVC_VERSION}")
36-
set(CLANG_IN_VS "1")
37-
ENDIF()
33+
IF(MSVC_IDE)
34+
IF(CMAKE_GENERATOR_TOOLSET STREQUAL "v141_clang_c2")
35+
#1900 is reported
36+
message("v141_clang_c2 toolset was specified via -T. Reported MSVC_VERSION is: ${MSVC_VERSION}")
37+
set(CLANG_IN_VS "1")
38+
ENDIF()
3839

39-
# We want our project to also run on Windows XP
40-
# 1900 (VS2015) is not supported but we leave here
41-
IF(MSVC_VERSION VERSION_LESS 1910 )
42-
IF(NOT CLANG_IN_VS STREQUAL "1")
43-
set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2015
44-
# https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
45-
add_definitions("/Zc:threadSafeInit-")
46-
ENDIF()
47-
ELSE()
48-
IF(NOT CLANG_IN_VS STREQUAL "1")
49-
set(CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2017
50-
# https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
51-
add_definitions("/Zc:threadSafeInit-")
40+
# We want our project to also run on Windows XP
41+
# 1900 (VS2015) is not supported but we leave here
42+
IF(MSVC_VERSION VERSION_LESS 1910 )
43+
IF(NOT CLANG_IN_VS STREQUAL "1")
44+
set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2015
45+
# https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
46+
add_definitions("/Zc:threadSafeInit-")
47+
ENDIF()
48+
ELSE()
49+
IF(NOT CLANG_IN_VS STREQUAL "1")
50+
set(CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2017
51+
# https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
52+
add_definitions("/Zc:threadSafeInit-")
53+
ENDIF()
5254
ENDIF()
5355
ENDIF()
5456

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

6972
# Enable CRT heap debugging - only effective in debug builds
7073
add_definitions("/D _CRTDBG_MAP_ALLOC")
71-
74+
7275
add_definitions("/D __SSE2__")
7376

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

8087
# Set additional optimization flags
81-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy /Ot /GS- /Oi")
82-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy /Ot /GS- /Oi")
88+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy /Ot /GS- /Oi /arch:${MSVC_CPU_ARCH}")
89+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy /Ot /GS- /Oi /arch:${MSVC_CPU_ARCH}")
8390

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

93101
ENDIF()
94102

@@ -104,4 +112,4 @@ configure_file(
104112
IMMEDIATE @ONLY)
105113

106114
add_custom_target(uninstall
107-
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
115+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)

avs_core/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ elseif (MINGW)
5454

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

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

6565
# Windows DLL dependencies
66-
if (MSVC_IDE)
67-
target_link_libraries("AvsCore" "Winmm.lib" "Vfw32.lib" "Msacm32.lib" "Gdi32.lib" "User32.lib" "Advapi32.lib" "Ole32.lib" "ImageHlp.lib")
68-
elseif (MINGW)
69-
target_link_libraries("AvsCore" "uuid" "winmm" "vfw32" "msacm32" "gdi32" "user32" "advapi32" "ole32" "imagehlp.lib")
66+
if (MSVC OR MINGW)
67+
target_link_libraries("AvsCore" "uuid" "winmm" "vfw32" "msacm32" "gdi32" "user32" "advapi32" "ole32" "imagehlp")
7068
endif()
7169

7270
if (MSVC_IDE)

avs_core/Files.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ FILE(GLOB AvsCore_Sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
1313
"core/*.c"
1414
"core/*.cpp"
1515
"core/*.h"
16-
"core/avisynth.rc"
1716

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

42-
IF( MSVC_IDE )
41+
IF( MSVC OR MINGW )
4342
# Export definitions in general are not needed on x64 and only cause warnings,
4443
# unfortunately we still must need a .def file for some COM functions.
4544
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
4645
LIST(APPEND AvsCore_Sources "core/avisynth64.def")
4746
else()
4847
LIST(APPEND AvsCore_Sources "core/avisynth.def")
4948
endif()
50-
ENDIF()
49+
ENDIF()
50+
51+
IF( MSVC_IDE )
52+
# Ninja, unfortunately, seems to have some issues with using rc.exe
53+
LIST(APPEND AvsCore_Sources "core/avisynth.rc")
54+
ENDIF()

0 commit comments

Comments
 (0)