so that's how libraries work
This commit is contained in:
parent
64c96cba26
commit
30d0787a62
@ -35,9 +35,11 @@ foreach(cogfile ${cogfiles})
|
|||||||
set(coggedfiles ${coggedfiles} "${thisfile}")
|
set(coggedfiles ${coggedfiles} "${thisfile}")
|
||||||
endforeach(cogfile)
|
endforeach(cogfile)
|
||||||
|
|
||||||
|
add_library(bottles SHARED ${src}/bottles/bottles.cpp)
|
||||||
|
|
||||||
add_custom_target(cog ALL DEPENDS ${coggedfiles})
|
add_custom_target(cog ALL DEPENDS ${coggedfiles})
|
||||||
|
|
||||||
add_executable(cellar ${src}/cellar.cpp ${src}/commands.cpp ${src}/fs.cpp
|
add_executable(cellar ${src}/cellar.cpp ${src}/commands.cpp ${src}/fs.cpp
|
||||||
${src}/bottles.cpp ${src}/version.cpp)
|
${src}/version.cpp)
|
||||||
add_dependencies(cellar cog)
|
add_dependencies(cellar cog)
|
||||||
target_link_libraries(cellar ${Boost_LIBRARIES})
|
target_link_libraries(cellar ${Boost_LIBRARIES} bottles)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "commands.hpp"
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -27,8 +28,11 @@ namespace cellar {
|
|||||||
string canonical_path;
|
string canonical_path;
|
||||||
Bottle();
|
Bottle();
|
||||||
};
|
};
|
||||||
map<string, Bottle> get_bottles();
|
extern map<string, Bottle> get_bottles();
|
||||||
}
|
}
|
||||||
|
namespace commands {
|
||||||
|
extern map<string, cellar::commands::CommandFunction> bottles_commands();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __BOTTLES_HPP
|
#endif // __BOTTLES_HPP
|
||||||
|
24
include/dll.hpp
Normal file
24
include/dll.hpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
|
#ifdef BUILDING_DLL
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define DLL_PUBLIC __attribute__ ((dllexport))
|
||||||
|
#else
|
||||||
|
#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define DLL_PUBLIC __attribute__ ((dllimport))
|
||||||
|
#else
|
||||||
|
#define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#define DLL_LOCAL
|
||||||
|
#else
|
||||||
|
#if __GNUC__ >= 4
|
||||||
|
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
|
||||||
|
#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
|
||||||
|
#else
|
||||||
|
#define DLL_PUBLIC
|
||||||
|
#define DLL_LOCAL
|
||||||
|
#endif
|
||||||
|
#endif
|
@ -11,11 +11,13 @@
|
|||||||
|
|
||||||
#include "bottles.hpp"
|
#include "bottles.hpp"
|
||||||
#include "commands.hpp"
|
#include "commands.hpp"
|
||||||
|
#include "dll.hpp"
|
||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cellar::bottles;
|
using namespace cellar::bottles;
|
||||||
|
|
||||||
|
using CommandFunction = cellar::commands::CommandFunction;
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
Bottle::Bottle() {
|
Bottle::Bottle() {
|
||||||
@ -25,7 +27,7 @@ Bottle::Bottle() {
|
|||||||
type = bottle_anonymous;
|
type = bottle_anonymous;
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, Bottle> cellar::bottles::get_bottles() {
|
DLL_PUBLIC map<string, Bottle> cellar::bottles::get_bottles() {
|
||||||
map<string, Bottle> result;
|
map<string, Bottle> result;
|
||||||
|
|
||||||
string homepath = getenv("HOME");
|
string homepath = getenv("HOME");
|
||||||
@ -95,4 +97,8 @@ void print_bottles(int argc, char** argv) {
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cellar::commands::CommandFunction listcmd = cellar::commands::command_map["list"] = &print_bottles;
|
DLL_PUBLIC map<string, CommandFunction> cellar::commands::bottles_commands() {
|
||||||
|
map<string, CommandFunction> result;
|
||||||
|
result.insert(pair<string,CommandFunction>("list", &print_bottles));
|
||||||
|
return result;
|
||||||
|
}
|
@ -37,6 +37,10 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
cmdparse.parse(argc, argv);
|
cmdparse.parse(argc, argv);
|
||||||
|
|
||||||
|
for (auto item : commands::bottles_commands()) {
|
||||||
|
commands::command_map[item.first] = item.second;
|
||||||
|
}
|
||||||
|
|
||||||
string usercmd = command.getValue();
|
string usercmd = command.getValue();
|
||||||
if (commands::command_map.count(usercmd) > 0) {
|
if (commands::command_map.count(usercmd) > 0) {
|
||||||
commands::command_map[usercmd](argc, argv);
|
commands::command_map[usercmd](argc, argv);
|
||||||
|
Loading…
Reference in New Issue
Block a user