From 712a3199732315d86c704734a8d230d6b4ee64f5 Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 21 Aug 2022 13:25:36 -0700 Subject: [PATCH] De-duplicate list of static libraries and flags applied to all libraries This is so flags that apply globally (i.e. to the game and all static libraries it's compiled with), such as /MT on MSVC, can be put in a list, and along with putting all static libraries in a list, we remove the need for each flag to be repeated for each static library and we can just use a foreach loop instead. (Global compile flags of course don't apply to us meddling with CMAKE_C_FLAGS and CMAKE_CXX_FLAGS directly, because we need to do that in order to make sure the C and C++ standards are set properly.) --- desktop_version/CMakeLists.txt | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/desktop_version/CMakeLists.txt b/desktop_version/CMakeLists.txt index 55a53186..fa0b5666 100644 --- a/desktop_version/CMakeLists.txt +++ b/desktop_version/CMakeLists.txt @@ -295,6 +295,12 @@ target_compile_definitions(lodepng-static PRIVATE -DLODEPNG_NO_COMPILE_ENCODER ) +if(BUNDLE_DEPENDENCIES) + set(STATIC_LIBRARIES physfs-static tinyxml2-static lodepng-static faudio-static) +else() + set(STATIC_LIBRARIES lodepng-static) +endif() + if(BUNDLE_DEPENDENCIES) add_library(tinyxml2-static STATIC ${XML2_SRC}) add_library(physfs-static STATIC ${PFS_SRC}) @@ -307,27 +313,27 @@ if(BUNDLE_DEPENDENCIES) ../third_party/FAudio/include ) - target_link_libraries(VVVVVV physfs-static tinyxml2-static lodepng-static faudio-static) + target_link_libraries(VVVVVV ${STATIC_LIBRARIES}) else() find_package(utf8cpp CONFIG) - target_link_libraries(VVVVVV physfs tinyxml2 utf8cpp lodepng-static FAudio) + target_link_libraries(VVVVVV ${STATIC_LIBRARIES} physfs tinyxml2 utf8cpp FAudio) endif() + if(MSVC) # Statically link Microsoft's runtime library so end users don't have to install it - target_compile_options(VVVVVV PRIVATE /MT) - - # /MT must also be applied to every statically-linked library, else you get a linker error - if(BUNDLE_DEPENDENCIES) - target_compile_options(tinyxml2-static PRIVATE /MT) - target_compile_options(physfs-static PRIVATE /MT) - target_compile_options(faudio-static PRIVATE /MT) - endif() - - target_compile_options(lodepng-static PRIVATE /MT) + list(APPEND GLOBAL_COMPILE_FLAGS /MT) endif() + +target_compile_options(VVVVVV PRIVATE ${GLOBAL_COMPILE_FLAGS}) + +foreach(static_library IN LISTS STATIC_LIBRARIES) + target_compile_options(${static_library} PRIVATE ${GLOBAL_COMPILE_FLAGS}) +endforeach(static_library) + + # SDL2 Dependency (Detection pulled from FAudio) if(DEFINED SDL2_INCLUDE_DIRS AND DEFINED SDL2_LIBRARIES) message(STATUS "Using pre-defined SDL2 variables SDL2_INCLUDE_DIRS and SDL2_LIBRARIES")