Skip to content

Commit f7a6edb

Browse files
authored
Make os_types.h private (#167)
* add ENABLE_ESI_PARSER compile options
1 parent 17b38e0 commit f7a6edb

File tree

10 files changed

+99
-20
lines changed

10 files changed

+99
-20
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_BINARY_DIR})
88
include(Config)
99
include(debug)
1010

11+
option(ENABLE_ESI_PARSER "Enable Esi Parser" ON)
1112
add_subdirectory(lib)
1213

1314
option(BUILD_UNIT_TESTS "Build unit tests" OFF)
@@ -84,3 +85,5 @@ if (BUILD_TOOLS)
8485
add_subdirectory(tools)
8586
endif()
8687
endif()
88+
89+

conanfile.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
3+
from conan.tools.files import get, copy
4+
import os
5+
6+
required_conan_version = ">=1.55"
7+
8+
class KickCATRecipe(ConanFile):
9+
name = "kickcat"
10+
url = "https://github.com/conan-io/conan-center-index"
11+
homepage = "https://github.com/Siviuze/KickCAT"
12+
description = "Thin EtherCAT stack designed to be embedded in a more complex software and with efficiency in mind"
13+
license = "CeCILL-C"
14+
topics = ("ethercat")
15+
settings = "os", "compiler", "build_type", "arch"
16+
options = {"shared": [True, False], "fPIC": [True, False], "with_esi_parser": [True, False]}
17+
default_options = {"shared": False, "fPIC": True, "with_esi_parser": False}
18+
19+
# Sources are located in the same place as this recipe, copy them to the recipe
20+
exports_sources = "CMakeLists.txt", "lib/*", "examples/*", "cmake/*"
21+
22+
# def source(self):
23+
# get(self, **self.conan_data["sources"][self.version])
24+
25+
def config_options(self):
26+
if self.settings.os == "Windows":
27+
del self.options.fPIC
28+
29+
def layout(self):
30+
cmake_layout(self)
31+
32+
def generate(self):
33+
tc = CMakeToolchain(self)
34+
tc.variables["ENABLE_ESI_PARSER"] = bool(self.options.with_esi_parser)
35+
tc.generate()
36+
37+
deps = CMakeDeps(self)
38+
deps.generate()
39+
40+
def requirements(self):
41+
if self.options.with_esi_parser:
42+
self.requires("tinyxml2/10.0.0")
43+
44+
def build(self):
45+
cmake = CMake(self)
46+
cmake.configure(variables={"BUILD_UNIT_TESTS": "OFF",
47+
"BUILD_EXAMPLES": "OFF",
48+
"BUILD_SIMULATION": "OFF",
49+
"BUILD_TOOLS": "OFF"})
50+
cmake.build()
51+
52+
def package(self):
53+
src_folders = ["lib/include", "lib/slave/include", "lib/slave/driver/include", "lib/master/include"]
54+
for folder in src_folders:
55+
copy(self, "*.h", os.path.join(self.source_folder, folder),
56+
os.path.join(self.package_folder, "include"))
57+
58+
copy(self, "*.a", self.build_folder,
59+
os.path.join(self.package_folder, "lib"), keep_path=False)
60+
copy(self, "*.so", self.build_folder,
61+
os.path.join(self.package_folder, "lib"), keep_path=False)
62+
63+
def package_info(self):
64+
self.cpp_info.libs = ["kickcat"]
65+
66+

examples/master/load_esi/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
get_property(OK_TO_BUILD GLOBAL PROPERTY ESI_AVAILABLE)
2-
if (OK_TO_BUILD)
1+
if (ENABLE_ESI_PARSER)
32
add_executable(load_esi load_esi.cc ${OS_SRCS})
43
target_include_directories(load_esi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
54
target_link_libraries(load_esi common kickcat)

lib/CMakeLists.txt

+11-12
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@ set(KICKCAT_SOURCES
1414
${CMAKE_CURRENT_SOURCE_DIR}/src/CoE/mailbox/response.cc
1515
)
1616

17-
find_package(tinyxml2 CONFIG QUIET)
18-
if (tinyxml2_FOUND)
19-
list(APPEND KICKCAT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/CoE/EsiParser.cc)
20-
set_property(GLOBAL PROPERTY ESI_AVAILABLE True)
21-
endif()
2217

2318
if (NUTTX)
2419
set(OS_LIB_SOURCES
2520
${CMAKE_CURRENT_SOURCE_DIR}/src/OS/Linux/Time.cc
2621
)
2722
set(OS_LIBRARIES )
28-
set(OS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/kickcat/OS/Linux/types)
2923
elseif(PIKEOS)
3024
set(OS_LIB_SOURCES
3125
${CMAKE_CURRENT_SOURCE_DIR}/src/OS/PikeOS/Socket.cc
@@ -34,8 +28,8 @@ elseif(PIKEOS)
3428
)
3529

3630
set(OS_LIBRARIES )
37-
set(OS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/kickcat/OS/PikeOS/types)
3831
elseif (UNIX)
32+
3933
set(OS_LIB_SOURCES
4034
${CMAKE_CURRENT_SOURCE_DIR}/src/OS/Linux/Socket.cc
4135
${CMAKE_CURRENT_SOURCE_DIR}/src/OS/Linux/Time.cc
@@ -45,17 +39,22 @@ elseif (UNIX)
4539
${CMAKE_CURRENT_SOURCE_DIR}/src/OS/Linux/ConditionVariable.cc
4640
)
4741
set(OS_LIBRARIES pthread rt)
48-
set(OS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/kickcat/OS/Linux/types)
42+
43+
if (ENABLE_ESI_PARSER)
44+
find_package(tinyxml2 CONFIG REQUIRED)
45+
list(APPEND KICKCAT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/CoE/EsiParser.cc)
46+
list(APPEND OS_LIBRARIES tinyxml2::tinyxml2)
47+
endif()
48+
4949
endif()
5050

5151
add_library(kickcat ${KICKCAT_SOURCES} ${OS_LIB_SOURCES})
5252
target_include_directories(kickcat
53-
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${OS_INCLUDE_DIR}
53+
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
5454
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/kickcat)
55+
5556
target_link_libraries(kickcat ${OS_LIBRARIES})
56-
if (tinyxml2_FOUND)
57-
target_link_libraries(kickcat tinyxml2::tinyxml2)
58-
endif()
57+
5958
set_kickcat_properties(kickcat)
6059

6160
add_subdirectory(master)

lib/include/kickcat/OS/Mutex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef KICKCAT_OS_LINUX_MUTEX_H
22
#define KICKCAT_OS_LINUX_MUTEX_H
33

4-
#include "os_types.h"
4+
#include "kickcat/types.h"
55

66
namespace kickcat
77
{

lib/include/kickcat/OS/SharedMemory.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <string>
55

6-
#include "os_types.h"
6+
#include "kickcat/types.h"
77

88
namespace kickcat
99
{

lib/include/kickcat/protocol.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,8 @@ namespace kickcat
756756
/// extract a position or node address
757757
constexpr std::tuple<uint16_t, uint16_t> extractAddress(uint32_t address)
758758
{
759-
uint16_t offset = address >> 16;
760-
uint16_t position = address & 0xFFFF;
759+
uint16_t offset = static_cast<uint16_t>(address >> 16);
760+
uint16_t position = static_cast<uint16_t>(address & 0xFFFF);
761761
return std::make_tuple(position, offset);
762762
}
763763

lib/include/kickcat/types.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef KICKCAT_TYPES_H
2+
#define KICKCAT_TYPES_H
3+
4+
#if defined(__unix__) || defined(__NuttX__)
5+
#include "OS/Unix/types/os_types.h"
6+
#elif __PikeOS__
7+
#include "OS/PikeOS/types/os_types.h"
8+
#endif
9+
10+
#endif

tools/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ add_executable(eeprom eeprom.cc)
1010
target_link_libraries(eeprom kickcat)
1111
set_kickcat_properties(eeprom)
1212

13-
add_executable(od_generator od_generator.cc)
14-
target_link_libraries(od_generator kickcat)
13+
if (ENABLE_ESI_PARSER)
14+
add_executable(od_generator od_generator.cc)
15+
target_link_libraries(od_generator kickcat)
16+
endif()
1517

1618

1719
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

0 commit comments

Comments
 (0)