Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactoring] General maintenance #978

Merged
merged 6 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 62 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)


###
# General project settings
###
Expand Down Expand Up @@ -48,29 +49,34 @@ endif ()
find_package(libusb REQUIRED)

## Check for system-specific additional header files and libraries

include(CheckIncludeFile)
include(CheckLibraryExists)

CHECK_LIBRARY_EXISTS(ssp __stack_chk_fail "" _stack_chk_fail_exists)
if (_stack_chk_fail_exists)
if (WIN32)
set(SSP_LIB -static ssp)
else ()
set(SSP_LIB ssp)
endif ()
else ()
set(SSP_LIB "")
endif ()

CHECK_INCLUDE_FILE(sys/mman.h STLINK_HAVE_SYS_MMAN_H)
if (STLINK_HAVE_SYS_MMAN_H)
add_definitions(-DSTLINK_HAVE_SYS_MMAN_H)
endif ()
endif()

CHECK_INCLUDE_FILE(unistd.h STLINK_HAVE_UNISTD_H)
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)
if(WIN32)
set(SSP_LIB -static ssp)
else()
set(SSP_LIB ssp)
endif()
else ()
set(SSP_LIB "")
if (MSVC)
# Use string.h rather than strings.h and disable annoying warnings
add_definitions(-DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS /wd4710)
endif ()


Expand All @@ -81,50 +87,53 @@ endif ()
## Define include directories to avoid absolute paths for header defines
include_directories(${LIBUSB_INCLUDE_DIR})

# ====
include_directories(${PROJECT_SOURCE_DIR}/include) ### TODO: Clean this up...
include_directories(${PROJECT_BINARY_DIR}/include/stlink)
include_directories(${PROJECT_SOURCE_DIR}/include/stlink)
include_directories(${PROJECT_SOURCE_DIR}/include/stlink/tools)
# ====
include_directories(${PROJECT_SOURCE_DIR}/inc) # contains top-level header files
include_directories(${PROJECT_BINARY_DIR}/inc) # contains version.h

include_directories(src)
include_directories(src/tools) ### TODO: Clean this up...
include_directories(src/st-flash)
include_directories(src/stlink-lib)

set(STLINK_HEADERS
include/stlink.h
include/stlink/backend.h
include/stlink/chipid.h
include/stlink/commands.h
include/stlink/flash_loader.h
include/stlink/reg.h
src/logging.h
src/md5.h
src/sg.h
src/usb.h
inc/backend.h
src/stlink-lib/commands.h
src/stlink-lib/libusb_settings.h
src/stlink-lib/reg.h
inc/stlink.h
src/stlink-lib/chipid.h
src/stlink-lib/flash_loader.h
src/stlink-lib/logging.h
src/stlink-lib/md5.h
src/stlink-lib/sg.h
src/stlink-lib/usb.h
)

set(STLINK_SOURCE
src/common.c
src/chipid.c
src/flash_loader.c
src/logging.c
src/md5.c
src/sg.c
src/usb.c
src/stlink-lib/chipid.c
src/stlink-lib/flash_loader.c
src/stlink-lib/logging.c
src/stlink-lib/md5.c
src/stlink-lib/sg.c
src/stlink-lib/usb.c
)

if (WIN32 OR MINGW OR MSYS)
include_directories(src/mingw)
set(STLINK_SOURCE "${STLINK_SOURCE};src/mmap.c;src/mingw/mingw.c")
set(STLINK_HEADERS "${STLINK_HEADERS};src/mmap.h;src/mingw/mingw.h")
endif ()

if (MSVC)
if (WIN32)
include_directories(src/win32)
include_directories(src/getopt)
# Use string.h rather than strings.h and disable annoying warnings
add_definitions(-DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS /wd4710)
set(STLINK_SOURCE "${STLINK_SOURCE};src/win32/win32_socket.c")
set(STLINK_HEADERS "${STLINK_HEADERS};src/win32/win32_socket.h")

if (MSVC)
# Add drop-in replacement for unistd.h to sources
include_directories(src/win32/unistd)
set(STLINK_HEADERS "${STLINK_HEADERS};src/win32/unistd/unistd.h")
endif ()

if (NOT STLINK_HAVE_SYS_MMAN_H)
include_directories(src/win32/mmap)
set(STLINK_SOURCE "${STLINK_SOURCE};src/win32/mmap.c")
set(STLINK_HEADERS "${STLINK_HEADERS};src/win32/mmap.h")
endif()
endif ()

## Include test execution for test-targets for target Debug
Expand All @@ -140,7 +149,7 @@ endif ()
set(STLINK_LIBRARY_PATH ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Main library install directory")

# Set the environment variable LD_LIBRARY_PATH to point to /usr/local/lib (per default).
execute_process (COMMAND bash -c "export LD_LIBRARY_PATH="${CMAKE_INSTALL_LIBDIR}" ")
execute_process (COMMAND bash -c "export LD_LIBRARY_PATH=${CMAKE_INSTALL_LIBDIR}")


###
Expand Down Expand Up @@ -221,15 +230,18 @@ install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH})
# Build toolset executables
###

set(ST-FLASH_SOURCES src/st-flash/flash.c src/st-flash/flash_opts.c)
set(ST-INFO_SOURCES src/st-info/info.c)
set(ST-UTIL_SOURCES src/st-util/gdb-remote.c src/st-util/gdb-server.c src/st-util/semihosting.c)

if (MSVC)
# Add getopt to sources
set(ST-UTIL_SOURCES "${ST-UTIL_SOURCES};src/getopt/getopt.c")
include_directories(src/win32/getopt)
set(ST-UTIL_SOURCES "${ST-UTIL_SOURCES};src/win32/getopt/getopt.c")
endif ()

add_executable(st-flash src/tools/flash.c src/tools/flash_opts.c)
add_executable(st-info src/tools/info.c)
add_executable(st-flash ${ST-FLASH_SOURCES})
add_executable(st-info ${ST-INFO_SOURCES})
add_executable(st-util ${ST-UTIL_SOURCES})

if (WIN32 OR APPLE)
Expand Down Expand Up @@ -267,11 +279,7 @@ endif ()
# Additional build tasks
###

# ====
add_subdirectory(include) # contains subordinate CMakeLists for version config and old header includes
### TODO: Clean this up ...
# ====

add_subdirectory(inc) # contains subordinate CMakeLists for version config
add_subdirectory(src/stlink-gui) # contains subordinate CMakeLists to build GUI
add_subdirectory(tests) # contains subordinate CMakeLists to build test executables
add_subdirectory(cmake/packaging) # contains subordinate CMakeLists to build packages
Expand Down
1 change: 1 addition & 0 deletions cmake/modules/c_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function(add_cflag_if_supported flag)
endfunction()

add_cflag_if_supported("-std=gnu11")
add_cflag_if_supported("-std=gnu18")
add_cflag_if_supported("-Wall")
add_cflag_if_supported("-Wextra")
add_cflag_if_supported("-Wshadow")
Expand Down
Loading