Skip to content

Commit

Permalink
Merge pull request #885 from slyshykO/check_ssp
Browse files Browse the repository at this point in the history
check if app's need for libssp.
  • Loading branch information
Nightwalker-87 authored Mar 21, 2020
2 parents 6dac7a3 + 784fdde commit 691647b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
29 changes: 19 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ if (STLINK_HAVE_UNISTD_H)
add_definitions(-DSTLINK_HAVE_UNISTD_H)
endif()

include(CheckLibraryExists)
CHECK_LIBRARY_EXISTS(ssp __stack_chk_fail "" _stack_chk_fail_exists)

if(_stack_chk_fail_exists)
set(SSP_LIB ssp)
else()
set(SSP_LIB "")
endif()

if (CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif()
Expand Down Expand Up @@ -135,13 +144,13 @@ if (APPLE)
find_library(ObjC objc)
find_library(CoreFoundation CoreFoundation)
find_library(IOKit IOKit)
target_link_libraries(${STLINK_LIB_SHARED} ${CoreFoundation} ${IOKit} ${ObjC})
target_link_libraries(${STLINK_LIB_SHARED} ${CoreFoundation} ${IOKit} ${ObjC} ${SSP_LIB})
endif()

if (WIN32 OR MSYS OR MINGW)
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} wsock32 ws2_32)
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} wsock32 ws2_32 ${SSP_LIB})
else()
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY})
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB})
endif()


Expand All @@ -164,13 +173,13 @@ if (APPLE)
find_library(ObjC objc)
find_library(CoreFoundation CoreFoundation)
find_library(IOKit IOKit)
target_link_libraries(${STLINK_LIB_STATIC} ${CoreFoundation} ${IOKit} ${ObjC})
target_link_libraries(${STLINK_LIB_STATIC} ${CoreFoundation} ${IOKit} ${ObjC} ${SSP_LIB})
endif()

if (WIN32 OR MSYS OR MINGW)
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} wsock32 ws2_32)
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} wsock32 ws2_32 ${SSP_LIB})
else()
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY})
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB})
endif()

set_target_properties(${STLINK_LIB_STATIC} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
Expand All @@ -186,16 +195,16 @@ endif()
###
add_executable(st-flash src/tools/flash.c src/tools/flash_opts.c)
if (WIN32 OR APPLE)
target_link_libraries(st-flash ${STLINK_LIB_STATIC})
target_link_libraries(st-flash ${STLINK_LIB_STATIC} ${SSP_LIB})
else()
target_link_libraries(st-flash ${STLINK_LIB_SHARED})
target_link_libraries(st-flash ${STLINK_LIB_SHARED} ${SSP_LIB})
endif()

add_executable(st-info src/tools/info.c)
if (WIN32 OR APPLE)
target_link_libraries(st-info ${STLINK_LIB_STATIC})
target_link_libraries(st-info ${STLINK_LIB_STATIC} ${SSP_LIB})
else()
target_link_libraries(st-info ${STLINK_LIB_SHARED})
target_link_libraries(st-info ${STLINK_LIB_SHARED} ${SSP_LIB})
endif()

install(TARGETS st-flash st-info
Expand Down
4 changes: 2 additions & 2 deletions src/gdbserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ endif()
add_executable(st-util ${STUTIL_SOURCE})

if (WIN32 OR APPLE)
target_link_libraries(st-util ${STLINK_LIB_STATIC})
target_link_libraries(st-util ${STLINK_LIB_STATIC} ${SSP_LIB})
else()
target_link_libraries(st-util ${STLINK_LIB_SHARED})
target_link_libraries(st-util ${STLINK_LIB_SHARED} ${SSP_LIB})
endif()

install(TARGETS st-util
Expand Down
4 changes: 2 additions & 2 deletions src/tools/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ include_directories(SYSTEM ${gtk_INCLUDE_DIRS})
add_executable(stlink-gui-local ${GUI_SOURCES})
set_target_properties(stlink-gui-local PROPERTIES
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(stlink-gui-local ${STLINK_LIB_STATIC} ${gtk_LDFLAGS})
target_link_libraries(stlink-gui-local ${STLINK_LIB_STATIC} ${gtk_LDFLAGS} ${SSP_LIB})


add_executable(stlink-gui ${GUI_SOURCES})
set_target_properties(stlink-gui PROPERTIES
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_PREFIX}/${INSTALLED_UI_DIR}")
target_link_libraries(stlink-gui ${STLINK_LIB_STATIC} ${gtk_LDFLAGS})
target_link_libraries(stlink-gui ${STLINK_LIB_STATIC} ${gtk_LDFLAGS} ${SSP_LIB})

install(TARGETS stlink-gui
RUNTIME DESTINATION bin)
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ set(TESTS
foreach(test ${TESTS})
add_executable(${test} ${test}.c)
add_dependencies(${test} ${STLINK_LIB_STATIC})
target_link_libraries(${test} ${STLINK_LIB_STATIC})
target_link_libraries(${test} ${STLINK_LIB_STATIC} ${SSP_LIB})
add_test(${test} ${CMAKE_CURRENT_BINARY_DIR}/${test})
endforeach()

add_executable(flash flash.c "${CMAKE_SOURCE_DIR}/src/tools/flash_opts.c")
target_link_libraries(flash ${STLINK_LIB_STATIC})
target_link_libraries(flash ${STLINK_LIB_STATIC} ${SSP_LIB})
add_test(flash ${CMAKE_CURRENT_BINARY_DIR}/flash)

0 comments on commit 691647b

Please sign in to comment.