Skip to content

Commit

Permalink
#3 WiP for CMake conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerMalmberg committed Oct 20, 2018
1 parent 466e40c commit 19e9554
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 46 deletions.
80 changes: 36 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(Smooth)
include(${CMAKE_CURRENT_LIST_DIR}/idf_utils.cmake)

set(CMAKE_CXX_STANDARD 11)
verify_idf_path()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=bounds -fsanitize=leak -fsanitize=return -fsanitize=null")

include_directories(include)

add_definitions("-DCONFIG_SMOOTH_MAX_MQTT_MESSAGE_SIZE=3500")
add_definitions("-DCONFIG_SMOOTH_MAX_MQTT_OUTGOING_MESSAGES=10")

set(SOURCE_FILES
set(SOURCES
application/network/mqtt/packet/ConnAck.cpp
application/network/mqtt/packet/Connect.cpp
application/network/mqtt/packet/Disconnect.cpp
Expand Down Expand Up @@ -47,6 +39,7 @@ set(SOURCE_FILES
core/timer/Timer.cpp
core/timer/TimerService.cpp
core/Application.cpp
core/json/Value.cpp
core/Task.cpp
include/smooth/application/display/ST7735.h
include/smooth/application/io/ADS1115.h
Expand Down Expand Up @@ -133,42 +126,41 @@ set(SOURCE_FILES
include/smooth/core/task_priorities.h
include/smooth/core/ipc/ILinkSubscriber.h
include/smooth/core/ipc/IPolledTaskQueue.h

${IDF_PATH}/components/json/cJSON/cJSON.c
${IDF_PATH}/components/json/cJSON/cJSON.h
include/smooth/core/json/Value.h
core/json/Value.cpp)

add_library(${PROJECT_NAME} ${SOURCE_FILES})

set(COMPONENTS
freertos
cxx
esp32
driver
log
tcpip_adapter
lwip
openssl
fatfs/src
vfs
storage
wear_levelling
nvs_flash
json/cJSON
spi_flash
$ENV{IDF_PATH}/components/json/cJSON/cJSON.c
$ENV{IDF_PATH}/components/json/cJSON/cJSON.h
)

set(COMPONENT_INCLUDE_DIRS "")
add_library(smooth STATIC ${SOURCES})

foreach (COMP ${COMPONENTS})
if(EXISTS ${IDF_PATH}/components/${COMP}/include)
list(APPEND COMPONENT_INCLUDE_DIRS ${IDF_PATH}/components/${COMP}/include)
else()
list(APPEND COMPONENT_INCLUDE_DIRS ${IDF_PATH}/components/${COMP})
endif()
endforeach ()
if (${ESP_PLATFORM})
target_compile_definitions(smooth PRIVATE _GLIBCXX_USE_C99) # for std::to_string (until using xtensa-gcc 8)
add_idf_include(smooth newlib)
add_idf_include(smooth newlib/platform_include)
add_idf_include(smooth log)
add_idf_include(smooth heap)
add_idf_include(smooth freertos)
add_idf_include(smooth soc)
add_idf_include(smooth soc/esp32)
add_idf_include(smooth driver)
add_idf_include(smooth esp32)
add_idf_include(smooth lwip/lwip/src)
add_idf_include(smooth lwip/include/apps)
add_idf_include(smooth lwip/port/esp32)
add_idf_include(smooth vfs)
add_idf_include(smooth nvs_flash)
add_idf_include(smooth spi_flash)
add_idf_include(smooth tcpip_adapter)
add_idf_include(smooth json/cJSON)
else ()
project(smooth)
add_definitions("-DCONFIG_SMOOTH_MAX_MQTT_MESSAGE_SIZE=3500")
add_definitions("-DCONFIG_SMOOTH_MAX_MQTT_OUTGOING_MESSAGES=10")
endif ()

include_directories(${COMPONENT_INCLUDE_DIRS})
target_include_directories(
smooth
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include
PRIVATE $ENV{IDF_PATH}/components/json/cJSON
)

set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${COMPONENT_INCLUDE_DIRS})
24 changes: 24 additions & 0 deletions idf_utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function(add_idf_include target component)
if (EXISTS $ENV{IDF_PATH}/components/${component}/include)
target_include_directories(${target} PRIVATE $ENV{IDF_PATH}/components/${component}/include)
elseif (EXISTS $ENV{IDF_PATH}/components/${component})
target_include_directories(${target} PRIVATE $ENV{IDF_PATH}/components/${component})
else ()
message(FATAL_ERROR "Given component path does not exist: ${component}")
endif ()
endfunction()

function(verify_idf_path)
if (NOT EXISTS "$ENV{IDF_PATH}/Kconfig")
message(FATAL_ERROR "Environment IDF_PATH must be set to an existing IDF-installation. IDF_PATH: '$ENV{IDF_PATH}'")
else ()
message(STATUS "IDF_PATH appears valid.")
endif ()
endfunction()

function(optionally_enable_idf_project_management)
if (IDF_PLATFORM)
message(STATUS "Compiling for IDF, enabling IDF project management.")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
endif ()
endfunction()
6 changes: 4 additions & 2 deletions include/smooth/core/timer/ElapsedTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace smooth
class ElapsedTime
{
public:
/// Starts and the performance timer.
/// Starts the performance timer.
void start()
{
active = true;
Expand All @@ -33,19 +33,21 @@ namespace smooth
timersub(&end_time, &start_time, &elapsed);
}

/// Semantically the same as start(), but provided for syntactical reasons.
/// Functionally the same as start(), but provided for syntactical reasons.
void reset()
{
// Simply restart the timer.
start();
}

/// Zeroes the time, but lets it keep running.
void zero()
{
gettimeofday(&start_time, nullptr);
end_time = start_time;
}

/// Stops the timer and zeroes it.
void stop_and_zero()
{
stop();
Expand Down
174 changes: 174 additions & 0 deletions old_CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
cmake_minimum_required(VERSION 3.8)
project(Smooth)

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=bounds -fsanitize=leak -fsanitize=return -fsanitize=null")

include_directories(include)

add_definitions("-DCONFIG_SMOOTH_MAX_MQTT_MESSAGE_SIZE=3500")
add_definitions("-DCONFIG_SMOOTH_MAX_MQTT_OUTGOING_MESSAGES=10")

set(SOURCE_FILES
application/network/mqtt/packet/ConnAck.cpp
application/network/mqtt/packet/Connect.cpp
application/network/mqtt/packet/Disconnect.cpp
application/network/mqtt/packet/MQTTPacket.cpp
application/network/mqtt/packet/MQTTProtocolDefinitions.cpp
application/network/mqtt/packet/PacketDecoder.cpp
application/network/mqtt/packet/PacketIdentifierFactory.cpp
application/network/mqtt/packet/PingReq.cpp
application/network/mqtt/packet/PingResp.cpp
application/network/mqtt/packet/PubAck.cpp
application/network/mqtt/packet/PubComp.cpp
application/network/mqtt/packet/Publish.cpp
application/network/mqtt/packet/PubRec.cpp
application/network/mqtt/packet/PubRel.cpp
application/network/mqtt/packet/SubAck.cpp
application/network/mqtt/packet/Subscribe.cpp
application/network/mqtt/packet/UnsubAck.cpp
application/network/mqtt/packet/Unsubscribe.cpp
application/network/mqtt/state/ConnectedState.cpp
application/network/mqtt/state/ConnectToBrokerState.cpp
application/network/mqtt/state/DisconnectedState.cpp
application/network/mqtt/state/DisconnectState.cpp
application/network/mqtt/state/MQTTBaseState.cpp
application/network/mqtt/state/RunState.cpp
application/network/mqtt/MqttClient.cpp
application/network/mqtt/Publication.cpp
application/network/mqtt/Subscription.cpp
core/ipc/QueueNotification.cpp
core/logging/posix/posix_log.cpp
core/network/IPv4.cpp
#core/network/IPv6.cpp
core/network/SocketDispatcher.cpp
core/timer/ElapsedTime.cpp
core/timer/Timer.cpp
core/timer/TimerService.cpp
core/Application.cpp
core/Task.cpp
include/smooth/application/display/ST7735.h
include/smooth/application/io/ADS1115.h
include/smooth/application/io/MCP23017.h
include/smooth/application/network/mqtt/event/BaseEvent.h
include/smooth/application/network/mqtt/event/ConnectEvent.h
include/smooth/application/network/mqtt/event/DisconnectEvent.h
include/smooth/application/network/mqtt/packet/ConnAck.h
include/smooth/application/network/mqtt/packet/Connect.h
include/smooth/application/network/mqtt/packet/Disconnect.h
include/smooth/application/network/mqtt/packet/IPacketReceiver.h
include/smooth/application/network/mqtt/packet/MQTTPacket.h
include/smooth/application/network/mqtt/packet/PacketDecoder.h
include/smooth/application/network/mqtt/packet/PacketIdentifierFactory.h
include/smooth/application/network/mqtt/packet/PingReq.h
include/smooth/application/network/mqtt/packet/PingResp.h
include/smooth/application/network/mqtt/packet/PubAck.h
include/smooth/application/network/mqtt/packet/PubComp.h
include/smooth/application/network/mqtt/packet/Publish.h
include/smooth/application/network/mqtt/packet/PubRec.h
include/smooth/application/network/mqtt/packet/PubRel.h
include/smooth/application/network/mqtt/packet/SubAck.h
include/smooth/application/network/mqtt/packet/Subscribe.h
include/smooth/application/network/mqtt/packet/UnsubAck.h
include/smooth/application/network/mqtt/packet/Unsubscribe.h
include/smooth/application/network/mqtt/state/ConnectedState.h
include/smooth/application/network/mqtt/state/ConnectToBrokerState.h
include/smooth/application/network/mqtt/state/DisconnectedState.h
include/smooth/application/network/mqtt/state/DisconnectState.h
include/smooth/application/network/mqtt/state/IdleState.h
include/smooth/application/network/mqtt/state/MQTTBaseState.h
include/smooth/application/network/mqtt/state/MqttFSM.h
include/smooth/application/network/mqtt/state/MqttFsmConstants.h
include/smooth/application/network/mqtt/state/RunState.h
include/smooth/application/network/mqtt/state/StartupState.h
include/smooth/application/network/mqtt/IMqttClient.h
include/smooth/application/network/mqtt/InFlight.h
include/smooth/application/network/mqtt/Logging.h
include/smooth/application/network/mqtt/MqttClient.h
include/smooth/application/network/mqtt/MQTTProtocolDefinitions.h
include/smooth/application/network/mqtt/Publication.h
include/smooth/application/network/mqtt/Subscription.h
include/smooth/core/fsm/StaticFSM.h
include/smooth/core/ipc/IEventListener.h
include/smooth/core/ipc/ITaskEventQueue.h
include/smooth/core/ipc/Link.h
include/smooth/core/ipc/Publisher.h
include/smooth/core/ipc/Queue.h
include/smooth/core/ipc/QueueNotification.h
include/smooth/core/ipc/SubscribingTaskEventQueue.h
include/smooth/core/ipc/TaskEventQueue.h
include/smooth/core/logging/log.h
include/smooth/core/network/ConnectionStatusEvent.h
include/smooth/core/network/DataAvailableEvent.h
include/smooth/core/network/InetAddress.h
include/smooth/core/network/IPacketAssembly.h
include/smooth/core/network/IPacketDisassembly.h
include/smooth/core/network/IPacketReceiveBuffer.h
include/smooth/core/network/IPacketSendBuffer.h
include/smooth/core/network/IPv4.h
include/smooth/core/network/IPv6.h
include/smooth/core/network/ISocket.h
include/smooth/core/network/NetworkStatus.h
include/smooth/core/network/SocketOperation.h
include/smooth/core/network/PacketReceiveBuffer.h
include/smooth/core/network/PacketSendBuffer.h
include/smooth/core/network/Socket.h
include/smooth/core/network/SocketDispatcher.h
include/smooth/core/network/TransmitBufferEmptyEvent.h
include/smooth/core/timer/ElapsedTime.h
include/smooth/core/timer/ITimer.h
include/smooth/core/timer/Timer.h
include/smooth/core/timer/TimerExpiredEvent.h
include/smooth/core/timer/TimerService.h
include/smooth/core/util/advance_iterator.h
include/smooth/core/util/ByteSet.h
include/smooth/core/util/CircularBuffer.h
include/smooth/core/util/FixedBuffer.h
include/smooth/core/util/FixedBufferBase.h
include/smooth/core/util/make_unique.h
include/smooth/core/Application.h
include/smooth/core/Task.h
include/smooth/core/TaskStatus.h
include/smooth/core/task_priorities.h
include/smooth/core/ipc/ILinkSubscriber.h
include/smooth/core/ipc/IPolledTaskQueue.h

${IDF_PATH}/components/json/cJSON/cJSON.c
${IDF_PATH}/components/json/cJSON/cJSON.h
include/smooth/core/json/Value.h
core/json/Value.cpp)

add_library(${PROJECT_NAME} ${SOURCE_FILES})

set(COMPONENTS
freertos
cxx
esp32
driver
log
tcpip_adapter
lwip
openssl
fatfs/src
vfs
storage
wear_levelling
nvs_flash
json/cJSON
spi_flash
)

set(COMPONENT_INCLUDE_DIRS "")

foreach (COMP ${COMPONENTS})
if(EXISTS ${IDF_PATH}/components/${COMP}/include)
list(APPEND COMPONENT_INCLUDE_DIRS ${IDF_PATH}/components/${COMP}/include)
else()
list(APPEND COMPONENT_INCLUDE_DIRS ${IDF_PATH}/components/${COMP})
endif()
endforeach ()

include_directories(${COMPONENT_INCLUDE_DIRS})

set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${COMPONENT_INCLUDE_DIRS})
File renamed without changes.

0 comments on commit 19e9554

Please sign in to comment.