Skip to content

Commit

Permalink
feat(cmake): Use config.h to set the preprocessor device variables
Browse files Browse the repository at this point in the history
  • Loading branch information
marcfir committed Aug 20, 2024
1 parent 866d7b1 commit a13fdab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ find_package (Threads REQUIRED)
include_directories(${libosal_INCLUDE_DIRS} include)
link_directories(${libosal_LIB_DIR})

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


set(SRC_ETHERCAT
src/async_loop.c
src/coe.c
Expand Down Expand Up @@ -96,29 +93,31 @@ list(FIND ECAT_DEVICE "bpf" HAS_SOCK_BPF)
if (${HAS_SOCK_RAW} GREATER -1)
message("Include device sock_raw")
list(APPEND SRC_HW_LAYER src/hw_sock_raw.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_LEGACY)
set(LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_LEGACY 1)
endif()
if (${HAS_SOCK_RAW_MMAPED} GREATER -1)
message("Include device sock_raw_mmaped")
list(APPEND SRC_HW_LAYER src/hw_sock_raw_mmaped.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_MMAPED)
set(LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_MMAPED 1)
endif()
if (${HAS_SOCK_FILE} GREATER -1)
message("Include device file")
list(APPEND SRC_HW_LAYER src/hw_file.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_FILE)
set(LIBETHERCAT_BUILD_DEVICE_FILE 1)
endif()
if (${HAS_SOCK_PIKEOS} GREATER -1)
message("Include device pikeos")
list(APPEND SRC_HW_LAYER src/hw_pikeos.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_PIKEOS)
set(LIBETHERCAT_BUILD_DEVICE_PIKEOS 1)
endif()
if (${HAS_SOCK_BPF} GREATER -1)
message("Include device bpf")
list(APPEND SRC_HW_LAYER src/hw_bpf.c)
add_compile_definitions(LIBETHERCAT_BUILD_DEVICE_BPD)
set(LIBETHERCAT_BUILD_DEVICE_BPF 1)
endif()

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

# LIBS
add_library(ethercat ${SRC_ETHERCAT} ${SRC_HW_LAYER})
target_link_libraries (ethercat ${CMAKE_THREAD_LIBS_INIT} ${libosal_LIBS})
Expand Down
15 changes: 15 additions & 0 deletions cmake/cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@
/* Define to the version of this package. */
#cmakedefine LIBETHERCAT_VERSION "@LIBETHERCAT_VERSION@"

/* Define to build DEVICE_SOCK_RAW_LEGACY. */
#cmakedefine LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_LEGACY ${LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_LEGACY}

/* Define to build DEVICE_SOCK_RAW_MMAPED. */
#cmakedefine LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_MMAPED ${LIBETHERCAT_BUILD_DEVICE_SOCK_RAW_MMAPED}

/* Define to build DEVICE_FILE. */
#cmakedefine LIBETHERCAT_BUILD_DEVICE_FILE ${LIBETHERCAT_BUILD_DEVICE_FILE}

/* Define to build BUILD_DEVICE_PIKEOS. */
#cmakedefine LIBETHERCAT_BUILD_DEVICE_PIKEOS ${LIBETHERCAT_BUILD_DEVICE_PIKEOS}

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

/* 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 a13fdab

Please sign in to comment.