Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/fmi/CMakeLists.txt
169668 views
1
2
#########################################################
3
# Building of the libsumo-FMI2 library
4
set (libsumofmi2_SRCS
5
fmi2Functions.c
6
sumo2fmi_bridge.c
7
libsumocpp2c.cpp
8
)
9
10
add_library(libsumofmi2 SHARED ${libsumofmi2_SRCS})
11
set_target_properties(libsumofmi2 PROPERTIES PREFIX "")
12
set_target_properties(libsumofmi2 PROPERTIES OUTPUT_NAME libsumofmi2${BINARY_SUFFIX})
13
set_target_properties(libsumofmi2 PROPERTIES OUTPUT_NAME_DEBUG libsumofmi2${BINARY_SUFFIX}D)
14
target_link_libraries(libsumofmi2 libsumocpp)
15
16
#########################################################
17
# Building of the ZIP Archive with the model description
18
# and the static library for the FMU
19
20
# The Library needs to go to a specific folder
21
# (binaries/win32 or binaries/win64 or ...)
22
# We need to determine the name for this folder
23
24
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
25
set(BITS "64")
26
else()
27
set(BITS "32")
28
endif()
29
30
if (WIN32)
31
if (CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
32
set(BITS "32")
33
endif()
34
if (CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
35
set(BITS "64")
36
endif()
37
set(PLATFORM_FOLDER_NAME "win${BITS}")
38
endif()
39
40
if (UNIX AND NOT APPLE)
41
set(PLATFORM_FOLDER_NAME "linux${BITS}")
42
endif()
43
44
if (APPLE)
45
set(PLATFORM_FOLDER_NAME "darwin${BITS}")
46
endif()
47
48
# Set the temporary folder name to collect the contents for the ZIP archive
49
set(ZIP_BUILD_FOLDER_NAME "sumo-fmi2")
50
51
# The command and parameters for rm / remove_directory change in cmake
52
if (${CMAKE_VERSION} VERSION_GREATER 3.17.0)
53
set(remove_command "rm" "-rf")
54
else()
55
set(remove_command "remove_directory")
56
endif()
57
58
###########################################################
59
# Define the custom target FMI to have all of these files
60
# built (also as part of ALL - but of course this happens
61
# only when FMI is enabled)
62
add_custom_target(prepfmi
63
# Remove the old directory (if exists) and create a new directory
64
COMMAND ${CMAKE_COMMAND} -E ${remove_command} "${ZIP_BUILD_FOLDER_NAME}"
65
COMMAND ${CMAKE_COMMAND} -E make_directory "${ZIP_BUILD_FOLDER_NAME}"
66
# Copy the XML file with the model description
67
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/modelDescription.xml" "${ZIP_BUILD_FOLDER_NAME}"
68
# Create the folder for the binaries and copy the library
69
COMMAND ${CMAKE_COMMAND} -E make_directory "${ZIP_BUILD_FOLDER_NAME}/binaries/${PLATFORM_FOLDER_NAME}/"
70
COMMAND ${CMAKE_COMMAND} -E copy ${SUMO_LIBRARIES_RELEASE_DLL} $<TARGET_FILE:libsumofmi2> $<TARGET_FILE:libsumocpp> "${ZIP_BUILD_FOLDER_NAME}/binaries/${PLATFORM_FOLDER_NAME}/"
71
)
72
add_dependencies(prepfmi libsumofmi2)
73
74
# native zip seems to work better
75
FIND_PROGRAM(ZIP_EXECUTABLE zip)
76
if (NOT VERBOSE_SUB)
77
set(ZIP_OPTS "-q")
78
endif ()
79
if (ZIP_EXECUTABLE)
80
add_custom_target(fmi ALL WORKING_DIRECTORY "${ZIP_BUILD_FOLDER_NAME}" COMMAND "${ZIP_EXECUTABLE}" ${ZIP_OPTS} -r "$<TARGET_FILE_DIR:libsumofmi2>/${ZIP_BUILD_FOLDER_NAME}$<$<CONFIG:Debug>:D>-${PLATFORM_FOLDER_NAME}.fmu" .)
81
else()
82
add_custom_target(fmi ALL COMMAND ${CMAKE_COMMAND} -E chdir "${ZIP_BUILD_FOLDER_NAME}" ${CMAKE_COMMAND} -E tar "cf" "$<TARGET_FILE_DIR:libsumofmi2>/${ZIP_BUILD_FOLDER_NAME}$<$<CONFIG:Debug>:D>-${PLATFORM_FOLDER_NAME}.fmu" --format=zip ".")
83
endif()
84
add_dependencies(fmi prepfmi)
85
86