-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
102 lines (91 loc) · 3.17 KB
/
Copy pathCMakeLists.txt
File metadata and controls
102 lines (91 loc) · 3.17 KB
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
# SPDX-FileCopyrightText: 2025 Verizon
# SPDX-License-Identifier: Apache-2.0
# Set flags for compiling the binary
set(ASN1_DEFINITIONS
ASN_DISABLE_PRINT_SUPPORT
ASN_PDU_COLLECTION
)
# Reference cmake files for custom functions
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(PostBuild)
# Grab all of the sources
set(VERSION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${J2735_REV}")
# Check if the standard version directory exists
if(NOT EXISTS "${VERSION_DIR}")
message(FATAL_ERROR
"Missing standard directory: ${VERSION_DIR}\n"
"Please ensure the SAE J2735 ${J2735_REV} files are present."
)
endif()
file(GLOB ASN1_SOURCES "${VERSION_DIR}/src/*.c")
# Final check: Did we actually find any code?
if(NOT ASN1_SOURCES)
message(FATAL_ERROR "Directory found, but no .c files found in: ${VERSION_DIR}/src")
endif()
# Build out the native library if specified
if(BUILD_NATIVE_LIB)
file(MAKE_DIRECTORY "${DIST_STATIC_DIR}")
add_library(j2735_native_lib STATIC)
target_sources(j2735_native_lib PRIVATE ${ASN1_SOURCES})
target_include_directories(j2735_native_lib
PUBLIC "${VERSION_DIR}/include"
)
target_compile_definitions(j2735_native_lib PRIVATE ${ASN1_DEFINITIONS})
set_target_properties(j2735_native_lib PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${DIST_STATIC_DIR}"
OUTPUT_NAME "j2735codec"
)
endif()
# Build out WASM if activated by emscripten
if(EMSCRIPTEN)
# Setup for compilation
add_executable(j2735_wasm_lib)
target_sources(j2735_wasm_lib PRIVATE ${ASN1_SOURCES})
target_include_directories(j2735_wasm_lib
PUBLIC "${VERSION_DIR}/include"
)
target_compile_definitions(j2735_wasm_lib PRIVATE ${ASN1_DEFINITIONS})
# Need link options for WASM build
target_link_options(j2735_wasm_lib PRIVATE
"-sSTANDALONE_WASM"
"-sEXPORTED_FUNCTIONS=['_transcode','_malloc','_free']"
"-Wl,--no-entry"
)
# Setup output properties
set_target_properties(j2735_wasm_lib PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${DIST_WASM_DIR}"
OUTPUT_NAME "j2735codec"
SUFFIX ".wasm"
)
# Perform post build actions, build dist directory
add_custom_command(TARGET j2735_wasm_lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${DIST_WASM_DIR}"
COMMENT "Constructing WASM asset directory ${DIST_WASM_DIR}..."
VERBATIM
)
# Build binding outputs
foreach(DIR ${PY_DIR} ${NODE_DIR})
# Create directories for each binding
set(GEN_DIR "${DIR}/generated")
create_binding_directories(j2735_wasm_lib ${GEN_DIR})
set(EXT ".py")
if(${DIR} STREQUAL ${NODE_DIR})
set(EXT ".ts")
endif()
# Generate enums for python binding
generate_enums(
j2735_wasm_lib
"${VERSION_DIR}/src/pdu_collection.c"
"${GEN_DIR}/pdu${EXT}"
"&asn_DEF_"
"PDUTypes"
)
generate_enums(
j2735_wasm_lib
"${VERSION_DIR}/include/asn_application.h"
"${GEN_DIR}/encodings${EXT}"
"ATS_"
"EncodingRules"
)
endforeach()
endif()