This new structure provides several benefits:
* Allows us to install multiple CMake projects in the same destination
dir (without include path conflicts).
- This makes shipping the trading algo sdk a trivial excercise. Simply
copy the lib and include dirs from the install dest. That's it!
* Puts us in a position to break up the monolithic libspark into smaller
modules, which are easier to manage.
Windows specific notes:
* Get rid of unnecessary script vs_filters.cmake
* Define WebsocketConnectionGateway directly in cs (instead of proto)
- The proto would no longer be in the include path passed to protoc.
Moving it to c# because there wasn't a compelling reason for it to
be a proto in the first place.
* Set spark output prefix to "lib" on windows
- So we get "libspark.dll" instead of "spark.dll", which conflicts
with the csharp lib, "Spark.dll".
* Copy libspark.dll to net8.0 & net8.0-windows in a single cmake build
target
fix build: Copy libspark to both dirs net8.0, net8.0-windows
165 lines
6.3 KiB
CMake
165 lines
6.3 KiB
CMake
set(Protobuf_PROTOC_EXECUTABLE "${EXTERNALS_BIN}/protoc")
|
|
set(PROTOBUF_INCLUDE_DIRS "${EXTERNALS_INCLUDE}")
|
|
set(PROTOBUF_STATIC_LIB "libprotobuf")
|
|
set(_protobuf_src_dir ${CMAKE_SOURCE_DIR}/src/lib_spark)
|
|
set(_protobuf_bin_dir ${CMAKE_BINARY_DIR}/src/lib_spark)
|
|
|
|
function(Protobuf_Generate_Cpp)
|
|
set(_options)
|
|
set(_one_value_args CXX_SOURCES CXX_HEADERS CXX_OUT_DIR)
|
|
set(_multi_value_args PROTO_INCLUDE_DIRS PROTO_SOURCES)
|
|
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
|
set(${_ARGS_CXX_SOURCES})
|
|
set(${_ARGS_CXX_HEADERS})
|
|
|
|
set(_proto_include_cli_args)
|
|
foreach(_dir ${_ARGS_PROTO_INCLUDE_DIRS})
|
|
list(APPEND _proto_include_cli_args -I ${_dir})
|
|
endforeach()
|
|
|
|
foreach(FIL ${_ARGS_PROTO_SOURCES})
|
|
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
|
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
|
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
|
|
if(FIL_DIR)
|
|
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
|
|
endif()
|
|
|
|
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc")
|
|
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h")
|
|
|
|
add_custom_command(
|
|
OUTPUT "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h"
|
|
COMMAND
|
|
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${_ARGS_CXX_OUT_DIR} ${_proto_include_cli_args} ${ABS_FIL}
|
|
DEPENDS ${ABS_FIL}
|
|
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
|
|
VERBATIM)
|
|
endforeach()
|
|
|
|
set_source_files_properties(${${_ARGS_CXX_SOURCES}} ${${_ARGS_CXX_HEADERS}} PROPERTIES GENERATED TRUE)
|
|
|
|
# remove some warnings from protobuf generated files
|
|
if(WIN32)
|
|
set_source_files_properties(${${_ARGS_CXX_SOURCES}} PROPERTIES COMPILE_FLAGS
|
|
"/wd4309 /wd4838")
|
|
else()
|
|
set_source_files_properties(
|
|
${${_ARGS_CXX_SOURCES}}
|
|
PROPERTIES
|
|
COMPILE_FLAGS
|
|
"-Wno-unused-parameter -Wno-effc++ -Wno-pedantic -Wno-sign-compare -Wno-uninitialized"
|
|
)
|
|
endif()
|
|
|
|
set(${_ARGS_CXX_SOURCES}
|
|
${${_ARGS_CXX_SOURCES}}
|
|
PARENT_SCOPE)
|
|
set(${_ARGS_CXX_HEADERS}
|
|
${${_ARGS_CXX_HEADERS}}
|
|
PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
function(Service_Compiler_Generate_Cpp)
|
|
set(_options)
|
|
set(_one_value_args CXX_SOURCES CXX_HEADERS CXX_OUT_DIR)
|
|
set(_multi_value_args PROTO_INCLUDE_DIRS PROTO_SOURCES)
|
|
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
|
set(${_ARGS_CXX_SOURCES})
|
|
set(${_ARGS_CXX_HEADERS})
|
|
|
|
set(_proto_include_cli_args)
|
|
foreach(_dir ${_ARGS_PROTO_INCLUDE_DIRS})
|
|
list(APPEND _proto_include_cli_args -I ${_dir})
|
|
endforeach()
|
|
|
|
foreach(FIL ${_ARGS_PROTO_SOURCES})
|
|
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
|
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
|
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
|
|
if(FIL_DIR)
|
|
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
|
|
endif()
|
|
|
|
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc")
|
|
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h")
|
|
|
|
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.cc")
|
|
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.h")
|
|
|
|
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.cc")
|
|
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.h")
|
|
|
|
set(TEMPLATES
|
|
${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/templates/cpp/client.pb.cc
|
|
${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/templates/cpp/client.pb.h
|
|
${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/templates/cpp/server.pb.cc
|
|
${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/templates/cpp/server.pb.h
|
|
)
|
|
|
|
set(_plugin_py ${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/plugin.py)
|
|
if(WIN32)
|
|
set(_plugin_cmd ${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/plugin.cmd)
|
|
add_custom_command(
|
|
OUTPUT "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.cc"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.h"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.cc"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.h"
|
|
COMMAND SET PYTHONPATH=${SPARK_PYTHON}
|
|
COMMAND ${CMAKE_SOURCE_DIR}/.venv/Scripts/activate.bat
|
|
COMMAND
|
|
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${_ARGS_CXX_OUT_DIR}
|
|
--plugin=protoc-gen-service=${_plugin_cmd}
|
|
--service_out=lang=cpp:${_ARGS_CXX_OUT_DIR} -I
|
|
${PROTOBUF_INCLUDE_DIRS} -I ${_protobuf_src_dir} ${ABS_FIL}
|
|
DEPENDS ${ABS_FIL} ${TEMPLATES} ${_plugin_cmd} ${_plugin_py}
|
|
COMMENT "Running C++ service compiler on ${FIL}"
|
|
VERBATIM)
|
|
else()
|
|
add_custom_command(
|
|
OUTPUT "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.cc"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.h"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.cc"
|
|
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.h"
|
|
COMMAND ${CMAKE_SOURCE_DIR}/tools/venv_exec.sh
|
|
ARGS
|
|
${Protobuf_PROTOC_EXECUTABLE}
|
|
--cpp_out=${_ARGS_CXX_OUT_DIR}
|
|
--plugin=protoc-gen-service=${_plugin_py}
|
|
--service_out=lang=cpp,make_file_name=${ABS_FIL}:${_ARGS_CXX_OUT_DIR}
|
|
${_proto_include_cli_args} ${ABS_FIL}
|
|
DEPENDS ${ABS_FIL} ${TEMPLATES} ${_plugin_py}
|
|
COMMENT "Running C++ service compiler on ${FIL}"
|
|
VERBATIM)
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
# remove some warnings from protobuf generated files
|
|
if(WIN32)
|
|
set_source_files_properties(${${_ARGS_CXX_SOURCES}} PROPERTIES COMPILE_FLAGS
|
|
"/wd4309 /wd4838")
|
|
else()
|
|
set_source_files_properties(
|
|
${${_ARGS_CXX_SOURCES}}
|
|
PROPERTIES
|
|
COMPILE_FLAGS
|
|
"-Wno-unused-parameter -Wno-effc++ -Wno-pedantic -Wno-sign-compare -Wno-uninitialized"
|
|
)
|
|
endif()
|
|
|
|
set(${_ARGS_CXX_SOURCES}
|
|
${${_ARGS_CXX_SOURCES}}
|
|
PARENT_SCOPE)
|
|
set(${_ARGS_CXX_HEADERS}
|
|
${${_ARGS_CXX_HEADERS}}
|
|
PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|