diff options
| author | ruki <[email protected]> | 2019-09-14 21:44:31 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-09-14 21:44:31 +0800 |
| commit | 074d2607f20aa675e6835c0e31e8876d2f05da57 (patch) | |
| tree | 38f795698d48e9bba30cc3091ced2782c69f0711 /xmake/templates/c++/shared | |
| parent | c08df8d304703ca1153019825ac3cc378ac92e32 (diff) | |
improve project template
Diffstat (limited to 'xmake/templates/c++/shared')
| -rw-r--r-- | xmake/templates/c++/shared/project/src/interface.cpp | 6 | ||||
| -rw-r--r-- | xmake/templates/c++/shared/project/src/interface.h | 24 | ||||
| -rw-r--r-- | xmake/templates/c++/shared/project/src/test.cpp | 10 | ||||
| -rw-r--r-- | xmake/templates/c++/shared/project/xmake.lua | 26 | ||||
| -rw-r--r-- | xmake/templates/c++/shared/template.lua | 14 |
5 files changed, 80 insertions, 0 deletions
diff --git a/xmake/templates/c++/shared/project/src/interface.cpp b/xmake/templates/c++/shared/project/src/interface.cpp new file mode 100644 index 000000000..598d07560 --- /dev/null +++ b/xmake/templates/c++/shared/project/src/interface.cpp @@ -0,0 +1,6 @@ +#include "interface.h" + +int add(int a, int b) +{ + return a + b; +} diff --git a/xmake/templates/c++/shared/project/src/interface.h b/xmake/templates/c++/shared/project/src/interface.h new file mode 100644 index 000000000..ef24ba3ce --- /dev/null +++ b/xmake/templates/c++/shared/project/src/interface.h @@ -0,0 +1,24 @@ +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) +# define __export __declspec(dllexport) +#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) +# define __export __attribute__((visibility("default"))) +#else +# define __export +#endif + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +__export int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/xmake/templates/c++/shared/project/src/test.cpp b/xmake/templates/c++/shared/project/src/test.cpp new file mode 100644 index 000000000..72e03272b --- /dev/null +++ b/xmake/templates/c++/shared/project/src/test.cpp @@ -0,0 +1,10 @@ +#include "interface.h" +#include <iostream> + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "add(1, 2) = " << add(1, 2) << endl; + return 0; +} diff --git a/xmake/templates/c++/shared/project/xmake.lua b/xmake/templates/c++/shared/project/xmake.lua new file mode 100644 index 000000000..59fe4dbe6 --- /dev/null +++ b/xmake/templates/c++/shared/project/xmake.lua @@ -0,0 +1,26 @@ + +-- add modes: debug and release +add_rules("mode.debug", "mode.release") + +-- add target +target("[targetname]") + + -- set kind + set_kind("shared") + + -- add files + add_files("src/interface.cpp") + +-- add target +target("[targetname]_demo") + + -- set kind + set_kind("binary") + + -- add deps + add_deps("[targetname]") + + -- add files + add_files("src/test.cpp") + + diff --git a/xmake/templates/c++/shared/template.lua b/xmake/templates/c++/shared/template.lua new file mode 100644 index 000000000..666542844 --- /dev/null +++ b/xmake/templates/c++/shared/template.lua @@ -0,0 +1,14 @@ +-- set name +set_name("shared") + +-- set description +set_description("The Shared Library") + +-- set project directory +set_projectdir("project") + +-- add macros +add_macros("targetname", "$(targetname)") + +-- add macro files +add_macrofiles("xmake.lua") |
