2021-10-26 15:47:36 +08:00
|
|
|
cmake_minimum_required(VERSION 3.9)
|
2019-12-17 03:32:09 +08:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
|
2021-02-14 04:26:38 +08:00
|
|
|
project(SOEM
|
|
|
|
DESCRIPTION "Simple Open EtherCAT Master"
|
|
|
|
VERSION 1.4.0
|
|
|
|
LANGUAGES C)
|
2017-08-16 19:48:51 +08:00
|
|
|
|
|
|
|
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
|
|
|
# Default to installing in SOEM source directory
|
2019-12-17 03:32:09 +08:00
|
|
|
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/install)
|
2017-08-16 19:48:51 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(SOEM_INCLUDE_INSTALL_DIR include/soem)
|
2017-07-13 22:40:13 +08:00
|
|
|
set(SOEM_LIB_INSTALL_DIR lib)
|
2021-02-15 01:22:48 +08:00
|
|
|
|
|
|
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
|
|
set(BUILD_TESTS TRUE)
|
|
|
|
else()
|
|
|
|
message(STATUS "SOEM: not building tests when built as dependency")
|
|
|
|
set(BUILD_TESTS FALSE)
|
|
|
|
endif()
|
2017-08-16 19:48:51 +08:00
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
set(OS "win32")
|
|
|
|
include_directories(oshw/win32/wpcap/Include)
|
2018-02-23 04:12:59 +08:00
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
2019-12-17 03:32:09 +08:00
|
|
|
link_directories(${CMAKE_CURRENT_LIST_DIR}/oshw/win32/wpcap/Lib/x64)
|
2018-02-23 04:12:59 +08:00
|
|
|
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
2019-12-17 03:32:09 +08:00
|
|
|
link_directories(${CMAKE_CURRENT_LIST_DIR}/oshw/win32/wpcap/Lib)
|
2018-02-23 04:12:59 +08:00
|
|
|
endif()
|
2017-08-16 19:48:51 +08:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
|
|
|
|
set(OS_LIBS wpcap.lib Packet.lib Ws2_32.lib Winmm.lib)
|
2019-05-15 13:35:31 +08:00
|
|
|
elseif(UNIX AND NOT APPLE)
|
2017-08-16 19:48:51 +08:00
|
|
|
set(OS "linux")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
|
|
|
|
set(OS_LIBS pthread rt)
|
2019-05-15 13:35:31 +08:00
|
|
|
elseif(APPLE)
|
|
|
|
# This must come *before* linux or MacOSX will identify as Unix.
|
|
|
|
set(OS "macosx")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
|
|
|
|
set(OS_LIBS pthread pcap)
|
2017-08-16 19:48:51 +08:00
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "rt-kernel")
|
|
|
|
set(OS "rtk")
|
2021-02-19 01:11:29 +08:00
|
|
|
message(STATUS "ARCH is ${ARCH}")
|
|
|
|
message(STATUS "BSP is ${BSP}")
|
2017-08-16 19:48:51 +08:00
|
|
|
include_directories(oshw/${OS}/${ARCH})
|
|
|
|
file(GLOB OSHW_EXTRA_SOURCES oshw/${OS}/${ARCH}/*.c)
|
|
|
|
set(OSHW_SOURCES "${OS_HW_SOURCES} ${OSHW_ARCHSOURCES}")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-but-set-variable")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
|
|
|
|
set(OS_LIBS "-Wl,--start-group -l${BSP} -l${ARCH} -lkern -ldev -lsio -lblock -lfs -lusb -llwip -leth -li2c -lrtc -lcan -lnand -lspi -lnor -lpwm -ladc -ltrace -lc -lm -Wl,--end-group")
|
2017-07-13 22:40:13 +08:00
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "rtems")
|
2021-02-19 01:11:29 +08:00
|
|
|
message(STATUS "Building for RTEMS")
|
2017-07-13 22:40:13 +08:00
|
|
|
set(OS "rtems")
|
|
|
|
set(SOEM_LIB_INSTALL_DIR ${LIB_DIR})
|
2018-06-25 23:02:46 +08:00
|
|
|
set(BUILD_TESTS FALSE)
|
2017-08-16 19:48:51 +08:00
|
|
|
endif()
|
|
|
|
|
2021-02-19 01:11:29 +08:00
|
|
|
message(STATUS "OS is ${OS}")
|
2017-08-16 19:48:51 +08:00
|
|
|
|
|
|
|
file(GLOB SOEM_SOURCES soem/*.c)
|
|
|
|
file(GLOB OSAL_SOURCES osal/${OS}/*.c)
|
|
|
|
file(GLOB OSHW_SOURCES oshw/${OS}/*.c)
|
|
|
|
|
|
|
|
file(GLOB SOEM_HEADERS soem/*.h)
|
|
|
|
file(GLOB OSAL_HEADERS osal/osal.h osal/${OS}/*.h)
|
|
|
|
file(GLOB OSHW_HEADERS oshw/${OS}/*.h)
|
|
|
|
|
|
|
|
add_library(soem STATIC
|
|
|
|
${SOEM_SOURCES}
|
|
|
|
${OSAL_SOURCES}
|
|
|
|
${OSHW_SOURCES}
|
|
|
|
${OSHW_EXTRA_SOURCES})
|
|
|
|
target_link_libraries(soem ${OS_LIBS})
|
|
|
|
|
2019-09-23 22:14:26 +08:00
|
|
|
target_include_directories(soem PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/soem>
|
|
|
|
$<INSTALL_INTERFACE:include/soem>)
|
|
|
|
|
|
|
|
target_include_directories(soem PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/osal>
|
|
|
|
$<INSTALL_INTERFACE:include/soem>)
|
|
|
|
|
|
|
|
target_include_directories(soem PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/osal/${OS}>
|
|
|
|
$<INSTALL_INTERFACE:include/soem>)
|
|
|
|
|
|
|
|
target_include_directories(soem
|
|
|
|
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/oshw/${OS}>
|
|
|
|
$<INSTALL_INTERFACE:include/soem>
|
|
|
|
)
|
|
|
|
|
2021-02-19 01:11:29 +08:00
|
|
|
message(STATUS "LIB_DIR: ${SOEM_LIB_INSTALL_DIR}")
|
2017-07-13 22:40:13 +08:00
|
|
|
|
2019-09-23 22:14:26 +08:00
|
|
|
install(TARGETS soem EXPORT soemConfig DESTINATION ${SOEM_LIB_INSTALL_DIR})
|
|
|
|
|
2019-12-17 03:32:09 +08:00
|
|
|
install(EXPORT soemConfig DESTINATION share/soem/cmake)
|
2019-09-23 22:14:26 +08:00
|
|
|
|
2017-08-16 19:48:51 +08:00
|
|
|
install(FILES
|
|
|
|
${SOEM_HEADERS}
|
|
|
|
${OSAL_HEADERS}
|
|
|
|
${OSHW_HEADERS}
|
|
|
|
DESTINATION ${SOEM_INCLUDE_INSTALL_DIR})
|
|
|
|
|
2018-06-25 23:02:46 +08:00
|
|
|
if(BUILD_TESTS)
|
2021-02-25 17:01:21 +08:00
|
|
|
add_subdirectory(test/simple_ng)
|
2018-06-25 23:02:46 +08:00
|
|
|
add_subdirectory(test/linux/slaveinfo)
|
|
|
|
add_subdirectory(test/linux/eepromtool)
|
|
|
|
add_subdirectory(test/linux/simple_test)
|
|
|
|
endif()
|