Skip to content

Commit 66b3b5f

Browse files
Fixed formatting of cmake files + couple of minor updates
1 parent 948c723 commit 66b3b5f

File tree

21 files changed

+782
-778
lines changed

21 files changed

+782
-778
lines changed

BuildUtils.cmake

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
11
if(PLATFORM_WIN32 OR PLATFORM_UNVIRSAL_WINDOWS)
2-
3-
function(copy_required_dlls TARGET_NAME)
4-
set(ENGINE_DLLS
5-
GraphicsEngineD3D11-shared
6-
GraphicsEngineD3D12-shared
7-
)
8-
if(PLATFORM_WIN32)
9-
list(APPEND ENGINE_DLLS GraphicsEngineOpenGL-shared)
10-
endif()
2+
3+
function(copy_required_dlls TARGET_NAME)
4+
set(ENGINE_DLLS
5+
GraphicsEngineD3D11-shared
6+
GraphicsEngineD3D12-shared
7+
)
8+
if(PLATFORM_WIN32)
9+
list(APPEND ENGINE_DLLS GraphicsEngineOpenGL-shared)
10+
endif()
1111

12-
foreach(DLL ${ENGINE_DLLS})
13-
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
14-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
15-
"\"$<TARGET_FILE:${DLL}>\""
16-
"\"$<TARGET_FILE_DIR:${TARGET_NAME}>\"")
17-
endforeach(DLL)
12+
foreach(DLL ${ENGINE_DLLS})
13+
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
14+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
15+
"\"$<TARGET_FILE:${DLL}>\""
16+
"\"$<TARGET_FILE_DIR:${TARGET_NAME}>\"")
17+
endforeach(DLL)
1818

19-
# Copy D3Dcompiler_47.dll
20-
if(MSVC)
21-
if(WIN64)
22-
set(D3D_COMPILER_PATH "\"$(VC_ExecutablePath_x64_x64)\\D3Dcompiler_47.dll\"")
23-
else()
24-
set(D3D_COMPILER_PATH "\"$(VC_ExecutablePath_x86_x86)\\D3Dcompiler_47.dll\"")
25-
endif()
26-
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
27-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
28-
${D3D_COMPILER_PATH}
29-
"\"$<TARGET_FILE_DIR:${TARGET_NAME}>\"")
30-
endif()
31-
endfunction()
19+
# Copy D3Dcompiler_47.dll
20+
if(MSVC)
21+
if(WIN64)
22+
set(D3D_COMPILER_PATH "\"$(VC_ExecutablePath_x64_x64)\\D3Dcompiler_47.dll\"")
23+
else()
24+
set(D3D_COMPILER_PATH "\"$(VC_ExecutablePath_x86_x86)\\D3Dcompiler_47.dll\"")
25+
endif()
26+
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
27+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
28+
${D3D_COMPILER_PATH}
29+
"\"$<TARGET_FILE_DIR:${TARGET_NAME}>\"")
30+
endif()
31+
endfunction()
3232

3333
endif(PLATFORM_WIN32 OR PLATFORM_UNVIRSAL_WINDOWS)
3434

3535

3636
function(set_common_target_properties TARGET)
37-
38-
get_target_property(TARGET_TYPE ${TARGET} TYPE)
37+
38+
get_target_property(TARGET_TYPE ${TARGET} TYPE)
3939

40-
if(MSVC)
41-
# For msvc, enable link-time code generation for release builds (I was not able to
42-
# find any way to set these settings through interface library BuildSettings)
43-
if(TARGET_TYPE STREQUAL STATIC_LIBRARY)
44-
set_target_properties(${TARGET} PROPERTIES
45-
STATIC_LIBRARY_FLAGS_RELEASE /LTCG
46-
STATIC_LIBRARY_FLAGS_MINSIZEREL /LTCG
47-
STATIC_LIBRARY_FLAGS_RELWITHDEBINFO /LTCG
48-
)
49-
else()
50-
set_target_properties(${TARGET} PROPERTIES
51-
LINK_FLAGS_RELEASE "/LTCG /OPT:REF"
52-
LINK_FLAGS_MINSIZEREL "/LTCG /OPT:REF"
53-
LINK_FLAGS_RELWITHDEBINFO "/LTCG /OPT:REF"
54-
)
40+
if(MSVC)
41+
# For msvc, enable link-time code generation for release builds (I was not able to
42+
# find any way to set these settings through interface library BuildSettings)
43+
if(TARGET_TYPE STREQUAL STATIC_LIBRARY)
44+
set_target_properties(${TARGET} PROPERTIES
45+
STATIC_LIBRARY_FLAGS_RELEASE /LTCG
46+
STATIC_LIBRARY_FLAGS_MINSIZEREL /LTCG
47+
STATIC_LIBRARY_FLAGS_RELWITHDEBINFO /LTCG
48+
)
49+
else()
50+
set_target_properties(${TARGET} PROPERTIES
51+
LINK_FLAGS_RELEASE "/LTCG /OPT:REF"
52+
LINK_FLAGS_MINSIZEREL "/LTCG /OPT:REF"
53+
LINK_FLAGS_RELWITHDEBINFO "/LTCG /OPT:REF"
54+
)
5555

56-
if(PLATFORM_UNIVERSAL_WINDOWS)
57-
# On UWP, disable incremental link to avoid linker warnings
58-
set_target_properties(${TARGET} PROPERTIES
59-
LINK_FLAGS_DEBUG /INCREMENTAL:NO
60-
)
61-
endif()
62-
endif()
63-
endif()
56+
if(PLATFORM_UNIVERSAL_WINDOWS)
57+
# On UWP, disable incremental link to avoid linker warnings
58+
set_target_properties(${TARGET} PROPERTIES
59+
LINK_FLAGS_DEBUG /INCREMENTAL:NO
60+
)
61+
endif()
62+
endif()
63+
endif()
6464

65-
if(PLATFORM_ANDROID)
66-
# target_compile_features(BuildSettings INTERFACE cxx_std_11) generates an error in gradle build on Android
67-
# It is crucial to set CXX_STANDARD flag to only affect c++ files and avoid failures compiling c-files:
68-
# error: invalid argument '-std=c++11' not allowed with 'C/ObjC'
69-
set_target_properties(${TARGET} PROPERTIES CXX_STANDARD 11)
70-
endif()
71-
72-
if(PLATFORM_IOS)
73-
# Feature detection fails for iOS build, so we have to set CXX_STANDARD
74-
# as a workaround
75-
set_target_properties(${TARGET} PROPERTIES CXX_STANDARD 11)
65+
if(PLATFORM_ANDROID)
66+
# target_compile_features(BuildSettings INTERFACE cxx_std_11) generates an error in gradle build on Android
67+
# It is crucial to set CXX_STANDARD flag to only affect c++ files and avoid failures compiling c-files:
68+
# error: invalid argument '-std=c++11' not allowed with 'C/ObjC'
69+
set_target_properties(${TARGET} PROPERTIES CXX_STANDARD 11)
70+
endif()
71+
72+
if(PLATFORM_IOS)
73+
# Feature detection fails for iOS build, so we have to set CXX_STANDARD
74+
# as a workaround
75+
set_target_properties(${TARGET} PROPERTIES CXX_STANDARD 11)
7676

77-
set_target_properties(${TARGET} PROPERTIES
78-
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 10.0
79-
)
80-
endif()
77+
set_target_properties(${TARGET} PROPERTIES
78+
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 10.0
79+
)
80+
endif()
8181
endfunction()

CMakeLists.txt

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -14,133 +14,133 @@ set(GLES_SUPPORTED FALSE CACHE INTERNAL "GLES is not spported")
1414
set(CMAKE_OBJECT_PATH_MAX 4096)
1515

1616
if(WIN32)
17-
if(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
18-
set(PLATFORM_UNIVERSAL_WINDOWS TRUE CACHE INTERNAL "Target platform: Windows Store")
19-
message("Target platform: Universal Windows")
20-
else()
21-
set(PLATFORM_WIN32 TRUE CACHE INTERNAL "Target platform: Win32") #WIN32 is a variable, so we cannot use string "WIN32"
22-
message("Target platform: Win32")
23-
endif()
17+
if(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
18+
set(PLATFORM_UNIVERSAL_WINDOWS TRUE CACHE INTERNAL "Target platform: Windows Store")
19+
message("Target platform: Universal Windows")
20+
else()
21+
set(PLATFORM_WIN32 TRUE CACHE INTERNAL "Target platform: Win32") #WIN32 is a variable, so we cannot use string "WIN32"
22+
message("Target platform: Win32")
23+
endif()
2424
else()
25-
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
26-
set(PLATFORM_ANDROID TRUE CACHE INTERNAL "Target platform: Android")
27-
message("Target platform: Android")
28-
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
29-
set(PLATFORM_LINUX TRUE CACHE INTERNAL "Target platform: Linux")
30-
message("Target Platform: Linux")
31-
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
32-
if(IOS)
33-
set(PLATFORM_IOS TRUE CACHE INTERNAL "Target platform: iOS")
34-
message("Target Platform: iOS")
35-
else()
36-
set(PLATFORM_MACOS TRUE CACHE INTERNAL "Target platform: MacOS")
37-
message("Target Platform: MacOS")
38-
endif()
39-
else()
40-
message(FATAL_ERROR "Unsupported platform")
41-
endif()
25+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
26+
set(PLATFORM_ANDROID TRUE CACHE INTERNAL "Target platform: Android")
27+
message("Target platform: Android")
28+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
29+
set(PLATFORM_LINUX TRUE CACHE INTERNAL "Target platform: Linux")
30+
message("Target Platform: Linux")
31+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
32+
if(IOS)
33+
set(PLATFORM_IOS TRUE CACHE INTERNAL "Target platform: iOS")
34+
message("Target Platform: iOS")
35+
else()
36+
set(PLATFORM_MACOS TRUE CACHE INTERNAL "Target platform: MacOS")
37+
message("Target Platform: MacOS")
38+
endif()
39+
else()
40+
message(FATAL_ERROR "Unsupported platform")
41+
endif()
4242
endif(WIN32)
4343

4444
add_library(BuildSettings INTERFACE)
4545

4646
if(PLATFORM_WIN32)
47-
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 supported on Win32 platform")
48-
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 supported on Win32 platform")
49-
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL supported on Win32 platform")
50-
target_compile_definitions(BuildSettings INTERFACE PLATFORM_WIN32=1)
47+
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 supported on Win32 platform")
48+
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 supported on Win32 platform")
49+
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL supported on Win32 platform")
50+
target_compile_definitions(BuildSettings INTERFACE PLATFORM_WIN32=1)
5151
elseif(PLATFORM_UNIVERSAL_WINDOWS)
52-
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 supported on Univeral Windows platform")
53-
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 supported on Univeral Windows platform")
54-
target_compile_definitions(BuildSettings INTERFACE PLATFORM_UNIVERSAL_WINDOWS=1)
52+
set(D3D11_SUPPORTED TRUE CACHE INTERNAL "D3D11 supported on Univeral Windows platform")
53+
set(D3D12_SUPPORTED TRUE CACHE INTERNAL "D3D12 supported on Univeral Windows platform")
54+
target_compile_definitions(BuildSettings INTERFACE PLATFORM_UNIVERSAL_WINDOWS=1)
5555
elseif(PLATFORM_ANDROID)
56-
set(GLES_SUPPORTED TRUE CACHE INTERNAL "OpenGLES supported on Android platform")
57-
target_compile_definitions(BuildSettings INTERFACE PLATFORM_ANDROID=1)
56+
set(GLES_SUPPORTED TRUE CACHE INTERNAL "OpenGLES supported on Android platform")
57+
target_compile_definitions(BuildSettings INTERFACE PLATFORM_ANDROID=1)
5858
elseif(PLATFORM_LINUX)
59-
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL supported on Linux platform")
60-
target_compile_definitions(BuildSettings INTERFACE PLATFORM_LINUX=1)
59+
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL supported on Linux platform")
60+
target_compile_definitions(BuildSettings INTERFACE PLATFORM_LINUX=1)
6161
elseif(PLATFORM_MACOS)
62-
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL supported on MacOS platform")
63-
target_compile_definitions(BuildSettings INTERFACE PLATFORM_MACOS=1)
62+
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL supported on MacOS platform")
63+
target_compile_definitions(BuildSettings INTERFACE PLATFORM_MACOS=1)
6464
elseif(PLATFORM_IOS)
65-
set(GLES_SUPPORTED TRUE CACHE INTERNAL "OpenGLES supported on iOS platform")
66-
target_compile_definitions(BuildSettings INTERFACE PLATFORM_IOS=1)
65+
set(GLES_SUPPORTED TRUE CACHE INTERNAL "OpenGLES supported on iOS platform")
66+
target_compile_definitions(BuildSettings INTERFACE PLATFORM_IOS=1)
6767
else()
68-
message(FATAL_ERROR "No PLATFORM_XXX variable defined. Make sure that 'DiligentCore' folder is processed first")
68+
message(FATAL_ERROR "No PLATFORM_XXX variable defined. Make sure that 'DiligentCore' folder is processed first")
6969
endif()
7070

7171
if(MSVC)
72-
# For msvc, enable level 4 warnings except for
73-
# - w4100 - unreferenced formal parameter
74-
# - w4505 - unreferenced local function has been removed
75-
target_compile_options(BuildSettings INTERFACE /W4 /wd4100 /wd4505)
76-
# In all releases mode also:
77-
# - disable w4189 - local variable is initialized but not referenced
78-
# - Enable AVX2 instruction set (/arch:AVX2)
79-
# - Disable RTTI (/GR-)
80-
# - Enable whole program optimizaion (/GL)
81-
# - Enable string pooling (/GF)
82-
set(MSVC_ALL_RELEASE_COMPILE_OPTIONS /arch:AVX2 /wd4189 /GR- /GL /GF)
83-
#target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:RELEASE>:/arch:AVX2 /wd4189 /Ot")
84-
# In RELEASE mode:
85-
# - Set favor fast code option (/Ot)
86-
# - Enable intrinsic functions (/Oi)
87-
set(MSVC_RELEASE_COMPILE_OPTIONS ${MSVC_ALL_RELEASE_COMPILE_OPTIONS} /Ot /Oi)
88-
# In MINSIZEREL mode set favor small code option (/Os)
89-
set(MSVC_MINSIZEREL_COMPILE_OPTIONS ${MSVC_ALL_RELEASE_COMPILE_OPTIONS} /Os)
90-
set(MSVC_RELWITHDEBINFO_COMPILE_OPTIONS ${MSVC_ALL_RELEASE_COMPILE_OPTIONS})
91-
target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:RELEASE>:${MSVC_RELEASE_COMPILE_OPTIONS}>")
92-
target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:MINSIZEREL>:${MSVC_MINSIZEREL_COMPILE_OPTIONS}>")
93-
target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:RELWITHDEBINFO>:${MSVC_RELWITHDEBINFO_COMPILE_OPTIONS}>")
94-
# !!!NOTE!!! For some reason above is the only form of generator expression that works
95-
# For instance, this way
96-
# target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:RELEASE>:/Ot>")
97-
# does not work as expected
72+
# For msvc, enable level 4 warnings except for
73+
# - w4100 - unreferenced formal parameter
74+
# - w4505 - unreferenced local function has been removed
75+
target_compile_options(BuildSettings INTERFACE /W4 /wd4100 /wd4505)
76+
# In all releases mode also:
77+
# - disable w4189 - local variable is initialized but not referenced
78+
# - Enable AVX2 instruction set (/arch:AVX2)
79+
# - Disable RTTI (/GR-)
80+
# - Enable whole program optimizaion (/GL)
81+
# - Enable string pooling (/GF)
82+
set(MSVC_ALL_RELEASE_COMPILE_OPTIONS /arch:AVX2 /wd4189 /GR- /GL /GF)
83+
#target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:RELEASE>:/arch:AVX2 /wd4189 /Ot")
84+
# In RELEASE mode:
85+
# - Set favor fast code option (/Ot)
86+
# - Enable intrinsic functions (/Oi)
87+
set(MSVC_RELEASE_COMPILE_OPTIONS ${MSVC_ALL_RELEASE_COMPILE_OPTIONS} /Ot /Oi)
88+
# In MINSIZEREL mode set favor small code option (/Os)
89+
set(MSVC_MINSIZEREL_COMPILE_OPTIONS ${MSVC_ALL_RELEASE_COMPILE_OPTIONS} /Os)
90+
set(MSVC_RELWITHDEBINFO_COMPILE_OPTIONS ${MSVC_ALL_RELEASE_COMPILE_OPTIONS})
91+
target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:RELEASE>:${MSVC_RELEASE_COMPILE_OPTIONS}>")
92+
target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:MINSIZEREL>:${MSVC_MINSIZEREL_COMPILE_OPTIONS}>")
93+
target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:RELWITHDEBINFO>:${MSVC_RELWITHDEBINFO_COMPILE_OPTIONS}>")
94+
# !!!NOTE!!! For some reason above is the only form of generator expression that works
95+
# For instance, this way
96+
# target_compile_options(BuildSettings INTERFACE "$<$<CONFIG:RELEASE>:/Ot>")
97+
# does not work as expected
9898
else()
9999

100-
set(DEBUG_MACROS _DEBUG DEBUG)
101-
set(RELEASE_MACROS NDEBUG)
102-
target_compile_definitions(BuildSettings INTERFACE "$<$<CONFIG:DEBUG>:${DEBUG_MACROS}>")
103-
target_compile_definitions(BuildSettings INTERFACE "$<$<CONFIG:RELEASE>:${RELEASE_MACROS}>")
104-
target_compile_definitions(BuildSettings INTERFACE "$<$<CONFIG:MINSIZEREL>:${RELEASE_MACROS}>")
105-
target_compile_definitions(BuildSettings INTERFACE "$<$<CONFIG:RELWITHDEBINFO>:${RELEASE_MACROS}>")
100+
set(DEBUG_MACROS _DEBUG DEBUG)
101+
set(RELEASE_MACROS NDEBUG)
102+
target_compile_definitions(BuildSettings INTERFACE "$<$<CONFIG:DEBUG>:${DEBUG_MACROS}>")
103+
target_compile_definitions(BuildSettings INTERFACE "$<$<CONFIG:RELEASE>:${RELEASE_MACROS}>")
104+
target_compile_definitions(BuildSettings INTERFACE "$<$<CONFIG:MINSIZEREL>:${RELEASE_MACROS}>")
105+
target_compile_definitions(BuildSettings INTERFACE "$<$<CONFIG:RELWITHDEBINFO>:${RELEASE_MACROS}>")
106106

107107
endif(MSVC)
108108

109109
if(PLATFORM_LINUX)
110-
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
111-
# Without -fPIC option GCC fails to link static libraries into dynamic library:
112-
# -fPIC
113-
# If supported for the target machine, emit position-independent code, suitable for
114-
# dynamic linking and avoiding any limit on the size of the global offset table.
115-
target_compile_options(BuildSettings INTERFACE -fPIC)
116-
endif()
110+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
111+
# Without -fPIC option GCC fails to link static libraries into dynamic library:
112+
# -fPIC
113+
# If supported for the target machine, emit position-independent code, suitable for
114+
# dynamic linking and avoiding any limit on the size of the global offset table.
115+
target_compile_options(BuildSettings INTERFACE -fPIC)
116+
endif()
117117
endif()
118118

119119
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
120-
set(ARCH 64 CACHE INTERNAL "64-bit architecture")
120+
set(ARCH 64 CACHE INTERNAL "64-bit architecture")
121121
else()
122-
set(ARCH 32 CACHE INTERNAL "32-bit architecture")
122+
set(ARCH 32 CACHE INTERNAL "32-bit architecture")
123123
endif()
124124

125125
if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS OR PLATFORM_MACOS)
126126

127-
# https://cmake.org/cmake/help/v3.8/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES
128-
target_compile_features(BuildSettings INTERFACE cxx_std_11) # Generates an error in gradle build on Android
127+
# https://cmake.org/cmake/help/v3.8/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES
128+
target_compile_features(BuildSettings INTERFACE cxx_std_11) # Generates an error in gradle build on Android
129129

130130
elseif(PLATFORM_ANDROID)
131131

132-
# LOCAL_CPP_FEATURES := exceptions rtti
132+
# LOCAL_CPP_FEATURES := exceptions rtti
133133

134134
elseif(PLATFORM_IOS)
135135

136-
136+
137137
endif()
138138

139139
if(PLATFORM_MACOS)
140-
find_library(APP_KIT AppKit)
141-
if (NOT APP_KIT)
142-
message(FATAL_ERROR "AppKit not found")
143-
endif()
140+
find_library(APP_KIT AppKit)
141+
if (NOT APP_KIT)
142+
message(FATAL_ERROR "AppKit not found")
143+
endif()
144144
elseif(PLATFORM_IOS)
145145
find_library(CORE_FOUNDATION CoreFoundation)
146146
if(NOT CORE_FOUNDATION)

0 commit comments

Comments
 (0)