From 6c0b7932ab5aeded456bfa44f7fc4988bed16be0 Mon Sep 17 00:00:00 2001 From: marcfir Date: Mon, 26 Aug 2024 13:33:57 +0000 Subject: [PATCH] fix(cmake): Set correct preprocessor defines in CMake to enable/disable mbx functions --- CMakeLists.txt | 37 ++++++++++++++++++++++++++++++++----- README.md | 4 ++++ cmake/cmake_config.h.in | 17 ++++++++++++++++- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 678b1b4..657eae1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) @@ -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) @@ -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 @@ -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 diff --git a/README.md b/README.md index 64b7191..8401501 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmake/cmake_config.h.in b/cmake/cmake_config.h.in index 91d7373..2816a91 100644 --- a/cmake/cmake_config.h.in +++ b/cmake/cmake_config.h.in @@ -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