diff --git a/CMakeLists.txt b/CMakeLists.txt index ce5cbe2c..d01726fd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,11 @@ cmake_minimum_required (VERSION 3.2) project (DROGON CXX) message (STATUS "os:" ${CMAKE_SYSTEM_NAME}) -IF (CMAKE_SYSTEM_NAME MATCHES "Linux") +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") +#Clang, use c++17 + set(CMAKE_CXX_STD_FLAGS c++17) + set(CXX_STD 17) +else() EXEC_PROGRAM (gcc ARGS "--version | grep '^gcc'|awk '{print $3}' | sed s'/)//g' | sed s'/-.*//g'" OUTPUT_VARIABLE version) MESSAGE(STATUS "This is gcc version:: " ${version}) if(version LESS 5.4.0) @@ -17,10 +21,6 @@ IF (CMAKE_SYSTEM_NAME MATCHES "Linux") set(CXX_STD 17) MESSAGE(STATUS "c++17") endif() -else() -#MacOS use c++17 - set(CMAKE_CXX_STD_FLAGS c++17) - set(CXX_STD 17) endif() include_directories(${PROJECT_SOURCE_DIR}/trantor ${PROJECT_SOURCE_DIR}/lib/inc ${PROJECT_SOURCE_DIR}/orm_lib/inc) @@ -161,14 +161,16 @@ else() file(APPEND "${CONFIG_HEADER}" "#define USE_ORM 0\n") endif() - - string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER) if(CMAKE_BUILD_TYPE_LOWER STREQUAL release) - file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[]=\"" ${CMAKE_CXX_FLAGS_RELEASE} "\";") + file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[] = \"" ${CMAKE_CXX_FLAGS_RELEASE} "\";\n") else() - file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[]=\"" ${CMAKE_CXX_FLAGS_DEBUG} "\";") + file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[] = \"" ${CMAKE_CXX_FLAGS_DEBUG} "\";\n") endif() + +file(APPEND "${CONFIG_HEADER}" "const char compilerCommand[] = \"${CMAKE_CXX_COMPILER}\";\n") +file(APPEND "${CONFIG_HEADER}" "const char compilerId[] = \"${CMAKE_CXX_COMPILER_ID}\";\n") + get_target_property(INS drogon INCLUDE_DIRECTORIES) file(APPEND "${CONFIG_HEADER}" "\nconst char includeDirs[]=\"") diff --git a/lib/src/DrClassMap.cc b/lib/src/DrClassMap.cc index ebe086cb..d65d3236 100755 --- a/lib/src/DrClassMap.cc +++ b/lib/src/DrClassMap.cc @@ -14,10 +14,10 @@ #include #include -#include +#include + using namespace drogon; -//std::map * DrClassMap::classMap=nullptr; -//std::once_flag DrClassMap::flag; + namespace drogon { namespace internal @@ -40,6 +40,7 @@ static std::mutex &getMapMutex() void DrClassMap::registerClass(const std::string &className, const DrAllocFunc &func) { + LOG_TRACE << "Register class:" << className; getMap().insert(std::make_pair(className, func)); } diff --git a/lib/src/HttpResponseImpl.cc b/lib/src/HttpResponseImpl.cc index 8a9cf47b..c13ca6e2 100755 --- a/lib/src/HttpResponseImpl.cc +++ b/lib/src/HttpResponseImpl.cc @@ -48,7 +48,7 @@ HttpResponsePtr HttpResponse::newHttpJsonResponse(const Json::Value &data) HttpResponsePtr HttpResponse::newNotFoundResponse() { auto &resp = HttpAppFrameworkImpl::instance().getCustom404Page(); - if(resp) + if (resp) { return resp; } @@ -64,8 +64,6 @@ HttpResponsePtr HttpResponse::newNotFoundResponse() }); return notFoundResp; } - - } HttpResponsePtr HttpResponse::newLocationRedirectResponse(const std::string &path) { diff --git a/lib/src/SharedLibManager.cc b/lib/src/SharedLibManager.cc index 0a79b601..735d50e0 100755 --- a/lib/src/SharedLibManager.cc +++ b/lib/src/SharedLibManager.cc @@ -110,9 +110,9 @@ void SharedLibManager::managerLibs() return; } - // { - // std::ofstream fout(lockFile); - // } + { + std::ofstream fout(lockFile); + } std::string cmd = "drogon_ctl create view "; cmd.append(filename).append(" -o ").append(libPath); LOG_TRACE << cmd; @@ -150,13 +150,23 @@ void SharedLibManager::managerLibs() void *SharedLibManager::loadLibs(const std::string &sourceFile, void *oldHld) { LOG_TRACE << "src:" << sourceFile; - std::string cmd = "g++ "; - cmd.append(sourceFile).append(" ").append(compileFlags).append(" ").append(includeDirs).append(" -shared -fPIC --no-gnu-unique -o "); - auto pos = sourceFile.rfind("."); + std::string cmd = compilerCommand; + auto pos = cmd.rfind("/"); + if (pos != std::string::npos) + { + cmd = cmd.substr(pos + 1); + } + cmd.append(" ").append(sourceFile).append(" ").append(compileFlags).append(" ").append(includeDirs); + if (std::string(compilerId).find("Clang") != std::string::npos) + cmd.append(" -shared -fPIC -undefined dynamic_lookup -o "); + else + cmd.append(" -shared -fPIC --no-gnu-unique -o "); + pos = sourceFile.rfind("."); auto soFile = sourceFile.substr(0, pos); soFile.append(".so"); cmd.append(soFile); void *Handle = nullptr; + LOG_TRACE << cmd; if (system(cmd.c_str()) == 0) { LOG_TRACE << "Compiled successfully";