From 94e06538fcd4bac6bb8960e16d44d52a1752edf6 Mon Sep 17 00:00:00 2001 From: Greg Williamson Date: Thu, 9 Apr 2020 19:49:40 -0400 Subject: [PATCH] Build emake as part of release. (#107) Partner of enigma-dev/enigma-dev#1931 --- CMakeLists.txt | 64 ++++++++++++++++++++++++++----------- Plugins/ServerPlugin.cpp | 68 ++++++++++++++++++++++++++++++++++++---- Submodules/enigma-dev | 2 +- 3 files changed, 108 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d47fbc616..348337364 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,33 @@ -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.14) +project(RadialGM) + +include(CMakeDependentOption) option(RGM_ENABLE_GRPC_SERVER "Enable the GRPC client plugin for compilation and code analysis." ON) +option(RGM_BUILD_EMAKE "Build Emake and the compiler." ON) + +# FIXME: MSVC dynamic linking requires US TO DLLEXPORT our funcs +# since we currently don't, I'm force disabling the option on MSVC +cmake_dependent_option(RGM_BUILD_STATIC "Build static libs." ON "MSVC" OFF) + +if (RGM_BUILD_STATIC) + set(LIB_TYPE STATIC) +else() + set(LIB_TYPE SHARED) +endif() if (CMAKE_BUILD_TYPE MATCHES "Debug") set(EXE "RadialGM-Debug") + add_definitions(-DRGM_DEBUG) else() set(EXE "RadialGM") endif() set(EXE_DESCRIPTION "ENIGMA IDE") -project(RadialGM) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +SET(CMAKE_SKIP_BUILD_RPATH ON) +set(CMAKE_INSTALL_RPATH $ORIGIN) # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -28,7 +45,7 @@ set(CMAKE_AUTOUIC_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/Dialogs") # Include ENIGMA things set(ENIGMA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Submodules/enigma-dev) -include_directories("${CMAKE_BINARY_DIR}/Submodules/enigma-dev/CommandLine/libEGM/libProtocols" "${ENIGMA_DIR}/CommandLine/libEGM") +include_directories("${CMAKE_BINARY_DIR}/Submodules/enigma-dev/shared/protos/" "${ENIGMA_DIR}/CommandLine/libEGM" "${ENIGMA_DIR}/shared") # Populate a CMake variable with the sources set(RGM_SOURCES @@ -164,9 +181,6 @@ if (RGM_ENABLE_GRPC_SERVER) set(RGM_HEADERS ${RGM_HEADERS} Plugins/ServerPlugin.h) endif() - -set(CMAKE_INSTALL_RPATH "${ENIGMA_DIR}") - # Tell CMake to create the RadialGM executable add_executable(${EXE} WIN32 ${RGM_UI} ${RGM_HEADERS} ${RGM_SOURCES} ${EDITOR_SOURCES} ${RGM_RC}) @@ -240,9 +254,11 @@ find_package(Qt5 COMPONENTS Core Widgets Gui PrintSupport Multimedia REQUIRED) target_link_libraries(${EXE} PRIVATE Qt5::Core Qt5::Widgets Qt5::Gui Qt5::PrintSupport Qt5::Multimedia) # LibProto +add_subdirectory(Submodules/enigma-dev/shared) +add_subdirectory(Submodules/enigma-dev/shared/protos) add_subdirectory(Submodules/enigma-dev/CommandLine/libEGM) add_dependencies(${EXE} "EGM") -target_link_libraries(${EXE} PRIVATE "EGM" "Protocols") +target_link_libraries(${EXE} PRIVATE "EGM" "Protocols" "ENIGMAShared") # Find FreeType find_package(Freetype REQUIRED) @@ -270,19 +286,27 @@ if(WIN32) target_link_libraries(${EXE} PRIVATE Ws2_32 Wtsapi32 Wldap32 Crypt32 Winmm Userenv Netapi32 version Dwmapi Imm32) endif(WIN32) -install(TARGETS ${EXE} RUNTIME DESTINATION .) - if(MSVC) - # Default MSVC warnings are overkill. Set to Lvl 2 - target_compile_options(${EXE} PRIVATE /W1) - target_compile_options("EGM" PRIVATE /W1) - target_compile_options("Protocols" PRIVATE /W1) + # Default MSVC warnings are overkill. Set to Lvl 2 + target_compile_options(${EXE} PRIVATE /W1) +endif() + +if (RGM_BUILD_EMAKE) + add_subdirectory(Submodules/enigma-dev/CompilerSource) + add_subdirectory(Submodules/enigma-dev/CommandLine/emake) + if (CMAKE_BUILD_TYPE MATCHES "Debug") + set(CLI_TARGET "emake-debug") + else() + set(CLI_TARGET "emake") + endif() + add_dependencies(${EXE} ${CLI_TARGET}) endif() -install(TARGETS "Protocols" DESTINATION .) -install(TARGETS "EGM" DESTINATION .) +install(TARGETS ${EXE} RUNTIME DESTINATION .) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${EXE}.dir/Debug/${EXE}.pdb" DESTINATION . OPTIONAL) -set(APPS "${CMAKE_INSTALL_PREFIX}/${EXE}${CMAKE_EXECUTABLE_SUFFIX}") +set(RGM_APP "${CMAKE_INSTALL_PREFIX}/${EXE}${CMAKE_EXECUTABLE_SUFFIX}") +set(EMAKE_APP "${CMAKE_INSTALL_PREFIX}/${CLI_TARGET}${CMAKE_EXECUTABLE_SUFFIX}") if (MSVC) file(TO_CMAKE_PATH ${VCPKG_ROOT} VCPKG_ROOT) @@ -293,7 +317,8 @@ file(TO_CMAKE_PATH ${VCPKG_ROOT} VCPKG_ROOT) endif() else() set(LIBS "${CMAKE_INSTALL_PREFIX}/${CMAKE_SHARED_LIBRARY_PREFIX}EGM${CMAKE_SHARED_LIBRARY_SUFFIX}" - "${CMAKE_INSTALL_PREFIX}/${CMAKE_SHARED_LIBRARY_PREFIX}Protocols${CMAKE_SHARED_LIBRARY_SUFFIX}") + "${CMAKE_INSTALL_PREFIX}/${CMAKE_SHARED_LIBRARY_PREFIX}Protocols${CMAKE_SHARED_LIBRARY_SUFFIX}" + "${CMAKE_INSTALL_PREFIX}/${CMAKE_SHARED_LIBRARY_PREFIX}ENIGMAShared${CMAKE_SHARED_LIBRARY_SUFFIX}") endif() if (WIN32) @@ -314,7 +339,8 @@ if (WIN32) install(CODE " include(BundleUtilities) - fixup_bundle(\"${APPS}\" \"${LIBS}\" \"${SEARCH_PATHS}\") - execute_process(COMMAND windeployqt.exe ${WINDEPLOY_ARGS} ${APPS}) + fixup_bundle(\"${RGM_APP}\" \"${LIBS}\" \"${SEARCH_PATHS}\") + fixup_bundle(\"${EMAKE_APP}\" \"${LIBS}\" \"${SEARCH_PATHS}\") + execute_process(COMMAND windeployqt.exe ${WINDEPLOY_ARGS} ${RGM_APP}) ") endif() diff --git a/Plugins/ServerPlugin.cpp b/Plugins/ServerPlugin.cpp index 72ddb415d..919df2942 100644 --- a/Plugins/ServerPlugin.cpp +++ b/Plugins/ServerPlugin.cpp @@ -242,23 +242,75 @@ void CompilerClient::UpdateLoop(void* got_tag, bool ok) { ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) { // create a new child process for us to launch an emake server process = new QProcess(this); + + connect(process, &QProcess::errorOccurred, [&](QProcess::ProcessError error) { + qDebug() << "QProcess error: " << error << endl; + }); + connect(process, &QProcess::readyReadStandardOutput, [&]() { + emit LogOutput(process->readAllStandardOutput()); + }); + connect(process, &QProcess::readyReadStandardError, [&]() { + emit LogOutput(process->readAllStandardError()); + }); + + #ifdef _WIN32 + //TODO: Make all this stuff configurable in IDE + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + + // FIXME: this is just an approximate guess on how to get emake running outside a msys shell and currently causes emake to crash + QString msysPath; + if (!env.contains("MSYS_ROOT")) { + msysPath = env.value("SystemDrive", "C:") + "/msys64"; + qDebug().noquote() << "Environmental variable \"MSYS_ROOT\" is not set defaulting MSYS path to: " + msysPath; + } else msysPath = env.value("MSYS_ROOT"); + + env.insert("PATH", env.value("PATH") + ";" + msysPath + "/usr/bin;" + msysPath + "/mingw64/bin"); + process->setProcessEnvironment(env); + #endif // look for an executable file that looks like emake in some common directories - QList searchPaths = {QDir::currentPath(), "./enigma-dev", "../RadialGM/Submodules/enigma-dev"}; - QFileInfo emakeFileInfo(QFile("emake")); + QList searchPaths = {QDir::currentPath(), "./enigma-dev", "../enigma-dev", "../RadialGM/Submodules/enigma-dev"}; + #ifndef RGM_DEBUG + QString emakeName = "emake"; + #else + QString emakeName = "emake-debug"; + #endif + + QFileInfo emakeFileInfo; foreach (auto path, searchPaths) { const QDir dir(path); QDir::Filters filters = QDir::Filter::Executable | QDir::Filter::Files; - // we use a wildcard because we want it to find emake.exe on Windows - auto entryList = dir.entryInfoList(QStringList({"emake","emake.exe"}), filters, QDir::SortFlag::NoSort); + auto entryList = dir.entryInfoList(QStringList({emakeName, emakeName + ".exe"}), filters, QDir::SortFlag::NoSort); if (!entryList.empty()) { emakeFileInfo = entryList.first(); break; } } + + if (emakeFileInfo.filePath().isEmpty()) { + qDebug() << "Error: Failed to locate emake. Compiling and syntax check will not work.\n" << "Search Paths:\n" << searchPaths; + return; + } + + QFileInfo enigmaFileInfo; + foreach (auto path, searchPaths) { + const QDir dir(path); + QDir::Filters filters = QDir::Filter::AllEntries; + auto entryList = dir.entryInfoList(QStringList({"ENIGMAsystem"}), filters, QDir::SortFlag::NoSort); + if (!entryList.empty()) { + enigmaFileInfo = entryList.first(); + break; + } + } + + if (enigmaFileInfo.filePath().isEmpty()) { + qDebug() << "Error: Failed to locate ENIGMA sources. Compiling and syntax check will not work.\n" << "Search Paths:\n" << searchPaths; + return; + } // use the closest matching emake file we found and launch it in a child process - qDebug() << emakeFileInfo.absoluteFilePath(); + qDebug() << "Using emake exe at: " << emakeFileInfo.absolutePath(); + qDebug() << "Using ENIGMA sources at: " << enigmaFileInfo.absolutePath(); process->setWorkingDirectory(emakeFileInfo.absolutePath()); QString program = emakeFileInfo.fileName(); QStringList arguments; @@ -266,7 +318,11 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) { << "-e" << "Paths" << "-r" - << "--quiet"; + << "--quiet" + << "--enigma-root" + << enigmaFileInfo.absolutePath(); + + qDebug() << "Running: " << program << " " << arguments; process->start(program, arguments); process->waitForStarted(); diff --git a/Submodules/enigma-dev b/Submodules/enigma-dev index c868fabc2..3fa4e21ab 160000 --- a/Submodules/enigma-dev +++ b/Submodules/enigma-dev @@ -1 +1 @@ -Subproject commit c868fabc2a66c9bae79b4804ac89b1bdb225eb5d +Subproject commit 3fa4e21ab49e07370481cd1c35714d611bf1f9f6