diff --git a/.vscode/settings.json b/.vscode/settings.json index cdf8330..ec4ed88 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,13 +1,13 @@ { - "files.associations": { - "*.rh": "cpp" - }, - "cmake.buildDirectory":"${workspaceFolder}/build", - "cmake.mingwSearchDirs": [ - "D:\\qt\\Tools\\mingw730_32", - "D:\\qt\\Tools\\mingw730_64" - ], - "terminal.integrated.env.windows": { - }, - "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" -} \ No newline at end of file + "files.associations": { + "*.rh": "cpp", + "iostream": "cpp" + }, + "cmake.buildDirectory": "${workspaceFolder}/build", + "cmake.mingwSearchDirs": [ + "H:\\Qt\\5.14.0\\mingw73_64", + "H:\\Qt\\5.14.0\\mingw73_32" + ], + "terminal.integrated.env.windows": {}, + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" +} diff --git a/CMakeLists.txt b/CMakeLists.txt index f376690..10b5f10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,10 @@ add_subdirectory(general) find_package(libevent REQUIRED) set(EVENT__HAVE_LIBEVENT 1) +message(STATUS "PATH: " $ENV{CMAKE_MODULE_PATH}) -message(STATUS "libevent include: " ${libevent_INCLUDE_DIR}) -message(STATUS "libevent lib: " ${libevent_LIBRARIES}) +message(STATUS "libevent include: " ${libevent_INCLUDE_DIRS}) +message(STATUS "libevent lib: " ${libevent_INCLUDE_DIR}) message(STATUS "libevent lib Dirs: " ${libevent_LIB_DIRS}) SET(SRC_SDK sdk_main.c )#生成动态库需要至少包含一个源文件 @@ -77,7 +78,7 @@ add_custom_command(TARGET generallib PRE_LINK COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/general/src/math/eigen ${LIBRARY_OUTPUT_PATH}/inc/math/eigen) message( "copy third library") file(GLOB THIRD ${PROJECT_SOURCE_DIR}/general/third/include/*) -file(COPY ${THIRD} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/third/ +file(COPY ${THIRD} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/third/include/ FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) message( "copy net ") diff --git a/conanfile.py b/conanfile.py index a933bd2..045ff65 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,5 +1,6 @@ from conans import ConanFile, CMake, tools from conans import tools +import shutil class GenerallibConan(ConanFile): source_folder = "pkgsrc" @@ -9,15 +10,17 @@ class GenerallibConan(ConanFile): author = "caiyuzheng" url = "https://gitee.com/290198252/generallib" description = "a simple cpp basic library" - exports_sources = "general*", "test*" + generators = "cmake_find_package" + def source(self): tools.rmdir("pkgsrc") - git = tools.Git(folder=self.source_folder + "/pkgsrc") + git = tools.Git(folder=self.source_folder + "/pkgsrc", verify_ssl=False) git.clone("https://gitee.com/290198252/generallib.git") def package(self): - self.copy(pattern ="*.h", dst="include", src="general",keep_path=True) - self.copy(pattern ="*.hpp", dst="include", src="general",keep_path=True) + self.copy(pattern = "*.a",src ="pkgsrc\\obj\\",dst = "lib",keep_path=True) + shutil.copytree(self.build_folder + '\\pkgsrc\\obj\\inc', self.package_folder + "\\include\\generallib") + def build(self): cmake = CMake(self) @@ -31,8 +34,11 @@ class GenerallibConan(ConanFile): print("cygwin build") if tools.get_env("BUILD_ENV")=="msys": print("msys build") - tools.run_in_windows_bash(self, subsystem="msys",cwd="pkgsrc",msys_mingw=True,bashcmd="cmake build -G\"MinGW Makefiles\" " + tools.unix_path(self.source_folder + "/pkgsrc")) - tools.run_in_windows_bash(self, subsystem="msys",cwd="pkgsrc",msys_mingw=True,bashcmd="cmake --build . ") + tools.run_in_windows_bash(self, subsystem="msys", cwd="pkgsrc", bashcmd="cmake build -DCMAKE_MODULE_PATH=" + tools.unix_path(self.source_folder) + + " -G\"MinGW Makefiles\" " + tools.unix_path(self.source_folder) + "//pkgsrc") + tools.run_in_windows_bash( + self, subsystem="msys", cwd="pkgsrc", bashcmd="cmake --build .") def requirements(self): - self.requires("libevent/2.1.2", private=True, override=False) \ No newline at end of file + self.requires("libevent/2.1.2") + \ No newline at end of file diff --git a/general/CMakeLists.txt b/general/CMakeLists.txt index f2a6f2e..74f5958 100644 --- a/general/CMakeLists.txt +++ b/general/CMakeLists.txt @@ -1,9 +1,7 @@ cmake_minimum_required(VERSION 3.11) enable_language(CXX) project(General) -set(MINGW_PATH $ENV{MINGW_TOOLCHAIN}) -message("path is " ${MINGW_PATH}) -message( "libevent path " ${CONAN_LIBEVENT_ROOT}) + message( "current compiler " ${CMAKE_CXX_COMPILER_ID}) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") @@ -25,6 +23,7 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") endif() SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/obj) +message( "LIBRARY_OUTPUT_PATH " ${LIBRARY_OUTPUT_PATH}) set(CMAKE_CXX_STANDARD 11) INCLUDE_DIRECTORIES (./) INCLUDE_DIRECTORIES (inc) diff --git a/general/src/function/Timer.h b/general/src/function/Timer.h index d24ab52..6ba514e 100644 --- a/general/src/function/Timer.h +++ b/general/src/function/Timer.h @@ -3,7 +3,7 @@ // ======= // High Resolution Timer. // This timer is able to measure the elapsed time with 1 micro-second accuracy -// in both Windows, Linux and Unix system +// in both Windows, Linux and Unix system // // AUTHOR: Song Ho Ahn (song.ahn@gmail.com) // CREATED: 2003-01-13 @@ -15,41 +15,37 @@ #ifndef TIMER_H_DEF #define TIMER_H_DEF -#if defined(WIN32) || defined(_WIN32) // Windows system specific +#if defined(WIN32) || defined(_WIN32) // Windows system specific #include -#else // Unix based system specific +#else // Unix based system specific #include #endif - class Timer { public: - Timer(); // default constructor - ~Timer(); // default destructor - - void start(); // start timer - void stop(); // stop the timer - double getElapsedTime(); // get elapsed time in second - double getElapsedTimeInSec(); // get elapsed time in second (same as getElapsedTime) - double getElapsedTimeInMilliSec(); // get elapsed time in milli-second - double getElapsedTimeInMicroSec(); // get elapsed time in micro-second + Timer(); // default constructor + ~Timer(); // default destructor + void start(); // start timer + void stop(); // stop the timer + double getElapsedTime(); // get elapsed time in second + double getElapsedTimeInSec(); // get elapsed time in second (same as getElapsedTime) + double getElapsedTimeInMilliSec(); // get elapsed time in milli-second + double getElapsedTimeInMicroSec(); // get elapsed time in micro-second protected: - - private: - double startTimeInMicroSec; // starting time in micro-second - double endTimeInMicroSec; // ending time in micro-second - int stopped; // stop flag + double startTimeInMicroSec; // starting time in micro-second + double endTimeInMicroSec; // ending time in micro-second + int stopped; // stop flag #if defined(WIN32) || defined(_WIN32) - LARGE_INTEGER frequency; // ticks per second - LARGE_INTEGER startCount; // - LARGE_INTEGER endCount; // + LARGE_INTEGER frequency; // ticks per second + LARGE_INTEGER startCount; // + LARGE_INTEGER endCount; // #else - timeval startCount; // - timeval endCount; // + timeval startCount; // + timeval endCount; // #endif }; diff --git a/test/src/tcptest/CMakeLists.txt b/test/src/tcptest/CMakeLists.txt index 4055c76..267f8f9 100644 --- a/test/src/tcptest/CMakeLists.txt +++ b/test/src/tcptest/CMakeLists.txt @@ -1,13 +1,18 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.11) project(tcptest) +message("cmake module " $ENV{CMAKE_MODULE_PATH}) +message("project dir " ${PROJECT_SOURCE_DIR}) +message("current dir " ${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc) -message("current dir" ../..) -include_directories(../../../../general/obj/inc) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../general/obj/inc/third/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc) -link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake-build-debug/libgenerallib.a) -link_libraries(libGeneral.a) +link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../build) +link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../obj) + +link_libraries(libgenerallib.a) link_libraries(ws2_32) -link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/../../third/lib/libevent.a) -link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/../../third/lib/libevent_core.a) -add_executable(tcptest tcpclient_test.cpp) \ No newline at end of file +link_libraries(libevent.la) +link_libraries(libevent_core.la) +add_executable(tcptest tcpclient_test.cpp) + +target_include_directories(tcptest SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../obj/inc/third/include()) diff --git a/test/src/tcptest/tcpclient_test.cpp b/test/src/tcptest/tcpclient_test.cpp index 5fd9f00..b25723b 100644 --- a/test/src/tcptest/tcpclient_test.cpp +++ b/test/src/tcptest/tcpclient_test.cpp @@ -1,5 +1,8 @@ #include "TcpClient.h" +#include +#include +using namespace std; int main(){ TcpClientLibevent mTcp("127.0.0.1",8443, nullptr); } \ No newline at end of file