1- # wolfSSL Espressif Example Project CMakeLists.txt
1+ # [example]/CMakeLists.txt for Espressif targets
2+ #
3+ # Copyright (C) 2006-2025 wolfSSL Inc.
4+ #
5+ # This file is part of wolfMQTT.
6+ #
7+ # wolfMQTT is free software; you can redistribute it and/or modify
8+ # it under the terms of the GNU General Public License as published by
9+ # the Free Software Foundation; either version 2 of the License, or
10+ # (at your option) any later version.
11+ #
12+ # wolfMQTT is distributed in the hope that it will be useful,
13+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ # GNU General Public License for more details.
16+ #
17+ # You should have received a copy of the GNU General Public License
18+ # along with this program; if not, write to the Free Software
19+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+ #
221# v1.0
322#
423# The following lines of boilerplate have to be in your project's
@@ -12,13 +31,83 @@ set(WOLFSSL_USER_SETTINGS ON)
1231set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFMQTT_USER_SETTINGS" )
1332set (WOLFMQTT_USER_SETTINGS ON )
1433
34+ # These should typically be set in user_settings.h
1535set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_AWSIOT_EXAMPLE" )
1636set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_MQTT_TLS" )
1737set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFMQTT_EXTERN_CERT" )
1838set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_MAIN_DRIVER" )
1939
40+ # Find the user name to search for possible "wolfssl-username"
41+ # Reminder: Windows is %USERNAME%, Linux is $USER
42+ if ( "$ENV{USER} " STREQUAL "" ) # the bash user
43+ if ( "$ENV{USERNAME} " STREQUAL "" ) # the Windows user
44+ message (STATUS "could not find USER or USERNAME" )
45+ else ()
46+ # the bash user is not blank, so we'll use it.
47+ set (THIS_USER "$ENV{USERNAME} " )
48+ endif ()
49+ else ()
50+ # the bash user is not blank, so we'll use it.
51+ set (THIS_USER "$ENV{USER} " )
52+ endif ()
53+ message (STATUS "THIS_USER = ${THIS_USER} " )
2054
2155
56+ # CHECK_DUPLICATE_LIBRARIES function
57+ # Parameters:
58+ # RESULT_VAR (output variable)
59+ # KEYWORD (e.g. "wolfssl", "wolfmqtt", etc).
60+ #
61+ # Constructs a list of possible directories based on the keyword.
62+ # Counts the number of existing directories.
63+ # If at least two directories exist, sets RESULT_VAR to TRUE, otherwise FALSE.
64+ # Uses PARENT_SCOPE to return the result to the calling context.
65+ function (CHECK_DUPLICATE_LIBRARIES RESULT_VAR KEYWORD )
66+ set (DIR_LIST
67+ "${CMAKE_CURRENT_LIST_DIR} /components/${KEYWORD} "
68+ "${CMAKE_CURRENT_LIST_DIR} /components/my${KEYWORD} "
69+ "${CMAKE_CURRENT_LIST_DIR} /managed_components/wolfssl__${KEYWORD} "
70+ "${CMAKE_CURRENT_LIST_DIR} /managed_components/gojimmypi__my${KEYWORD} "
71+ "${CMAKE_CURRENT_LIST_DIR} /managed_components/${THIS_USER} __my${KEYWORD} "
72+ "$ENV{IDF_PATH} /components/${KEYWORD} /"
73+ "$ENV{IDF_PATH} /components/esp-${KEYWORD} /"
74+ )
75+
76+ set (EXISTING_COUNT 0)
77+ set (MATCHING_DIRS "" ) # List to store found directories
78+
79+ foreach (DIR ${DIR_LIST} )
80+ file (TO_CMAKE_PATH "${DIR} " DIR ) # Normalize paths
81+ message (STATUS "Checking for ${KEYWORD} in ${DIR} " )
82+ if (EXISTS "${DIR} " )
83+ math (EXPR EXISTING_COUNT "${EXISTING_COUNT} + 1" )
84+ list (APPEND MATCHING_DIRS "${DIR} " )
85+ message (STATUS "Found: ${DIR} " )
86+ endif ()
87+ endforeach ()
88+
89+ if (EXISTING_COUNT GREATER_EQUAL 2)
90+ set (${RESULT_VAR} TRUE PARENT_SCOPE )
91+ message (STATUS "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
92+ message (STATUS "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
93+ message (STATUS "WARNING: Found duplicate '${KEYWORD} ' in" )
94+ foreach (DUP_DIR ${MATCHING_DIRS} )
95+ message (STATUS " - ${DUP_DIR} " )
96+ endforeach ()
97+ message (STATUS "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
98+ message (STATUS "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
99+ message (WARNING "WARNING: More than 1 '${KEYWORD} ' component directories exist." )
100+
101+ # Append the warning flag to CMAKE_C_FLAGS and propagate it to the parent scope
102+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D${KEYWORD} _MULTI_INSTALL_WARNING" )
103+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} " PARENT_SCOPE )
104+ else ()
105+ set (${RESULT_VAR} FALSE PARENT_SCOPE )
106+
107+ message (STATUS "Confirmed less than two '${KEYWORD} ' component directories exist." )
108+ endif ()
109+ endfunction ()
110+
22111# The wolfSSL CMake file should be able to find the source code.
23112# Otherwise, assign an environment variable or set it here:
24113#
@@ -37,45 +126,53 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_MAIN_DRIVER")
37126if (WIN32 )
38127 # Windows-specific configuration here
39128 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS" )
40- message ("Detected Windows" )
129+ message (STATUS "Detected Windows" )
41130endif ()
42131if (CMAKE_HOST_UNIX )
43- message ("Detected UNIX" )
132+ message (STATUS "Detected UNIX" )
44133endif ()
45134if (APPLE )
46- message ("Detected APPLE" )
135+ message (STATUS "Detected APPLE" )
47136endif ()
48137if (CMAKE_HOST_UNIX AND (NOT APPLE ) AND EXISTS "/proc/sys/fs/binfmt_misc/WSLInterop" )
49138 # Windows-specific configuration here
50139 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_WSL" )
51- message ("Detected WSL" )
140+ message (STATUS "Detected WSL" )
52141endif ()
53142if (CMAKE_HOST_UNIX AND (NOT APPLE ) AND (NOT WIN32 ))
54143 # Windows-specific configuration here
55144 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_LINUX" )
56- message ("Detected Linux" )
145+ message (STATUS "Detected Linux" )
57146endif ()
58147if (APPLE )
59148 # Windows-specific configuration here
60149 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_CMAKE_SYSTEM_NAME_APPLE" )
61- message ("Detected Apple" )
150+ message (STATUS "Detected Apple" )
62151endif ()
63152# End optional WOLFSSL_CMAKE_SYSTEM_NAME
64153
65154# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
66- set (PROTOCOL_EXAMPLES_DIR $ENV{IDF_PATH} /examples/common_components/protocol_examples_common)
155+ # set (PROTOCOL_EXAMPLES_DIR $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
156+ string (REPLACE "\\ " "/" PROTOCOL_EXAMPLES_DIR "$ENV{IDF_PATH} /examples/common_components/protocol_examples_common" )
67157
68158if (EXISTS "${PROTOCOL_EXAMPLES_DIR} " )
69- message ("Found PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR} " )
159+ message (STATUS "Found PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR} " )
70160 set (EXTRA_COMPONENT_DIRS $ENV{IDF_PATH} /examples/common_components/protocol_examples_common)
71161 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFOUND_PROTOCOL_EXAMPLES_DIR" )
72162else ()
73- message ("NOT FOUND: PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR} " )
163+ message (STATUS "NOT FOUND: PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR} " )
74164endif ()
75165
76- # Check that there are not conflicting wolfSSL components
166+ # Check that there are not conflicting wolfSSL components.
77167# The ESP Registry Component will be in ./managed_components/wolfssl__wolfssl
78168# The local component wolfSSL directory will be in ./components/wolfssl
169+ message (STATUS "Checking for wolfSSL as Managed Component or not... ${CMAKE_HOME_DIRECTORY} " )
170+ message (STATUS "Checking for duplicate components. CMAKE_HOME_DIRECTORY='${CMAKE_HOME_DIRECTORY} '" )
171+ CHECK_DUPLICATE_LIBRARIES (DUPE_WOLFSSL_FOUND "wolfssl" )
172+ CHECK_DUPLICATE_LIBRARIES (DUPE_WOLFSSL_FOUND "wolfmqtt" )
173+ CHECK_DUPLICATE_LIBRARIES (DUPE_WOLFSSL_FOUND "wolfssh" )
174+ CHECK_DUPLICATE_LIBRARIES (DUPE_WOLFSSL_FOUND "wolftpm" )
175+
79176if ( EXISTS "${CMAKE_HOME_DIRECTORY} /managed_components/wolfssl__wolfssl" AND EXISTS "${CMAKE_HOME_DIRECTORY} /components/wolfssl" )
80177 # These exclude statements don't seem to be honored by the $ENV{IDF_PATH}/tools/cmake/project.cmake'
81178 # add_subdirectory("${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl" EXCLUDE_FROM_ALL)
@@ -90,16 +187,31 @@ if( EXISTS "${CMAKE_HOME_DIRECTORY}/managed_components/wolfssl__wolfssl" AND EXI
90187 message (FATAL_ERROR "\n Please use either the ESP Registry Managed Component or the wolfSSL component directory but not both.\n "
91188 "If removing the ./managed_components/wolfssl__wolfssl directory, remember to also remove "
92189 "or rename the idf_component.yml file typically found in ./main/" )
93- else ()
190+ elseif (EXISTS "${CMAKE_HOME_DIRECTORY} /components/wolfssl" )
191+ # A standard project component (not a Managed Component)
94192 message (STATUS "No conflicting wolfSSL components found." )
193+ set (WOLFSSL_PATH "${CMAKE_HOME_DIRECTORY} /components/wolfssl" )
194+ elseif (EXISTS "${CMAKE_HOME_DIRECTORY} /managed_components/wolfssl__wolfssl" )
195+ # The official Managed Component called wolfssl from the wolfssl user.
196+ message (STATUS "No conflicting wolfSSL components found as a Managed Component." )
197+ set (WOLFSSL_PATH "${CMAKE_HOME_DIRECTORY} /managed_components/wolfssl__wolfssl" )
198+ elseif (EXISTS "${CMAKE_HOME_DIRECTORY} /managed_components/gojimmypi__mywolfssl" )
199+ # There is a known gojimmypi staging component available for anyone:
200+ message (STATUS "No conflicting wolfSSL components found as a gojimmypi staging Managed Component." )
201+ elseif (EXISTS "${CMAKE_HOME_DIRECTORY} /managed_components/${THIS_USER} __mywolfssl" )
202+ # Other users with permissions might publish their own mywolfssl staging Managed Component
203+ message (STATUS "No conflicting wolfSSL components found as a Managed Component." )
204+ set (WOLFSSL_PATH "${CMAKE_HOME_DIRECTORY} /managed_components/${THIS_USER} __mywolfssl" )
205+ else ()
206+ message (STATUS "WARNING: wolfssl component directory not found." )
95207endif ()
96208
97209
98210# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
99211set (PROTOCOL_EXAMPLES_DIR $ENV{IDF_PATH} /examples/common_components/protocol_examples_common)
100212
101213if (EXISTS "${PROTOCOL_EXAMPLES_DIR} " )
102- message ("Found PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR} " )
214+ message (STATUS "Found PROTOCOL_EXAMPLES_DIR=${PROTOCOL_EXAMPLES_DIR} " )
103215 set (EXTRA_COMPONENT_DIRS $ENV{IDF_PATH} /examples/common_components/protocol_examples_common)
104216 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFOUND_PROTOCOL_EXAMPLES_DIR" )
105217else ()
@@ -115,3 +227,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
115227#) # set components
116228
117229project (wolfssl_mqtt_aws_iot)
230+ message (STATUS "end project" )
0 commit comments