diff --git a/CMakeLists.txt b/CMakeLists.txt index 509755a4..4142a45e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -507,8 +507,17 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) # common flags set(MY_C_FLAGS -pipe -Wformat -Wformat-security -feliminate-unused-debug-types) - if(NOT CMAKE_BUILD_TYPE MATCHES Debug) - list(APPEND MY_C_FLAGS -D_FORTIFY_SOURCE=2) + if(ENABLE_SSP AND CMAKE_BUILD_TYPE STREQUAL Debug) + if(WIN32) + set(SSP_STATIC ON) + endif() + + find_package(SSP) + + if(SSP_LIBRARY) + list(APPEND MY_C_FLAGS -D_FORTIFY_SOURCE=2) + list(APPEND MY_C_LINKER_FLAGS ${SSP_LIBRARY}) + endif() endif() if(NOT (WIN32 OR X86_32)) # inline asm is not allowed with -fPIC @@ -603,18 +612,6 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) include(UseGCCBinUtilsWrappers) endif() - if(WIN32) - set(SSP_STATIC ON) - endif() - - if(ENABLE_SSP) - find_package(SSP) - - if(SSP_LIBRARY) - set(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} ${SSP_LIBRARY}) - endif() - endif() - set(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} -Wl,-allow-multiple-definition) if(CMAKE_PREFIX_PATH) diff --git a/cmake/HostCompile.cmake b/cmake/HostCompile.cmake index 2777e5c3..ef0b17ae 100644 --- a/cmake/HostCompile.cmake +++ b/cmake/HostCompile.cmake @@ -9,17 +9,21 @@ function(host_compile src dst_cmd) set(link_flags -Wl,--subsystem,console) endif() else() - set(dst "${dst_cmd}") + set(dst ${dst_cmd}) endif() # assume cc foo.c -o foo # will work on most hosts add_custom_command( - OUTPUT "${dst}" + OUTPUT ${dst} COMMAND cc ${src} -o ${dst} ${link_flags} - DEPENDS "${src}" + DEPENDS ${src} ) else() - get_filename_component(dst "${dst_cmd}" NAME) - add_executable("${dst}" "${src}") + get_filename_component(dst ${dst_cmd} NAME) + + add_executable(${dst} ${src}) + + # this is necessary because we override main with SDL_main + target_compile_definitions(${dst} PRIVATE -Dmain=main) endif() endfunction()