diff --git a/include/os/os.h b/include/os/os.h index e91edaab0f..d3f5e9f61b 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -20,26 +20,13 @@ extern "C" { #endif -#include "osInc.h" -#include "osDef.h" -#include "osAtomic.h" -#include "osDir.h" -#include "osFile.h" -#include "osLz4.h" -#include "osMath.h" -#include "osMemory.h" -#include "osRand.h" -#include "osSemaphore.h" -#include "osSignal.h" -#include "osSleep.h" -#include "osSocket.h" -#include "osString.h" -#include "osSysinfo.h" -#include "osTime.h" -#include "osTimer.h" -#include "osSystem.h" +#include +#include +#include +#include +#include -void osInit(); +#include "osMemory.h" #ifdef __cplusplus } diff --git a/include/os/osMemory.h b/include/os/osMemory.h new file mode 100644 index 0000000000..10c90cd9aa --- /dev/null +++ b/include/os/osMemory.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_OS_MEMORY_H_ +#define _TD_OS_MEMORY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define tfree(x) \ + do { \ + if (x) { \ + free((void *)x); \ + x = 0; \ + } \ + } while (0) + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_OS_MEMORY_H_*/ diff --git a/src/util/inc/talgo.h b/include/util/talgo.h similarity index 100% rename from src/util/inc/talgo.h rename to include/util/talgo.h diff --git a/src/util/inc/tcoding.h b/include/util/tcoding.h similarity index 99% rename from src/util/inc/tcoding.h rename to include/util/tcoding.h index ff34c15607..9825ab2bee 100644 --- a/src/util/inc/tcoding.h +++ b/include/util/tcoding.h @@ -19,11 +19,6 @@ extern "C" { #endif -#include -#include - -#include "tutil.h" - // TODO: move this to a platform file #define ENCODE_LIMIT (((uint8_t)1) << 7) static const int32_t TNUMBER = 1; diff --git a/src/util/inc/tlist.h b/include/util/tlist.h similarity index 100% rename from src/util/inc/tlist.h rename to include/util/tlist.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8f8f3462dc..32826f69ea 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,2 +1,4 @@ add_subdirectory(os) +add_subdirectory(util) +# add_subdirectory(common) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 4dce63e54f..57d4890f49 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,8 +1,11 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20) -PROJECT(TDengine) - -INCLUDE_DIRECTORIES(inc) -AUX_SOURCE_DIRECTORY(src SRC) - -ADD_LIBRARY(common ${SRC}) -TARGET_LINK_LIBRARIES(common tutil) +aux_source_directory(source COMMON_SRC) +add_library(common ${COMMON_SRC}) +target_include_directories( + common + PUBLIC "${CMAKE_SOURCE_DIR}/include/common" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" +) +target_include_directories( + common + PRIVATE util +) \ No newline at end of file diff --git a/src/os/CMakeLists.txt b/src/os/CMakeLists.txt index a64c9d79dd..4d3bf4d7dc 100644 --- a/src/os/CMakeLists.txt +++ b/src/os/CMakeLists.txt @@ -1,14 +1,7 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20) -PROJECT(TDengine) - -IF (TD_LINUX) - ADD_SUBDIRECTORY(src/linux) -ELSEIF (TD_DARWIN) - ADD_SUBDIRECTORY(src/darwin) -ELSEIF (TD_WINDOWS) - ADD_SUBDIRECTORY(src/windows) -ENDIF () - -ADD_SUBDIRECTORY(src/detail) -ADD_SUBDIRECTORY(tests) - +aux_source_directory(source OS_SRC) +add_library(os ${OS_SRC}) +target_include_directories( + os + PUBLIC "${CMAKE_SOURCE_DIR}/include/os" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" +) \ No newline at end of file diff --git a/src/os/source/os.c b/src/os/source/os.c new file mode 100644 index 0000000000..6dea4a4e57 --- /dev/null +++ b/src/os/source/os.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ \ No newline at end of file diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index ef304d2fcb..42d0bb6316 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -1,44 +1,11 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20) -PROJECT(TDengine) - -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sync/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/rmonotonic/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/TSZ/sz/include) - -AUX_SOURCE_DIRECTORY(src SRC) -ADD_LIBRARY(tutil ${SRC}) - -TARGET_LINK_LIBRARIES(tutil pthread os lz4 z rmonotonic ${VAR_TSZ} ) - - - -IF (TD_LINUX) - TARGET_LINK_LIBRARIES(tutil m rt) - ADD_SUBDIRECTORY(tests) - - FIND_PATH(ICONV_INCLUDE_EXIST iconv.h /usr/include/ /usr/local/include/) - IF (ICONV_INCLUDE_EXIST) - FIND_PATH(ICONV_LIBRARY_A_EXIST libiconv.a /usr/lib/ /usr/local/lib/ /lib64) - FIND_PATH(ICONV_LIBRARY_SO_EXIST libiconv.so /usr/lib/ /usr/local/lib/ /lib64) - IF (ICONV_LIBRARY_A_EXIST OR ICONV_LIBRARY_SO_EXIST) - MESSAGE(STATUS "Use the installed libiconv library") - TARGET_LINK_LIBRARIES(tutil iconv) - ELSE () - # libiconv library is already included in GLIBC, - MESSAGE(STATUS "Use the iconv functions in GLIBC") - ENDIF () - ELSE () - MESSAGE(STATUS "Failed to find iconv, use default encoding method") - ENDIF () - -ELSEIF (TD_WINDOWS) - TARGET_LINK_LIBRARIES(tutil iconv regex winmm IPHLPAPI ws2_32 wepoll) -ELSEIF(TD_DARWIN) - TARGET_LINK_LIBRARIES(tutil m) - TARGET_LINK_LIBRARIES(tutil iconv) -ENDIF() - -IF (TD_STORAGE) - TARGET_LINK_LIBRARIES(tutil storage) -ENDIF () +aux_source_directory(source UTIL_SRC) +add_library(util ${UTIL_SRC}) +target_include_directories( + util + PUBLIC "${CMAKE_SOURCE_DIR}/include/util" + PRIVATE "${CMAKE_SOURCE_DIR}/include" +) +target_link_libraries( + util + PRIVATE os +) \ No newline at end of file diff --git a/src/util/CMakeLists.txt.in b/src/util/CMakeLists.txt.in new file mode 100644 index 0000000000..ef304d2fcb --- /dev/null +++ b/src/util/CMakeLists.txt.in @@ -0,0 +1,44 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20) +PROJECT(TDengine) + +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sync/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/rmonotonic/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/TSZ/sz/include) + +AUX_SOURCE_DIRECTORY(src SRC) +ADD_LIBRARY(tutil ${SRC}) + +TARGET_LINK_LIBRARIES(tutil pthread os lz4 z rmonotonic ${VAR_TSZ} ) + + + +IF (TD_LINUX) + TARGET_LINK_LIBRARIES(tutil m rt) + ADD_SUBDIRECTORY(tests) + + FIND_PATH(ICONV_INCLUDE_EXIST iconv.h /usr/include/ /usr/local/include/) + IF (ICONV_INCLUDE_EXIST) + FIND_PATH(ICONV_LIBRARY_A_EXIST libiconv.a /usr/lib/ /usr/local/lib/ /lib64) + FIND_PATH(ICONV_LIBRARY_SO_EXIST libiconv.so /usr/lib/ /usr/local/lib/ /lib64) + IF (ICONV_LIBRARY_A_EXIST OR ICONV_LIBRARY_SO_EXIST) + MESSAGE(STATUS "Use the installed libiconv library") + TARGET_LINK_LIBRARIES(tutil iconv) + ELSE () + # libiconv library is already included in GLIBC, + MESSAGE(STATUS "Use the iconv functions in GLIBC") + ENDIF () + ELSE () + MESSAGE(STATUS "Failed to find iconv, use default encoding method") + ENDIF () + +ELSEIF (TD_WINDOWS) + TARGET_LINK_LIBRARIES(tutil iconv regex winmm IPHLPAPI ws2_32 wepoll) +ELSEIF(TD_DARWIN) + TARGET_LINK_LIBRARIES(tutil m) + TARGET_LINK_LIBRARIES(tutil iconv) +ENDIF() + +IF (TD_STORAGE) + TARGET_LINK_LIBRARIES(tutil storage) +ENDIF () diff --git a/src/util/src/talgo.c b/src/util/source/talgo.c similarity index 99% rename from src/util/src/talgo.c rename to src/util/source/talgo.c index 54b7e00eb7..b9aabd7c4a 100644 --- a/src/util/src/talgo.c +++ b/src/util/source/talgo.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "tutil.h" + #include "talgo.h" #define doswap(__left, __right, __size, __buf) do {\ diff --git a/src/util/src/tlist.c b/src/util/source/tlist.c similarity index 100% rename from src/util/src/tlist.c rename to src/util/source/tlist.c