mirror of
https://github.com/drogonframework/drogon.git
synced 2025-08-10 00:01:14 -04:00
Write the compilation configuration to config.h
This commit is contained in:
parent
975f76c2f7
commit
95b83206fb
1
.gitignore
vendored
1
.gitignore
vendored
@ -35,3 +35,4 @@ build
|
||||
cmake-build-debug
|
||||
.idea
|
||||
lib/inc/drogon/version.h
|
||||
lib/inc/drogon/config.h
|
||||
|
@ -43,7 +43,7 @@ if(Boost_FOUND)
|
||||
endif()
|
||||
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${CMAKE_CXX_STD_FLAGS} -g -ggdb -Wall -fpermissive")
|
||||
set(CMAKE_CXX_FLAGS "-std=${CMAKE_CXX_STD_FLAGS} -g -Wall -fpermissive ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
#string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}")
|
||||
|
||||
@ -73,10 +73,26 @@ install(TARGETS drogon DESTINATION lib)
|
||||
|
||||
file(GLOB trantor_net_headers "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/*.h")
|
||||
install(FILES ${trantor_net_headers} DESTINATION include/drogon)
|
||||
|
||||
file(WRITE "./config.h" "const char definitions[]=\"")
|
||||
add_dependencies(drogon trantor)
|
||||
add_dependencies(drogon makeVersion)
|
||||
|
||||
get_directory_property(DEFS COMPILE_DEFINITIONS)
|
||||
foreach(loop_var ${DEFS})
|
||||
message(STATUS "definitions " ${loop_var})
|
||||
file(APPEND "./config.h" "-D" ${loop_var} " ")
|
||||
endforeach(loop_var)
|
||||
file(APPEND "./config.h" "\";")
|
||||
file(APPEND "./config.h" "\n" "const char compileFlags[]=\"" ${CMAKE_CXX_FLAGS} "\";")
|
||||
|
||||
get_target_property(INS drogon INCLUDE_DIRECTORIES)
|
||||
file(APPEND "./config.h" "\nconst char includeDirs[]=\"")
|
||||
foreach(loop_var ${INS})
|
||||
file(APPEND "./config.h" "-I" ${loop_var} " ")
|
||||
endforeach(loop_var)
|
||||
file(APPEND "./config.h" "\";\n")
|
||||
EXEC_PROGRAM(${PROJECT_SOURCE_DIR}/update_config.sh ARGS "${PROJECT_SOURCE_DIR}/config.h ${PROJECT_SOURCE_DIR}/lib/inc/drogon/config.h")
|
||||
|
||||
if (MAKETEST STREQUAL YES)
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
endif ()
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "version.h"
|
||||
#include <drogon/version.h>
|
||||
#include <drogon/config.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace drogon_ctl;
|
||||
@ -30,4 +31,5 @@ void version::handleCommand(std::vector<std::string> ¶meters)
|
||||
std::cout<<"drogon ctl tools"<<std::endl;
|
||||
std::cout<<"version:"<<VERSION<<std::endl;
|
||||
std::cout<<"git commit:"<<VERSION_MD5<<std::endl;
|
||||
std::cout<<"compile config:"<<definitions<<compileFlags<<includeDirs<<std::endl;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
link_libraries(drogon trantor uuid pthread jsoncpp ssl crypto)
|
||||
link_libraries(drogon trantor uuid pthread jsoncpp ssl crypto dl)
|
||||
|
||||
FILE(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/static_link_example/*.csp)
|
||||
foreach(cspFile ${SCP_LIST})
|
||||
|
@ -18,7 +18,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
void *dlopen(const char *filename, int flag);
|
||||
static void forEachFileIn(const std::string &path,const std::function<void (const std::string &filename)> &cb)
|
||||
{
|
||||
DIR* dp;
|
||||
@ -53,7 +55,7 @@ static void forEachFileIn(const std::string &path,const std::function<void (cons
|
||||
/* if dirent is a directory, continue */
|
||||
if(S_ISDIR(st.st_mode))
|
||||
continue;
|
||||
cb(dirp->d_name);
|
||||
cb(fullname);
|
||||
|
||||
}
|
||||
return;
|
||||
@ -70,8 +72,30 @@ _viewPath(viewPath)
|
||||
}
|
||||
void SharedLibManager::managerLibs()
|
||||
{
|
||||
//LOG_DEBUG<<"manager .so libs in path "<<_viewPath;
|
||||
forEachFileIn("./",[](const std::string &filename){
|
||||
LOG_DEBUG<<"manager .so libs in path "<<_viewPath;
|
||||
forEachFileIn(_viewPath,[=](const std::string &filename){
|
||||
LOG_DEBUG<<filename;
|
||||
auto pos=filename.rfind(".");
|
||||
if(pos!=std::string::npos)
|
||||
{
|
||||
auto exName=filename.substr(pos+1);
|
||||
if(exName=="so")
|
||||
{
|
||||
//loading so file;
|
||||
if(_dlMap.find(filename)!=_dlMap.end())
|
||||
return;
|
||||
auto Handle=dlopen(filename.c_str(),RTLD_NOW);
|
||||
if(!Handle)
|
||||
{
|
||||
LOG_ERROR<<"load "<<filename<<" error!";
|
||||
LOG_ERROR<<dlerror();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_DEBUG<<"Successfully loaded library file "<<filename;
|
||||
_dlMap[filename]=Handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include <trantor/utils/NonCopyable.h>
|
||||
#include <trantor/net/EventLoop.h>
|
||||
#include <unordered_map>
|
||||
namespace drogon{
|
||||
class SharedLibManager:public trantor::NonCopyable
|
||||
{
|
||||
@ -25,5 +26,6 @@ namespace drogon{
|
||||
void managerLibs();
|
||||
trantor::EventLoop *_loop;
|
||||
std::string _viewPath;
|
||||
std::unordered_map<std::string,void *> _dlMap;
|
||||
};
|
||||
}
|
11
update_config.sh
Executable file
11
update_config.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
echo "update config.h"
|
||||
if [ ! -f $2 ];then
|
||||
mv -f $1 $2
|
||||
else
|
||||
diff $1 $2
|
||||
if [ $? -eq 1 ];then
|
||||
mv -f $1 $2
|
||||
fi
|
||||
fi
|
||||
rm -f $1
|
Loading…
x
Reference in New Issue
Block a user