Skip to content

Commit 8caba67

Browse files
committed
[CMake] Move compiler configuration to its own cmake file. (#498)
1 parent 6225457 commit 8caba67

File tree

2 files changed

+46
-35
lines changed

2 files changed

+46
-35
lines changed

CMakeLists.txt

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,8 @@ endif()
3333
# Top level project, doesn't really affect anything.
3434
project(genzh LANGUAGES C CXX)
3535

36-
# Print some information
37-
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
38-
message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
39-
message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}")
40-
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
41-
if (DEFINED MSVC_VERSION)
42-
message(STATUS "MSVC_VERSION: ${MSVC_VERSION}")
43-
endif()
44-
45-
# Set variable for VS6 to handle special cases.
46-
if (DEFINED MSVC_VERSION AND MSVC_VERSION LESS 1300)
47-
set(IS_VS6_BUILD TRUE)
48-
else()
49-
set(IS_VS6_BUILD FALSE)
50-
endif()
51-
52-
# Create PDB for Release as long as debug info was generated during compile.
53-
if(MSVC)
54-
string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE " /DEBUG /OPT:REF /OPT:ICF")
55-
string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE " /DEBUG /OPT:REF /OPT:ICF")
56-
endif()
36+
# This file handles extra settings wanted/needed for different compilers.
37+
include(cmake/compilers.cmake)
5738

5839
include(FetchContent)
5940

@@ -78,20 +59,6 @@ add_subdirectory(Dependencies/MaxSDK)
7859
add_subdirectory(Dependencies/SafeDisc)
7960
add_subdirectory(Dependencies/Utility)
8061

81-
if (NOT IS_VS6_BUILD)
82-
# Set C++ standard
83-
set(CMAKE_CXX_STANDARD 20)
84-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
85-
set(CMAKE_CXX_EXTENSIONS OFF) # Ensures only ISO features are used
86-
87-
if (MSVC)
88-
# Multithreaded build.
89-
add_compile_options(/MP)
90-
# Enforce strict __cplusplus version
91-
add_compile_options(/Zc:__cplusplus)
92-
endif()
93-
endif()
94-
9562
# Do we want to build extra SDK stuff or just the game binary?
9663
option(GENZH_BUILD_ZEROHOUR "Build Zero Hour code." ON)
9764
option(GENZH_BUILD_GENERALS "Build Generals code." ON)
@@ -110,6 +77,11 @@ add_feature_info(ProfileBuild GENZH_BUILD_PROFILE "Building as a \"Profile\" bui
11077

11178
add_library(gz_config INTERFACE)
11279

80+
if(NOT IS_VS6_BUILD)
81+
# Because we set CMAKE_CXX_STANDARD_REQUIRED and CMAKE_CXX_EXTENSIONS in the compilers.cmake this should be enforced.
82+
target_compile_features(gz_config INTERFACE cxx_std_20)
83+
endif()
84+
11385
target_compile_options(gz_config INTERFACE ${GENZH_FLAGS})
11486

11587
target_compile_definitions(gz_config INTERFACE $<IF:$<CONFIG:Debug>,_DEBUG WWDEBUG DEBUG,_RELEASE>)

cmake/compilers.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# Print some information
3+
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
4+
message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
5+
message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}")
6+
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
7+
if (DEFINED MSVC_VERSION)
8+
message(STATUS "MSVC_VERSION: ${MSVC_VERSION}")
9+
endif()
10+
11+
# Set variable for VS6 to handle special cases.
12+
if (DEFINED MSVC_VERSION AND MSVC_VERSION LESS 1300)
13+
set(IS_VS6_BUILD TRUE)
14+
else()
15+
set(IS_VS6_BUILD FALSE)
16+
endif()
17+
18+
# Make release builds have debug information too.
19+
if(MSVC)
20+
# Create PDB for Release as long as debug info was generated during compile.
21+
string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE " /DEBUG /OPT:REF /OPT:ICF")
22+
string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE " /DEBUG /OPT:REF /OPT:ICF")
23+
else()
24+
# We go a bit wild here and assume any other compiler we are going to use supports -g for debug info.
25+
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -g")
26+
string(APPEND CMAKE_C_FLAGS_RELEASE " -g")
27+
endif()
28+
29+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
30+
set(CMAKE_CXX_EXTENSIONS OFF) # Ensures only ISO features are used
31+
32+
if (NOT IS_VS6_BUILD)
33+
if (MSVC)
34+
# Multithreaded build.
35+
add_compile_options(/MP)
36+
# Enforce strict __cplusplus version
37+
add_compile_options(/Zc:__cplusplus)
38+
endif()
39+
endif()

0 commit comments

Comments
 (0)