Skip to content

Commit

Permalink
Formatting & style fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightwalker-87 committed Jun 24, 2023
1 parent b72f5b5 commit 101d77b
Show file tree
Hide file tree
Showing 26 changed files with 402 additions and 404 deletions.
36 changes: 18 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ else ()
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif ()
endif()


###
Expand All @@ -111,10 +111,10 @@ if (_stack_chk_fail_exists)
set(SSP_LIB -static ssp)
else ()
set(SSP_LIB ssp)
endif ()
endif()
else ()
set(SSP_LIB "")
endif ()
endif()

CHECK_INCLUDE_FILE(sys/mman.h STLINK_HAVE_SYS_MMAN_H)
if (STLINK_HAVE_SYS_MMAN_H)
Expand All @@ -129,17 +129,17 @@ endif()
CHECK_INCLUDE_FILE(unistd.h STLINK_HAVE_UNISTD_H)
if (STLINK_HAVE_UNISTD_H)
add_definitions(-DSTLINK_HAVE_UNISTD_H)
endif ()
endif()

CHECK_INCLUDE_FILE(dirent.h STLINK_HAVE_DIRENT_H)
if (STLINK_HAVE_DIRENT_H)
add_definitions(-DSTLINK_HAVE_DIRENT_H)
endif ()
endif()

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 ()
endif()


###
Expand All @@ -164,7 +164,7 @@ if (WIN32)
set(STLINK_INCLUDE_PATH ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Main include install directory")
else ()
set(STLINK_INCLUDE_PATH ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} CACHE PATH "Main include install directory")
endif ()
endif()

## Subordinate CMakeLists for version config & header installation
add_subdirectory(inc)
Expand Down Expand Up @@ -218,7 +218,7 @@ if (WIN32)
# 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 ()
endif()

if (NOT STLINK_HAVE_SYS_MMAN_H)
include_directories(src/win32/mmap)
Expand All @@ -230,12 +230,12 @@ if (WIN32)
set(STLINK_SOURCE "${STLINK_SOURCE};src/win32/sys_time.c")
set(STLINK_HEADERS "${STLINK_HEADERS};src/win32/sys_time.h")
endif()
endif ()
endif()

## Include test execution for test-targets for target Debug
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
include(CTest)
endif ()
endif()


###
Expand Down Expand Up @@ -271,7 +271,7 @@ if (WIN32) # ... with Windows libraries
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB} wsock32 ws2_32)
else ()
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB})
endif ()
endif()

install(TARGETS ${STLINK_LIB_SHARED}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand All @@ -285,7 +285,7 @@ file(COPY ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW64/dll/libusb-1.0.dll
DESTINATION ${CMAKE_INSTALL_BINDIR})
file(COPY ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW64/dll/libusb-1.0.dll
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
endif ()
endif()


###
Expand Down Expand Up @@ -317,7 +317,7 @@ if (WIN32) # ... with Windows libraries
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB} wsock32 ws2_32)
else ()
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB})
endif ()
endif()

install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

Expand All @@ -336,7 +336,7 @@ if (MSVC)
include_directories(src/win32/getopt)
set(ST-UTIL_SOURCES "${ST-UTIL_SOURCES};src/win32/getopt/getopt.c")
set(ST-TRACE_SOURCES "${ST-TRACE_SOURCES};src/win32/getopt/getopt.c")
endif ()
endif()

add_executable(st-flash ${ST-FLASH_SOURCES})
add_executable(st-info ${ST-INFO_SOURCES})
Expand All @@ -353,7 +353,7 @@ else ()
target_link_libraries(st-info ${STLINK_LIB_SHARED} ${SSP_LIB})
target_link_libraries(st-util ${STLINK_LIB_SHARED} ${SSP_LIB})
target_link_libraries(st-trace ${STLINK_LIB_SHARED} ${SSP_LIB})
endif ()
endif()

install(TARGETS st-flash DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS st-info DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand All @@ -374,7 +374,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(STLINK_UDEV_RULES_DIR "/lib/udev/rules.d" CACHE PATH "udev rules directory")
file(GLOB RULES_FILES ${CMAKE_SOURCE_DIR}/config/udev/rules.d/*.rules)
install(FILES ${RULES_FILES} DESTINATION ${STLINK_UDEV_RULES_DIR})
endif ()
endif()


###
Expand All @@ -386,7 +386,7 @@ if (WIN32)
set(CMAKE_CHIPS_DIR ${CMAKE_INSTALL_PREFIX}/config/chips)
else ()
set(CMAKE_CHIPS_DIR ${CMAKE_INSTALL_SHAREDIR}/${PROJECT_NAME}/chips)
endif ()
endif()
add_definitions( -DSTLINK_CHIPS_DIR="${CMAKE_CHIPS_DIR}" )
file(GLOB CHIP_FILES ${CMAKE_SOURCE_DIR}/config/chips/*.chip)
install(FILES ${CHIP_FILES} DESTINATION ${CMAKE_CHIPS_DIR})
Expand All @@ -413,4 +413,4 @@ if (NOT TARGET uninstall)
uninstall COMMAND ${CMAKE_COMMAND}
-P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake
)
endif ()
endif()
18 changes: 9 additions & 9 deletions cmake/modules/Findlibusb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") # FreeBSD; libusb is
mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY)
if (NOT LIBUSB_FOUND)
message(FATAL_ERROR "Expected libusb library not found on your system! Verify your system integrity.")
endif ()
endif()

elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") # OpenBSD; libusb-1.0 is available from ports
FIND_PATH(
Expand All @@ -41,7 +41,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") # OpenBSD; libusb-1.0
mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY)
if (NOT LIBUSB_FOUND)
message(FATAL_ERROR "No libusb-1.0 library found on your system! Install libusb-1.0 from ports or packages.")
endif ()
endif()

elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-toolchain on Debian
# MinGW/MSYS/MSVC: 64-bit or 32-bit?
Expand All @@ -51,7 +51,7 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to
else ()
message(STATUS "=== Building for Windows (i686) ===")
set(ARCH 32)
endif ()
endif()

if (WIN32 AND NOT EXISTS "/etc/debian_version") # Skip this for Debian...
# Preparations for installing libusb library
Expand All @@ -63,7 +63,7 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to
elseif (EXISTS "/etc/debian_version" AND MINGW) # ... only for cross-building on Debian
set(LIBUSB_WIN_ARCHIVE_PATH ${CMAKE_SOURCE_DIR}/build-mingw-${ARCH}/${LIBUSB_WIN_ARCHIVE})
set(LIBUSB_WIN_OUTPUT_FOLDER ${CMAKE_SOURCE_DIR}/build-mingw-${ARCH}/3rdparty/libusb-${LIBUSB_WIN_VERSION})
endif ()
endif()

# Get libusb package
if (EXISTS ${LIBUSB_WIN_ARCHIVE_PATH}) # ... should the package be already there (for whatever reason)
Expand All @@ -74,7 +74,7 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to
https://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-${LIBUSB_WIN_VERSION}/libusb-${LIBUSB_WIN_VERSION}.7z/download
${LIBUSB_WIN_ARCHIVE_PATH} EXPECTED_MD5 aabe177bde869bfad34278335eaf8955
)
endif ()
endif()

file(MAKE_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER})

Expand Down Expand Up @@ -110,9 +110,9 @@ elseif (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)) # Windows or MinGW-to
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
endif ()
endif()
message(STATUS "Missing libusb library has been installed")
endif ()
endif()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(libusb DEFAULT_MSG LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR)
mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY)

Expand All @@ -132,5 +132,5 @@ else ()

if (NOT LIBUSB_FOUND)
message(FATAL_ERROR "libusb library not found on your system! Install libusb 1.0.x from your package repository.")
endif ()
endif ()
endif()
endif()
8 changes: 4 additions & 4 deletions cmake/modules/c_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(add_cflag_if_supported flag)

if (C_SUPPORTS${flagclean})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
endif ()
endif()
endfunction()

add_cflag_if_supported("-Wall")
Expand All @@ -38,14 +38,14 @@ add_cflag_if_supported("-Wimplicit-function-declaration")
##
if (NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
add_cflag_if_supported("-Wredundant-decls")
endif ()
endif()

if (NOT (WIN32 OR (EXISTS "/etc/debian_version" AND MINGW)))
add_cflag_if_supported("-fPIC")
endif ()
endif()

if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
add_cflag_if_supported("-ggdb")
else ()
add_cflag_if_supported("-Werror")
endif ()
endif()
16 changes: 8 additions & 8 deletions cmake/modules/get_version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
)
if (res EQUAL 1)
set(PROJECT_VERSION "${PROJECT_VERSION}-dirty")
endif ()
endif()

# Strip a leading v off of the version as proceeding code expects just the version numbering.
string(REGEX REPLACE "^v" "" PROJECT_VERSION ${PROJECT_VERSION})
Expand All @@ -53,28 +53,28 @@ if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# ...the version does not match with git-version string
if (NOT __version_str STREQUAL __version_file)
message(STATUS "Rewrite ${PROJECT_SOURCE_DIR}/.version with ${__version_str}!")
endif ()
endif()

elseif (NOT EXISTS "${PROJECT_SOURCE_DIR}/.version")

# No local .version file found: Create a new one...
file(WRITE "${PROJECT_SOURCE_DIR}/.version" ${__version_str})

endif ()
endif()

message(STATUS "stlink version: ${PROJECT_VERSION}")
message(STATUS "Major ${PROJECT_VERSION_MAJOR} Minor ${PROJECT_VERSION_MINOR} Patch ${PROJECT_VERSION_PATCH}")

else (len EQUAL 3)
message(STATUS "Failed to extract version parts from \"${PROJECT_VERSION}\"")
set(ERROR_FLAG "1")
endif (len EQUAL 3)
endif(len EQUAL 3)

else (GIT_DESCRIBE_RESULT EQUAL 0)
message(WARNING "git describe failed: ${GIT_DESCRIBE_ERROR}")
set(ERROR_FLAG "1")
endif(GIT_DESCRIBE_RESULT EQUAL 0)
endif ()
endif()

##
# Failure to read version via git
Expand All @@ -101,9 +101,9 @@ if (NOT GIT_FOUND OR NOT EXISTS "${PROJECT_SOURCE_DIR}/.git" OR ERROR_FLAG EQUAL
set(__detect_version 1)
else ()
message(STATUS "Fail to extract version parts from \"${PROJECT_VERSION}\"")
endif ()
endif()
else (EXISTS ${PROJECT_SOURCE_DIR}/.version)
message(STATUS "File \"${PROJECT_SOURCE_DIR}/.version\" does not exist.")
message(FATAL_ERROR "Unable to determine project version")
endif ()
endif ()
endif()
endif()
Loading

0 comments on commit 101d77b

Please sign in to comment.