Skip to content

Commit

Permalink
using venv
Browse files Browse the repository at this point in the history
  • Loading branch information
ksergey committed Nov 8, 2023
1 parent 70de97e commit 84db923
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ cmake_minimum_required(VERSION 3.14)

project(sbe-code-gen)

find_package(PythonInterp 3.4 REQUIRED)

set(CPP_CODE_GEN_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
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)
Expand All @@ -15,23 +26,17 @@ function(SBEMakeCodec TARGET)

add_custom_command(
OUTPUT ${PARSED_OUTPUT}/schema.h
COMMAND ${PYTHON_EXECUTABLE} -m app --schema="${PARSED_SCHEMA}" --destination="${PARSED_OUTPUT}" --generator="${PARSED_GENERATOR}"
DEPENDS ${PARSED_SCHEMA}
WORKING_DIRECTORY ${CPP_CODE_GEN_ROOT}
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} PUBLIC ${PARSED_OUTPUT}/schema.h)
target_sources(${TARGET} INTERFACE ${PARSED_OUTPUT}/schema.h)
target_include_directories(${TARGET} INTERFACE "${PARSED_OUTPUT}")
endfunction()

add_custom_target(InstallRequirements
COMMAND ${PYTHON_EXECUTABLE} -m pip install -r requirements.txt
WORKING_DIRECTORY ${CPP_CODE_GEN_ROOT}
COMMENT install requirements
)

add_subdirectory(tests EXCLUDE_FROM_ALL)
add_subdirectory(example EXCLUDE_FROM_ALL)

0 comments on commit 84db923

Please sign in to comment.