cmake: fix linking to libssp and linking bin2c

Only add the macro `-D_FORTIFY_SOURCE=2` if we are linking to libssp
with gcc, do not use it at all on clang.

For `HostCompile.cmake` add the macro `-Dmain=main` to redefine the
macro added by SDL2 to compile flags `-Dmain=SDL_main`.

Fix #548.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2019-10-17 21:53:15 +00:00
parent eaa744cc2e
commit 36790074c3
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
2 changed files with 20 additions and 19 deletions

View File

@ -507,8 +507,17 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
# common flags # common flags
set(MY_C_FLAGS -pipe -Wformat -Wformat-security -feliminate-unused-debug-types) set(MY_C_FLAGS -pipe -Wformat -Wformat-security -feliminate-unused-debug-types)
if(NOT CMAKE_BUILD_TYPE MATCHES Debug) if(ENABLE_SSP AND CMAKE_BUILD_TYPE STREQUAL Debug)
list(APPEND MY_C_FLAGS -D_FORTIFY_SOURCE=2) 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() endif()
if(NOT (WIN32 OR X86_32)) # inline asm is not allowed with -fPIC 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) include(UseGCCBinUtilsWrappers)
endif() 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) set(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} -Wl,-allow-multiple-definition)
if(CMAKE_PREFIX_PATH) if(CMAKE_PREFIX_PATH)

View File

@ -9,17 +9,21 @@ function(host_compile src dst_cmd)
set(link_flags -Wl,--subsystem,console) set(link_flags -Wl,--subsystem,console)
endif() endif()
else() else()
set(dst "${dst_cmd}") set(dst ${dst_cmd})
endif() endif()
# assume cc foo.c -o foo # will work on most hosts # assume cc foo.c -o foo # will work on most hosts
add_custom_command( add_custom_command(
OUTPUT "${dst}" OUTPUT ${dst}
COMMAND cc ${src} -o ${dst} ${link_flags} COMMAND cc ${src} -o ${dst} ${link_flags}
DEPENDS "${src}" DEPENDS ${src}
) )
else() else()
get_filename_component(dst "${dst_cmd}" NAME) get_filename_component(dst ${dst_cmd} NAME)
add_executable("${dst}" "${src}")
add_executable(${dst} ${src})
# this is necessary because we override main with SDL_main
target_compile_definitions(${dst} PRIVATE -Dmain=main)
endif() endif()
endfunction() endfunction()