Skip to content

Commit

Permalink
Fix install header issues. Install mxplug. Fix install dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
lPrimemaster committed Jan 12, 2025
1 parent 713d851 commit ffaf330
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 23 deletions.
34 changes: 28 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ option(LTRACE "Enable/Disable trace logging." OFF)
option(PROFILE "Enable/Disable profiling with tracy." OFF)
option(USB_SUPPORT "Enable/Disable bulk USB transfer support with libusb." ON)
option(ONLINE_TRANSPILER "Enable/Disable realtime transpiler for plugins. This is recommended OFF." OFF)
option(BUILD_TESTS "Build tests." OFF)
option(BUILD_EXAMPLES "Build examples." OFF)
option(BUILD_CTARGETS "Build extra targets." OFF)

# Use vcpkg if we are on windows
if(WIN32)
message(WARNING "On windows, all packages must be installed as x64-mingw-dynamic if using vcpkg.")
set(VCPKG_TARGET_TRIPLET "x64-mingw-dynamic" CACHE STRING "Vcpkg target triplet.")
endif()

if(ONLINE_TRANSPILER)
add_definitions(-DONLINE_TRANSPILER)
Expand Down Expand Up @@ -81,21 +90,32 @@ add_executable(mxmain
main.cpp
)

# Set global windows libs
if(WIN32)
set(WINDOWS_GLIBS pdh)
endif()

# Add mulex functionalities
add_subdirectory(network)
add_subdirectory(rdb)
add_subdirectory(drv)
add_subdirectory(run)
add_subdirectory(bck)
add_subdirectory(ctargets)
add_subdirectory(examples)
add_subdirectory(plug)

if(BUILD_CTARGETS)
add_subdirectory(ctargets)
endif()

if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

# Link main
target_link_libraries(mxmain PRIVATE mxrpc mxrdb mxdrv mxhttp)

if(WIN32)
target_link_libraries(mxmain PRIVATE pdh)
target_link_libraries(mxmain PRIVATE ${WINDOWS_GLIBS})
endif()

target_compile_definitions(mxmain PUBLIC L2FILE)
Expand All @@ -108,10 +128,12 @@ build_manifest_json()
build_frontend_yarn()

# Add testing
enable_testing()
add_subdirectory(test)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()

# Generate binary resources (last step)
# Generate binary resources (last configure step)

set(vite_config_ts ${CMAKE_SOURCE_DIR}/network/vite.config.ts)
mx_resource_append(${vite_config_ts})
Expand Down
15 changes: 12 additions & 3 deletions bck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,33 @@ add_library(MxBackend
)

if(WIN32)
target_link_libraries(MxBackend wsock32 ws2_32 Shlwapi)
target_link_libraries(MxBackend wsock32 ws2_32 Shlwapi pdh)
endif()

target_link_libraries(MxBackend mxrdb mxhttp mxrpc)

# Enforce c++20
target_compile_features(MxBackend PUBLIC cxx_std_20)

# Set MX_RPC_METHOD keyword as a no op
target_compile_definitions(MxBackend PUBLIC MX_RPC_METHOD=)

add_library(mxbck ALIAS MxBackend)

include(../cmake/InstallMulex.cmake)
set(LIB_DEPS
"find_package(ZLIB REQUIRED)
"
find_package(ZLIB REQUIRED)
find_package(Tracy REQUIRED)
find_package(MxRun REQUIRED)
find_package(MxRpc REQUIRED)
find_package(MxRdb REQUIRED)
find_package(uSockets REQUIRED)
find_package(RapidJSON REQUIRED)
find_package(base64 REQUIRED)
find_package(MxHttp REQUIRED)"
find_package(libuv REQUIRED)
find_package(MxHttp REQUIRED)
"
)
install_target(MxBackend mxbackend.h)
set(LIB_DEPS "")
28 changes: 18 additions & 10 deletions cmake/BuildFrontend.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,28 @@ endmacro()
macro(build_frontend_yarn)
# Build frontend at configure time
message(STATUS "Building frontend via 'yarn build'...")
execute_process(
COMMAND yarn build
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/frontend
RESULT_VARIABLE yarn_result
OUTPUT_VARIABLE yarn_output
ERROR_VARIABLE yarn_error
)

if(yarn_result)
message(FATAL_ERROR "Yarn build failed with error: ${yarn_error}")
if(WIN32)
set(YARN_CMD cmd.exe /C yarn)
else()
message(STATUS "Yarn build OK.")
set(YARN_CMD yarn)
endif()

if(NOT EXISTS ${CMAKE_SOURCE_DIR}/frontend/node_modules/)
message(STATUS "Fetching node dependencies...")
execute_process(
COMMAND ${YARN_CMD}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/frontend
COMMAND_ECHO STDOUT
)
endif()

execute_process(
COMMAND ${YARN_CMD} build
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/frontend
COMMAND_ECHO STDOUT
)

# Read the files back and embed them into the executable via mxres.h.in
file(GLOB_RECURSE files "${CMAKE_SOURCE_DIR}/frontend/dist/*")
foreach(file ${files})
Expand Down
23 changes: 22 additions & 1 deletion cmake/InstallMulex.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ macro(install_mulex)
# Install server binary
install(TARGETS mxmain DESTINATION bin)

# Install plugin manager
install(TARGETS mxplug DESTINATION bin)

# Common includes
install(FILES network/socket.h DESTINATION include/network)
install(FILES network/rpc.h DESTINATION include/network)

file(GLOB COMMON_HEADERS ${CMAKE_SOURCE_DIR}/*.h)
install(FILES ${COMMON_HEADERS} DESTINATION include)
# install(FILES mxbackend.h DESTINATION include)
# install(FILES mxdrv.h DESTINATION include)
# install(FILES mxevt.h DESTINATION include)
# install(FILES mxhttp.h DESTINATION include)
# install(FILES mxlogger.h DESTINATION include)
# install(FILES mxmsg.h DESTINATION include)
# install(FILES mxrdb.h DESTINATION include)
# install(FILES mxrun.h DESTINATION include)
# install(FILES mxsystem.h DESTINATION include)
# install(FILES mxtypes.h DESTINATION include)
endmacro()

macro(install_target target header)
Expand All @@ -19,8 +32,16 @@ macro(install_target target header)
INCLUDES DESTINATION include
)

set(extra_args ${ARGN})
list(LENGTH extra_args extra_count)
set(dir_arg "")

if(${extra_count} GREATER 0)
list(GET extra_args 0 dir_arg)
endif()

if(NOT ${header} STREQUAL NONE)
install(FILES ${CMAKE_SOURCE_DIR}/${header} DESTINATION include)
install(FILES ${CMAKE_SOURCE_DIR}/${header} DESTINATION include/${dir_arg})
endif()

set(LIB_TARGET ${target})
Expand Down
1 change: 1 addition & 0 deletions cmake/InternetConnection.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
macro(check_network_connection)
message(STATUS "Checking network internet connection status...")
if(WIN32)
execute_process(
COMMAND ping www.google.com -n 2
Expand Down
2 changes: 1 addition & 1 deletion network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ target_include_directories(MxRpc PRIVATE
)

add_library(mxrpc ALIAS MxRpc)
install_target(MxRpc network/rpc.h)
install_target(MxRpc network/rpc.h network)

add_library(MxHttp
mxhttp.cpp
Expand Down
4 changes: 2 additions & 2 deletions network/mxhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace mulex
command += serveDir;
command += "' build";
#endif
std::string filename = std::filesystem::path(file).filename();
std::string filename = std::filesystem::path(file).filename().string();
switch(op) {
case SysFileWatcher::FileOp::CREATED:
{
Expand All @@ -148,7 +148,7 @@ namespace mulex
}
case SysFileWatcher::FileOp::DELETED:
{
std::string filename = std::filesystem::path(file).filename();
std::string filename = std::filesystem::path(file).filename().string();
HttpRemoveUserPlugin(filename);
break;
}
Expand Down

0 comments on commit ffaf330

Please sign in to comment.