Skip to content

Commit

Permalink
Merge pull request #17 from marcfir/master
Browse files Browse the repository at this point in the history
Set correct preprocessor defines in CMake
  • Loading branch information
robert-burger authored Aug 27, 2024
2 parents cee6500 + 6c0b793 commit b45539c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
37 changes: 32 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ string(REGEX MATCH "VERSION = ([0-9]*.[0-9]*.[0-9]*)" _ ${PROJECT_PROPERTIES})
set(PROJECT_VERSION ${CMAKE_MATCH_1})
project(libethercat VERSION ${PROJECT_VERSION})


option(MBX_SUPPORT_COE "Flag to enable or disable Mailbox CoE support" ON)
option(MBX_SUPPORT_FOE "Flag to enable or disable Mailbox FoE support" ON)
option(MBX_SUPPORT_SOE "Flag to enable or disable Mailbox SoE support" ON)
option(MBX_SUPPORT_EOE "Flag to enable or disable Mailbox EoE support" ON)
set(ECAT_DEVICE "sock_raw" CACHE STRING "EtherCAT device layer as `+` separated list")
string(REPLACE "+" ";" ECAT_DEVICE ${ECAT_DEVICE})

Expand Down Expand Up @@ -65,24 +70,21 @@ find_package (Threads REQUIRED)

include_directories(${libosal_INCLUDE_DIRS} include)
link_directories(${libosal_LIB_DIR})
check_symbol_exists("LIBOSAL_BUILD_POSIX" "libosal/config.h" LIBETHERCAT_BUILD_POSIX)

set(SRC_ETHERCAT
src/async_loop.c
src/coe.c
src/coe_master.c
src/datagram.c
src/dc.c
src/ec.c
src/eeprom.c
src/eoe.c
src/foe.c
src/hw.c
src/idx.c
src/mbx.c
src/mii.c
src/pool.c
src/slave.c
src/soe.c)
)

list(FIND ECAT_DEVICE "sock_raw" HAS_SOCK_RAW)
list(FIND ECAT_DEVICE "sock_raw_mmaped" HAS_SOCK_RAW_MMAPED)
Expand Down Expand Up @@ -116,6 +118,26 @@ if (${HAS_SOCK_BPF} GREATER -1)
set(LIBETHERCAT_BUILD_DEVICE_BPF 1)
endif()

if(${MBX_SUPPORT_COE})
set(LIBETHERCAT_MBX_SUPPORT_COE 1)
list(APPEND SRC_ETHERCAT src/coe.c src/coe_master.c)
endif()

if(${MBX_SUPPORT_FOE})
set(LIBETHERCAT_MBX_SUPPORT_FOE 1)
list(APPEND SRC_ETHERCAT src/foe.c)
endif()

if(${MBX_SUPPORT_SOE})
set(LIBETHERCAT_MBX_SUPPORT_SOE 1)
list(APPEND SRC_ETHERCAT src/soe.c)
endif()

if(${MBX_SUPPORT_EOE})
set(LIBETHERCAT_MBX_SUPPORT_EOE 1)
list(APPEND SRC_ETHERCAT src/eoe.c)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/libethercat/config.h)

# LIBS
Expand All @@ -132,6 +154,11 @@ target_link_libraries (ethercatdiag ethercat ${libosal_LIBS})
add_executable(example_with_dc tools/example_with_dc/example_with_dc.c)
target_link_libraries (example_with_dc ethercat ${libosal_LIBS} m)

if (${MBX_SUPPORT_FOE})
add_executable(foe_tool tools/foe_tool/foe_tool.c)
target_link_libraries (foe_tool ethercat ${libosal_LIBS})
endif()

# Install
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/libethercatConfigVersion.cmake
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ cmake --build .
| CMAKE_PREFIX_PATH | | Install directory of the libosal |
| ECAT_DEVICE | sock_raw | List of EtherCAT devices as `+` separated list. Possible values: sock_raw+sock_raw_mmaped+file+pikeos+bpf |
| BUILD_SHARED_LIBS | OFF | Flag to build shared libraries instead of static ones. |
| MBX_SUPPORT_COE | ON | Flag to enable or disable Mailbox CoE support
| MBX_SUPPORT_FOE | ON | Flag to enable or disable Mailbox FoE support
| MBX_SUPPORT_SOE | ON | Flag to enable or disable Mailbox SoE support
| MBX_SUPPORT_EOE | ON | Flag to enable or disable Mailbox EoE support

## Tools

Expand Down
17 changes: 16 additions & 1 deletion cmake/cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,24 @@
/* Define to build BUILD_DEVICE_PIKEOS. */
#cmakedefine LIBETHERCAT_BUILD_DEVICE_PIKEOS ${LIBETHERCAT_BUILD_DEVICE_PIKEOS}

/* Define to build BUILD_DEVICE_BPD. */
/* Define to build BUILD_DEVICE_BPF. */
#cmakedefine LIBETHERCAT_BUILD_DEVICE_BPF ${LIBETHERCAT_BUILD_DEVICE_BPF}

/* Define to build LIBETHERCAT_BUILD_POSIX. */
#cmakedefine LIBETHERCAT_BUILD_POSIX ${LIBETHERCAT_BUILD_POSIX}

/* Define to build LIBETHERCAT_MBX_SUPPORT_COE. */
#cmakedefine LIBETHERCAT_MBX_SUPPORT_COE ${LIBETHERCAT_MBX_SUPPORT_COE}

/* Define to build LIBETHERCAT_MBX_SUPPORT_SOE. */
#cmakedefine LIBETHERCAT_MBX_SUPPORT_SOE ${LIBETHERCAT_MBX_SUPPORT_SOE}

/* Define to build LIBETHERCAT_MBX_SUPPORT_FOE. */
#cmakedefine LIBETHERCAT_MBX_SUPPORT_FOE ${LIBETHERCAT_MBX_SUPPORT_FOE}

/* Define to build LIBETHERCAT_MBX_SUPPORT_EOE. */
#cmakedefine LIBETHERCAT_MBX_SUPPORT_EOE ${LIBETHERCAT_MBX_SUPPORT_EOE}

/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
#undef PTHREAD_CREATE_JOINABLE
Expand Down

0 comments on commit b45539c

Please sign in to comment.