Skip to content

Commit

Permalink
Make position independent code flag optional for static libraries (#27)
Browse files Browse the repository at this point in the history
* Make PIC optional for static libraries. Make compile definitions private

* Correct comment

* Remove note on fixed PIC
  • Loading branch information
pgreenland committed Feb 21, 2024
1 parent 8c25e8c commit 65e6167
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project(isotp LANGUAGES C VERSION 1.0.1 DESCRIPTION "A platform-agnostic ISOTP i

option(isotpc_USE_INCLUDE_DIR "Copy header files to separate include directory in current binary dir for better separation of header files to combat potential naming conflicts." OFF)
option(isotpc_STATIC_LIBRARY "Compile libisotpc as a static library, instead of a shared library." OFF)
option(isotpc_STATIC_LIBRARY_PIC "Make use of position independent code (PIC), when compiling as a static library (enabled automatically when building shared libraries)." OFF)
option(isotpc_PAD_CAN_FRAMES "Pad CAN frames to their full size." ON)
set(isotpc_CAN_FRAME_PAD_VALUE "0xAA" CACHE STRING "Padding byte value to be used in CAN frames if enabled")

Expand All @@ -20,13 +21,20 @@ endif()
# Strict building policies
###
target_compile_options(
isotp PUBLIC
-fPIC
isotp PRIVATE
-Werror
-Wall
-Wno-unknown-pragmas # ignore unknown pragmas, such as #pragma region
)

###
# Enable position independent code (PIC) if required
###
if (NOT isotpc_STATIC_LIBRARY OR isotpc_STATIC_LIBRARY_PIC)
# Building a shared library or a static library with PIC enabled
target_compile_options(isotp PRIVATE -fPIC)
endif()

###
# Provide padding configuration
###
Expand All @@ -38,10 +46,10 @@ endif()
# Check for debug builds
###
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(isotp PUBLIC -O0 -g) # don't optimise and add debugging symbols
target_compile_options(isotp PRIVATE -O0 -g) # don't optimise and add debugging symbols
else()
target_compile_options(isotp PUBLIC -O2) # optimise code
target_link_libraries(isotp PUBLIC -s) # strip the library
target_compile_options(isotp PRIVATE -O2) # optimise code
target_link_libraries(isotp PRIVATE -s) # strip the library
endif()

if (isotpc_USE_INCLUDE_DIR)
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ If your projects use a different build system, you are more than welcome to incl

The Makefile generator for isotpc will automatically detect whether or not your build system is using the `Debug` or `Release` build type and will adjust compiler parameters accordingly.

> **NOTE**: Regardless of build type, the library will be compiled as position-independant code.
#### Debug Build
If your project is configured to build as `Debug`, then the library will be compiled with **no** optimisations and **with** debug symbols.
`-DCMAKE_BUILD_TYPE=Debug`
Expand Down
2 changes: 1 addition & 1 deletion isotp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/* Private: Determines if by default, padding is added to ISO-TP message frames.
*/
//#define ISO_TP_FRAME_PADDING 0xAA
//#define ISO_TP_FRAME_PADDING

/* Private: Value to use when padding frames if enabled by ISO_TP_FRAME_PADDING
*/
Expand Down

0 comments on commit 65e6167

Please sign in to comment.