diff options
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | app/CMakeLists.txt | 37 | ||||
-rw-r--r-- | cmake/Exceptions.cmake | 31 | ||||
-rw-r--r-- | cmake/RTTI.cmake | 31 | ||||
-rw-r--r-- | cmake/Win32Subsystem.cmake | 31 |
5 files changed, 100 insertions, 34 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0edd517..ef5c85d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,10 @@ set(LINUX ${CMAKE_SYSTEM_NAME} MATCHES "Linux") include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() +include(cmake/Exceptions.cmake) +include(cmake/RTTI.cmake) +include(cmake/Win32Subsystem.cmake) + add_subdirectory(3rdparty/iconfontheaders) add_subdirectory(3rdparty/imgui) add_subdirectory(3rdparty/implot) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index e898800..fbbdfa1 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -138,40 +138,9 @@ if(NOT APPLE) endif() endif() -if(WIN32) - function(handle_gnu_style_compiler) - # No console window when targeting windows - # Supposedly the flag -mwindows would automatically make the executable use GUI subsystem - # But, when subsystem is set to GUI, linker will only search WinMain and wWinMain but not the standard main (it seems like) - # so creating GUI executable fails and the linker silently reverts to the default, CUI subsystem - target_link_options(CpltCore PRIVATE -Wl,-subsystem:windows) - target_link_options(CpltCore PRIVATE -Wl,-entry:mainCRTStartup) - endfunction() - - function(handle_msvc_style_compiler) - # No console window when targeting windows - target_link_options(CpltCore PRIVATE /SUBSYSTEM:windows /ENTRY:mainCRTStartup) - endfunction() - - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # GCC (MinGW) - handle_gnu_style_compiler() - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") - # MSVC-style argument clang (clang-cl.exe) - handle_msvc_style_compiler() - elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU") - # GNU-style argument clang (clang.exe and clang++.exe) - handle_gnu_style_compiler() - endif() - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - handle_msvc_style_compiler() - - # Use updated __cplusplus macro - # https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus - target_compile_options(CpltCore PUBLIC /Zc:__cplusplus) - endif() -endif() +target_flag_exceptions(CpltCore ON) +target_flag_rtti(CpltCore OFF) +target_use_windows_subsystem(CpltCore) if(CMAKE_UNITY_BUILD) message("CpltCore: - using unity build") diff --git a/cmake/Exceptions.cmake b/cmake/Exceptions.cmake new file mode 100644 index 0000000..89e7e69 --- /dev/null +++ b/cmake/Exceptions.cmake @@ -0,0 +1,31 @@ +function(target_flag_exceptions_msvc TARGET_NAME ENABLED) + if(ENABLED) + target_compile_options(${TARGET_NAME} PRIVATE /EHsc) + else() + target_compile_options(${TARGET_NAME} PRIVATE /EH-) + endif() +endfunction() + +function(target_flag_exceptions_gcc TARGET_NAME ENABLED) + if(ENABLED) + target_compile_options(${TARGET_NAME} PRIVATE -fexceptions) + else() + target_compile_options(${TARGET_NAME} PRIVATE -fno-exceptions) + endif() +endfunction() + +function(target_flag_exceptions TARGET_NAME ENABLED) + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + target_flag_exceptions_msvc(${TARGET_NAME} ${ENABLED}) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC") + target_flag_exceptions_msvc(${TARGET_NAME} ${ENABLED}) + elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "GNU") + target_flag_exceptions_gcc(${TARGET_NAME} ${ENABLED}) + endif() + elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + target_flag_exceptions_gcc(${TARGET_NAME} ${ENABLED}) + else() + message(FATAL "target_flag_exceptions(): Unknown compiler ${CMAKE_CXX_COMPILER_ID}") + endif() +endfunction() diff --git a/cmake/RTTI.cmake b/cmake/RTTI.cmake new file mode 100644 index 0000000..b948497 --- /dev/null +++ b/cmake/RTTI.cmake @@ -0,0 +1,31 @@ +function(target_flag_rtti_msvc TARGET_NAME ENABLED) + if(ENABLED) + target_compile_options(${TARGET_NAME} PRIVATE /GR) + else() + target_compile_options(${TARGET_NAME} PRIVATE /GR-) + endif() +endfunction() + +function(target_flag_rtti_gcc TARGET_NAME ENABLED) + if(ENABLED) + target_compile_options(${TARGET_NAME} PRIVATE -frtti) + else() + target_compile_options(${TARGET_NAME} PRIVATE -fno-rtti) + endif() +endfunction() + +function(target_flag_rtti TARGET_NAME ENABLED) + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + target_flag_rtti_msvc(${TARGET_NAME} ${ENABLED}) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC") + target_flag_rtti_msvc(${TARGET_NAME} ${ENABLED}) + elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "GNU") + target_flag_rtti_gcc(${TARGET_NAME} ${ENABLED}) + endif() + elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + target_flag_rtti_gcc(${TARGET_NAME} ${ENABLED}) + else() + message(FATAL "target_flag_rtti(): Unknown compiler ${CMAKE_CXX_COMPILER_ID}") + endif() +endfunction() diff --git a/cmake/Win32Subsystem.cmake b/cmake/Win32Subsystem.cmake new file mode 100644 index 0000000..8546fd9 --- /dev/null +++ b/cmake/Win32Subsystem.cmake @@ -0,0 +1,31 @@ +function(target_use_windows_subsystem TARGET_NAME) + if(WIN32) + function(handle_msvc_style_compiler) + target_link_options(${TARGET_NAME} PRIVATE /SUBSYSTEM:windows /ENTRY:mainCRTStartup) + endfunction() + + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # GCC (MinGW) + # Supposedly the flag -mwindows would automatically make the executable use GUI subsystem + # But, when subsystem is set to GUI, linker will only search WinMain and wWinMain but not the standard main (it seems like) + # so creating GUI executable fails and the linker silently reverts to the default, CUI subsystem + target_link_options(${TARGET_NAME} PRIVATE -Wl,-subsystem,windows) + target_link_options(${TARGET_NAME} PRIVATE -Wl,-entry,mainCRTStartup) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + # MSVC-style argument clang (clang-cl.exe) + handle_msvc_style_compiler() + elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU") + # GNU-style argument clang (clang.exe and clang++.exe) + target_link_options(${TARGET_NAME} PRIVATE -Wl,-subsystem:windows) + target_link_options(${TARGET_NAME} PRIVATE -Wl,-entry:mainCRTStartup) + endif() + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + handle_msvc_style_compiler() + + # Use updated __cplusplus macro + # https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus + target_compile_options(${TARGET_NAME} PUBLIC /Zc:__cplusplus) + endif() + endif() +endfunction() |