tc_port add getEnv/setEnv, exec command

This commit is contained in:
ruanshudong 2020-03-30 18:13:05 +08:00
parent 121adade0d
commit fc4578e0c0
5 changed files with 35 additions and 13 deletions

View File

@ -29,15 +29,11 @@ endif()
#-------------------------------------------------------------
if("${INSTALL_PREFIX}" STREQUAL "")
IF (UNIX)
set(INSTALL_PREFIX "/usr/local/tars/cpp")
ELSE()
set(INSTALL_PREFIX "c:\\tars\\cpp")
ENDIF()
set(CMAKE_INSTALL_PREFIX ${INSTALL_PREFIX})
endif()
IF (UNIX)
set(CMAKE_INSTALL_PREFIX "/usr/local/tars/cpp" CACHE STRING "set install path" FORCE)
ELSE()
set(CMAKE_INSTALL_PREFIX "c:\\tars\\cpp" CACHE STRING "set install path" FORCE)
ENDIF()
#-------------------------------------------------------------
IF (APPLE)
@ -89,7 +85,7 @@ message("CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message("PLATFORM: ${PLATFORM}")
message("INSTALL_PREFIX: ${INSTALL_PREFIX}")
message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
message("BIN: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
message("TARS2CPP: ${TARS2CPP}")
#-------------------------------------------------------------

View File

@ -37,7 +37,7 @@ macro(complice_tars OUT_DEPENDS_LIST HEADER TARS_DIR)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${TARS_H}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS tars2cpp ${TARS_IN}
DEPENDS tars2cpp ${FILE}
COMMAND ${TARS2CPP} --with-tars ${INCLUDE} ${TARS_IN}
COMMENT "${TARS2CPP} --with-tars ${INCLUDE} ${TARS_IN}")

@ -1 +1 @@
Subproject commit ed2cb055d5799d45bdeeec920092ee3fccd85e2b
Subproject commit 8d1993be26db9792f581e779890fb83fec0b9de4

View File

@ -66,6 +66,8 @@ public:
static std::string getEnv(const std::string &name);
static void setEnv(const std::string &name, const std::string &value);
static std::string exec(const char* cmd);
};
}

View File

@ -189,4 +189,28 @@ void TC_Port::setEnv(const string &name, const string &value)
setenv(name.c_str(), value.c_str(), true);
#endif
}
}
string TC_Port::exec(const char *cmd)
{
string fileData;
#if TARGET_PLATFORM_WINDOWS
FILE* fp = _popen(cmd, "r");
#else
FILE* fp = popen(cmd, "r");
#endif
static size_t buf_len = 2 * 1024 * 1024;
char *buf = new char[buf_len];
memset(buf, 0, buf_len);
fread(buf, sizeof(char), buf_len - 1, fp);
#if TARGET_PLATFORM_WINDOWS
_pclose(fp);
#else
pclose(fp);
#endif
fileData = string(buf);
delete []buf;
return fileData;
}
}