Aufgrund einer Störung des s3 Storage, könnten in nächster Zeit folgende GitLab Funktionen nicht zur Verfügung stehen: LFS, Container Registry, Job Artifacs, Uploads (Wiki, Bilder, Projekt-Exporte). Wir bitten um Verständnis. Es wird mit Hochdruck an der Behebung des Problems gearbeitet. Weitere Informationen zur Störung des Object Storage finden Sie hier: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/59-object-storage-pilot

Commit 5e36b182 authored by Mike Grüne's avatar Mike Grüne
Browse files

Add CMakeLists.ftl and Method for generation

parent 4730e9b6
Pipeline #157865 failed with stages
in 1 minute and 34 seconds
......@@ -15,6 +15,7 @@ import de.se_rwth.commons.logging.Log;
public class MqttTemplates {
private static final Template PrettyPrint;
private static final Template MQTT_CMAKELISTS;
// Loading .ftl files
static {
......@@ -25,19 +26,26 @@ public class MqttTemplates {
conf.setClassForTemplateLoading(MqttTemplates.class, "");
try {
PrettyPrint = conf.getTemplate("PrettyPrint.ftl");
MQTT_CMAKELISTS = conf.getTemplate("CMakeLists.ftl");
} catch (IOException e) {
String msg = "could not load template";
Log.error(msg, e);
throw new RuntimeException(msg, e);
}
}
public static String generateMqttAdapter(MqttAdapterModel model) {
HashMap<String, Object> data = new HashMap<>();
data.put("model", model);
return generate(PrettyPrint, data);
}
public static String generateMqttCMakeLists(MqttCMakeModel model) {
HashMap<String, Object> data = new HashMap<>();
data.put("model", model);
return generate(MQTT_CMAKELISTS, data);
}
@SuppressWarnings("rawtypes")
private static String generate(Template template, Map dataForTemplate) {
Log.errorIfNull(template);
......
#Setting cmake version
cmake_minimum_required(VERSION 3.1...3.14)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
#Using C++ version 11 with threads for compiling
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
# Find Pthread package
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
#Setting Project name
project (${model.name})
#Find MQTT packages
message("Searching for installed MQTT on your system...")
# Searching for include directory
if (NOT MQTT_INCLUDE_DIR)
find_path(MQTT_INCLUDE_DIR MQTTAsync.h HINTS "/usr/include/" "/usr/local/include/")
endif()
# Searching for libraries (without SSL support)
if (NOT MQTT_LIBS)
find_library(
MQTT_C_LIB
NAMES paho-mqtt3c)
find_library(
MQTT_A_LIB
NAMES paho-mqtt3a)
find_library(
MQTT_PP_LIB
NAMES paho-mqttpp3)
set(MQTT_LIBS ${MQTT_A_LIB} ${MQTT_C_LIB} ${MQTT_PP_LIB})
endif()
add_library(${model.name} ${model.name}.cpp)
# Checking if everything was found
if (NOT MQTT_C_LIB OR NOT MQTT_A_LIB OR NOT MQTT_PP_LIB)
message(FATAL_ERROR "MQTT libraries not found!")
elseif (NOT MQTT_INCLUDE_DIR)
message(FATAL_ERROR "MQTT includes not found!")
else()
message("MQTT includes found in "${MQTT_INCLUDE_DIR})
message("MQTT libraries found in "${MQTT_LIBS})
endif()
# Adding include directory to a target
target_include_directories(mqtt_demo PUBLIC ${MQTT_INCLUDE_DIR})
# Linking libraries to target
target_link_libraries(mqtt_demo PUBLIC ${MQTT_LIBS})
list(APPEND LIBRARIES ${model.compName})
list(APPEND LIBRARIES IAdapter_${model.compName})
<#list model.getPackages() as lib>
list(APPEND LIBRARIES ${lib}_LIBRARIES})
</#list>
target_link_libraries(${model.name} <#noparse>${LIBRARIES}</#noparse>)
list(APPEND INCLUDE_DIRS <#noparse>${CMAKE_CURRENT_SOURCE_DIR}</#noparse>)
<#list model.getPackages() as incl>
list(APPEND INCLUDE_DIRS ${incl}_INCLUDE_DIRS})
</#list>
target_include_directories(${model.name} PUBLIC <#noparse>${INCLUDE_DIRS}</#noparse>)
export(TARGETS ${model.name} FILE ${model.name}.cmake)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment