-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
118 lines (103 loc) · 4.76 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
cmake_minimum_required(VERSION 3.5)
project(ikaAgentModel)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Add ika OSI wrapper (and agent)
add_subdirectory(lib/osiWrapper)
# Set a default build type if none was specified
set(default_build_type "Release")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(default_build_type "Debug")
endif()
# configure build version
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting ikaAgentModel build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# FMU output directory
set(FMU_OUTDIR "${CMAKE_SOURCE_DIR}/lib" CACHE STRING "Fmu output directory")
# Logging
set(PUBLIC_LOGGING OFF CACHE BOOL "Enable logging via FMI logger")
set(PRIVATE_LOGGING OFF CACHE BOOL "Enable private logging to file")
if(WIN32)
set(PRIVATE_LOG_PATH "C:/TEMP/${PROJECT_NAME}.log" CACHE FILEPATH "Path to write private log file to")
else()
set(PRIVATE_LOG_PATH "/tmp/${PROJECT_NAME}.log" CACHE FILEPATH "Path to write private log file to")
endif()
set(VERBOSE_FMI_LOGGING OFF CACHE BOOL "Enable detailed FMI function logging")
set(DEBUG_BREAKS OFF CACHE BOOL "Enable debugger traps for debug builds of FMU")
string(TIMESTAMP FMUTIMESTAMP UTC)
string(MD5 FMUGUID modelDescription.in.xml)
configure_file(modelDescription.xml modelDescription.xml @ONLY)
# Define target library ikaAgentModel
add_library(${PROJECT_NAME} SHARED
src/OSMPTrafficAgent.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC
include
include/FMI)
if(WIN32)
target_link_libraries(${PROJECT_NAME}
PUBLIC osi_wrapper -static-libgcc -static-libstdc++ -static
)
elseif(UNIX)
target_link_libraries(${PROJECT_NAME}
PUBLIC osi_wrapper
)
endif()
# Compile definitions
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
target_compile_definitions(${PROJECT_NAME} PRIVATE "FMU_SHARED_OBJECT")
target_compile_definitions(${PROJECT_NAME} PRIVATE "FMU_GUID=\"${FMUGUID}\"")
if(PRIVATE_LOGGING)
file(TO_NATIVE_PATH ${PRIVATE_LOG_PATH} PRIVATE_LOG_PATH_NATIVE)
string(REPLACE "\\" "\\\\" PRIVATE_LOG_PATH_ESCAPED ${PRIVATE_LOG_PATH_NATIVE})
target_compile_definitions(${PROJECT_NAME} PRIVATE
"PRIVATE_LOG_PATH=\"${PRIVATE_LOG_PATH_ESCAPED}\"")
endif()
target_compile_definitions(${PROJECT_NAME} PRIVATE
$<$<BOOL:${PUBLIC_LOGGING}>:PUBLIC_LOGGING>
$<$<BOOL:${VERBOSE_FMI_LOGGING}>:VERBOSE_FMI_LOGGING>
$<$<BOOL:${DEBUG_BREAKS}>:DEBUG_BREAKS>)
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(FMI_BINARIES_PLATFORM "win64")
else()
set(FMI_BINARIES_PLATFORM "win32")
endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(FMI_BINARIES_PLATFORM "linux64")
else()
set(FMI_BINARIES_PLATFORM "linux32")
endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(FMI_BINARIES_PLATFORM "darwin64")
else()
set(FMI_BINARIES_PLATFORM "darwin32")
endif()
endif()
get_filename_component(Protobuf_REAL_LIBRARY_FILENAME "${Protobuf_LIBRARY}" REALPATH)
add_custom_command(OUTPUT ${FMU_OUTDIR}/${PROJECT_NAME}.fmu
DEPENDS ${PROJECT_NAME}
modelDescription.xml
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/buildfmu"
#COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/buildfmu/sources"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/buildfmu/binaries/${FMI_BINARIES_PLATFORM}"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/modelDescription.xml" "${CMAKE_CURRENT_BINARY_DIR}/buildfmu"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PROJECT_NAME}> "${CMAKE_CURRENT_BINARY_DIR}/buildfmu/binaries/${FMI_BINARIES_PLATFORM}"
#COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:open_simulation_interface> "${CMAKE_CURRENT_BINARY_DIR}/buildfmu/binaries/${FMI_BINARIES_PLATFORM}"
#COMMAND ${CMAKE_COMMAND} -E copy "${Protobuf_REAL_LIBRARY_FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/buildfmu/binaries/${FMI_BINARIES_PLATFORM}"
#COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_CURRENT_BINARY_DIR}/buildfmu" ${CMAKE_COMMAND} -E tar "cfv" "${CMAKE_CURRENT_SOURCE_DIR}/lib/${PROJECT_NAME}.fmu" --format=zip "modelDescription.xml" "${CMAKE_CURRENT_BINARY_DIR}/buildfmu/binaries/${FMI_BINARIES_PLATFORM}")
COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_CURRENT_BINARY_DIR}/buildfmu" ${CMAKE_COMMAND}
-E tar "cfv" "${FMU_OUTDIR}/${PROJECT_NAME}.fmu"
--format=zip "modelDescription.xml"
"${CMAKE_CURRENT_BINARY_DIR}/buildfmu/binaries/${FMI_BINARIES_PLATFORM}")
add_custom_target(${PROJECT_NAME}_fmu
ALL
DEPENDS ${FMU_OUTDIR}/${PROJECT_NAME}.fmu)