diff --git a/default-cmake-options.cmake b/default-cmake-options.cmake index d4cb280..3a85356 100644 --- a/default-cmake-options.cmake +++ b/default-cmake-options.cmake @@ -7,10 +7,21 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wimplicit-int") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + +if (MSVC) +add_compile_options(/wd4061 /wd4819) +add_compile_options(/wd4477 /wd4244 /wd4245) +add_compile_options(/wd4820 /wd4365) +add_compile_options(/wd4267) +add_compile_options(/wd4623 /wd4625 /wd4626 /wd5027 /wd5045) #nlohmann::json +add_compile_options(/wd4668) +add_compile_options(/wd4996) +add_compile_options(/wd5039) +else() +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") - +endif() set(BUILD_TYPE "release") if (debug) diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index 98c744c..661bff0 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -6,4 +6,7 @@ project(hakoniwa-core add_subdirectory(base-procs/hako-master) add_subdirectory(base-procs/hako-asset) -add_subdirectory(base-procs/hako-cmd) \ No newline at end of file +if(MSVC) +else() +add_subdirectory(base-procs/hako-cmd) +endif() \ No newline at end of file diff --git a/sample/base-procs/hako-asset/CMakeLists.txt b/sample/base-procs/hako-asset/CMakeLists.txt index 4198184..d782a86 100644 --- a/sample/base-procs/hako-asset/CMakeLists.txt +++ b/sample/base-procs/hako-asset/CMakeLists.txt @@ -10,11 +10,18 @@ add_executable( src/hako_asset.cpp ) +if(MSVC) +target_link_libraries( + hako-asset + hako +) +else() target_link_libraries( hako-asset hako -pthread ) +endif() #message(STATUS "HAKO_INTERFACE_DIR=" ${HAKO_INTERFACE_DIR}) diff --git a/sample/base-procs/hako-asset/src/hako_asset.cpp b/sample/base-procs/hako-asset/src/hako_asset.cpp index b8b7629..4ce06eb 100644 --- a/sample/base-procs/hako-asset/src/hako_asset.cpp +++ b/sample/base-procs/hako-asset/src/hako_asset.cpp @@ -1,7 +1,11 @@ #include #include #include +#include +#if WIN32 +#else #include +#endif #include #include #include diff --git a/sample/base-procs/hako-master/CMakeLists.txt b/sample/base-procs/hako-master/CMakeLists.txt index a34415a..f67f19f 100644 --- a/sample/base-procs/hako-master/CMakeLists.txt +++ b/sample/base-procs/hako-master/CMakeLists.txt @@ -9,12 +9,19 @@ add_executable( hako-master src/hako_master.cpp ) - +if(MSVC) +target_link_libraries( + hako-master + hako +) +else() target_link_libraries( hako-master hako -pthread ) +endif() + #message(STATUS "HAKO_INTERFACE_DIR=" ${HAKO_INTERFACE_DIR}) diff --git a/sample/base-procs/hako-master/src/hako_master.cpp b/sample/base-procs/hako-master/src/hako_master.cpp index 30cc344..d0e61e8 100644 --- a/sample/base-procs/hako-master/src/hako_master.cpp +++ b/sample/base-procs/hako-master/src/hako_master.cpp @@ -1,7 +1,11 @@ #include #include #include +#include +#if WIN32 +#else #include +#endif #include static bool hako_master_is_end = false; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c6a8555..f39cc10 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,8 @@ target_include_directories( PRIVATE ${PROJECT_SOURCE_DIR}/hako PRIVATE ${nlohmann_json_SOURCE_DIR}/single_include ) -if(WIN32) +if (MSVC) +elseif(WIN32) target_link_libraries(hako stdc++) +else() endif() diff --git a/src/hako/core/context/hako_context.hpp b/src/hako/core/context/hako_context.hpp index 5406993..f2c5708 100644 --- a/src/hako/core/context/hako_context.hpp +++ b/src/hako/core/context/hako_context.hpp @@ -8,10 +8,14 @@ namespace hako::core::context { public: HakoContext() { +#ifdef _WIN32 + this->pid_ = GetCurrentProcessId(); +#else this->pid_ = getpid(); +#endif } - pid_t get_pid() + pid_type get_pid() { return this->pid_; } @@ -20,7 +24,7 @@ namespace hako::core::context { { return (context.get_pid() == this->get_pid()); } - bool is_same(pid_t pid) + bool is_same(pid_type pid) { return (this->get_pid() == pid); } @@ -28,7 +32,7 @@ namespace hako::core::context { virtual ~HakoContext() {} private: - pid_t pid_; + pid_type pid_; }; } diff --git a/src/hako/data/hako_base_data.hpp b/src/hako/data/hako_base_data.hpp index 7f3eb38..c2abe2f 100644 --- a/src/hako/data/hako_base_data.hpp +++ b/src/hako/data/hako_base_data.hpp @@ -36,7 +36,7 @@ namespace hako::data { } HakoAssetEventType; typedef struct { - pid_t pid; + pid_type pid; HakoTimeType ctime; /* usec: for asset simulation time */ HakoTimeType update_time; /* usec: for heartbeat check */ HakoAssetEventType event; diff --git a/src/hako/data/hako_master_data.hpp b/src/hako/data/hako_master_data.hpp index 76e7ab3..f323ffa 100644 --- a/src/hako/data/hako_master_data.hpp +++ b/src/hako/data/hako_master_data.hpp @@ -18,7 +18,7 @@ namespace hako::data { typedef struct { - pid_t master_pid; + pid_type master_pid; HakoSimulationStateType state; HakoTimeSetType time_usec; uint32_t asset_num; @@ -68,7 +68,7 @@ namespace hako::data { this->shmp_->unlock_memory(HAKO_SHARED_MEMORY_ID_0); this->pdu_datap_ = std::make_shared(&this->master_datap_->pdu_meta_data, this->shmp_, this->get_shm_type()); } - pid_t get_master_pid() + pid_type get_master_pid() { return this->master_datap_->master_pid; } @@ -216,7 +216,7 @@ namespace hako::data { { HakoAssetIdType id = -1; hako::core::context::HakoContext context; - pid_t pid = context.get_pid(); + pid_type pid = context.get_pid(); for (int i = 0; i < HAKO_DATA_MAX_ASSET_NUM; i++) { if (this->master_datap_->assets[i].type != HakoAsset_Unknown) { if (this->master_datap_->assets_ev[i].pid == pid) { diff --git a/src/hako/utils/hako_clock.hpp b/src/hako/utils/hako_clock.hpp index b3f7067..b1d1597 100644 --- a/src/hako/utils/hako_clock.hpp +++ b/src/hako/utils/hako_clock.hpp @@ -6,10 +6,18 @@ static inline HakoTimeType hako_get_clock() { +#ifdef _WIN32 + LARGE_INTEGER frequency, time; + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&time); + return (time.QuadPart * 1000000) / frequency.QuadPart; +#else struct timespec tp; clock_gettime(CLOCK_REALTIME, &tp); - return ( (tp.tv_sec * 1000 * 1000) + (tp.tv_nsec / 1000) ); + return (tp.tv_sec * 1000000) + (tp.tv_nsec / 1000); +#endif } + static inline bool hako_clock_is_timeout(HakoTimeType check_time, HakoTimeType timeout) { HakoTimeType ctime = hako_get_clock(); diff --git a/src/hako/utils/hako_share/impl/hako_sem_flock.cpp b/src/hako/utils/hako_share/impl/hako_sem_flock.cpp index af9aa84..598bfc1 100644 --- a/src/hako/utils/hako_share/impl/hako_sem_flock.cpp +++ b/src/hako/utils/hako_share/impl/hako_sem_flock.cpp @@ -4,7 +4,11 @@ //#include "utils/hako_logger.hpp" #include "utils/hako_assert.hpp" #include +#if WIN32 +#else #include +#endif + #define HAKO_SEM_INX_MASTER 0 #define HAKO_SEM_INX_ASSETS 1 diff --git a/src/hako/utils/hako_share/impl/win/os_file_io.cpp b/src/hako/utils/hako_share/impl/win/os_file_io.cpp index 64e223f..eabee21 100644 --- a/src/hako/utils/hako_share/impl/win/os_file_io.cpp +++ b/src/hako/utils/hako_share/impl/win/os_file_io.cpp @@ -56,8 +56,17 @@ int win_create_rw(const char* filepath, WinHandleType *whp) void* win_mmap(WinHandleType *whp) { + if (whp == NULL) { + return NULL; + } whp->map_handle = CreateFileMapping(whp->handle, 0, PAGE_READWRITE, 0, 0, 0); + if (whp->map_handle == NULL) { + return NULL; + } whp->mmap_addr = MapViewOfFile(whp->map_handle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); + if (whp->mmap_addr == NULL) { + return NULL; + } return whp->mmap_addr; } @@ -113,7 +122,7 @@ int win_pwrite(WinHandleType *whp, const void* buf, size_t count, off_t offset) if (ret == FALSE) { DWORD err = GetLastError(); printf("win_pwrite error:%ld\n", err); - return -err; + return - (int)err; } return 0; } @@ -125,7 +134,7 @@ int win_pread(WinHandleType *whp, void* buf, size_t count, off_t offset) if (ret == FALSE) { DWORD err = GetLastError(); printf("win_pwrite error:%ld\n", err); - return -err; + return -(int)err; } return 0; } diff --git a/src/include/types/hako_osdeps.hpp b/src/include/types/hako_osdeps.hpp index 70efbc3..70432b5 100644 --- a/src/include/types/hako_osdeps.hpp +++ b/src/include/types/hako_osdeps.hpp @@ -17,11 +17,16 @@ #include #include #include - +typedef pid_t pid_type; #else #include "windows.h" - +#include +typedef SSIZE_T ssize_t; +typedef DWORD pid_type; +static inline void usleep(long microseconds) { + Sleep(microseconds / 1000); +} #endif /* OS_TYPE */ #endif /* _HAKO_OSDEPS_HPP_ */ \ No newline at end of file