forked from ksergey/sbe-code-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
42 lines (33 loc) · 1.41 KB
/
Copy pathCMakeLists.txt
File metadata and controls
42 lines (33 loc) · 1.41 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
cmake_minimum_required(VERSION 3.14)
project(sbe-code-gen)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
set(cppCodeGenRoot ${CMAKE_CURRENT_SOURCE_DIR})
set(pythonEnvPath ${CMAKE_CURRENT_BINARY_DIR}/venv)
set(pythonEnv ${pythonEnvPath}/bin/python)
add_custom_command(
OUTPUT ${pythonEnv}
COMMAND ${Python3_EXECUTABLE} -m venv ${pythonEnvPath}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt
COMMAND ${pythonEnv} -m pip install --upgrade pip
COMMAND ${pythonEnv} -m pip install -r ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt
)
add_custom_target(venv DEPENDS ${pythonEnv})
function(SBEMakeCodec TARGET)
set(options)
set(oneValueArgs SCHEMA OUTPUT GENERATOR)
set(multiValueArgs)
cmake_parse_arguments(PARSED "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_custom_command(
OUTPUT ${PARSED_OUTPUT}/schema.h
DEPENDS ${PARSED_SCHEMA} venv
COMMAND ${pythonEnv} -m app --schema="${PARSED_SCHEMA}" --destination="${PARSED_OUTPUT}" --generator="${PARSED_GENERATOR}"
WORKING_DIRECTORY ${cppCodeGenRoot}
COMMENT "generating schema (${PARSED_SCHEMA})"
)
add_library(${TARGET} INTERFACE)
target_compile_features(${TARGET} INTERFACE cxx_std_20)
target_sources(${TARGET} INTERFACE ${PARSED_OUTPUT}/schema.h)
target_include_directories(${TARGET} INTERFACE "${PARSED_OUTPUT}")
endfunction()
add_subdirectory(tests EXCLUDE_FROM_ALL)
add_subdirectory(example EXCLUDE_FROM_ALL)