Skip to content

Commit

Permalink
#124 fix cmake build, add example
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Jun 25, 2020
1 parent d65b795 commit c3feadf
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 26 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 2.8.7)

project (flecs C)

file(GLOB flecs_SRC "src/*.c")
file(GLOB_RECURSE flecs_SRC "src/*.c")

add_library(flecs SHARED ${flecs_SRC})
add_library(flecs_static STATIC ${flecs_SRC})
Expand All @@ -12,12 +12,6 @@ target_include_directories(flecs_static PUBLIC "include")

include_directories("include")

add_definitions(-DFLECS_IMPL)

if (TARGET flecs_static)
add_definitions(-DPRIVATE -DFLECS_STATIC)
endif()

install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include FILES_MATCHING PATTERN "*.h"
)
Expand Down
13 changes: 13 additions & 0 deletions examples/build/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required (VERSION 2.8.7)

project (cmake_example)

set(CMAKE_CXX_STANDARD 11)

add_subdirectory (flecs)

add_executable(cmake_example main.cpp)
add_executable(cmake_example_static main.cpp)

target_link_libraries(cmake_example flecs)
target_link_libraries(cmake_example_static flecs_static)
1 change: 1 addition & 0 deletions examples/build/cmake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For this to work, flecs needs to be a subdirectory of the example.
47 changes: 47 additions & 0 deletions examples/build/cmake/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "flecs.h"
#include <iostream>

/* Component types */
struct Position {
float x;
float y;
};

struct Velocity {
float x;
float y;
};

int main(int argc, char *argv[]) {
/* Create the world, pass arguments for overriding the number of threads,fps
* or for starting the admin dashboard (see flecs.h for details). */
flecs::world world(argc, argv);

flecs::component<Position>(world, "Position");
flecs::component<Velocity>(world, "Velocity");

flecs::system<Position, Velocity>(world)
.action([](const flecs::iter& it,
flecs::column<Position> p,
flecs::column<Velocity> v)
{
for (auto row : it) {
p[row].x += v[row].x;
p[row].y += v[row].y;

std::cout << "Moved " << it.entity(row).name() << " to {" <<
p[row].x << ", " << p[row].y << "}" << std::endl;
}
});

flecs::entity(world, "MyEntity")
.set<Position>({0, 0})
.set<Velocity>({1, 1});

world.set_target_fps(1);

std::cout << "Application move_system is running, press CTRL-C to exit..." << std::endl;

/* Run systems */
while (world.progress()) { }
}
3 changes: 0 additions & 3 deletions include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
/* FLECS_LEGACY should be defined when building for C89 */
// #define FLECS_LEGACY

/* FLECS_STATIC should be defined when building as a static library */
// #define FLECS_STATIC

/* FLECS_NO_CPP should be defined when building for C++ without the C++ API */
// #define FLECS_NO_CPP

Expand Down
18 changes: 7 additions & 11 deletions include/flecs/bake_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,17 @@
#endif

/* Headers of private dependencies */
#ifdef FLECS_IMPL
#ifdef flecs_EXPORT
/* No dependencies */
#endif

/* Convenience macro for exporting symbols */
#ifndef FLECS_STATIC
#if FLECS_IMPL && (defined(_MSC_VER) || defined(__MINGW32__))
#define FLECS_EXPORT __declspec(dllexport)
#elif FLECS_IMPL
#define FLECS_EXPORT __attribute__((__visibility__("default")))
#elif defined _MSC_VER
#define FLECS_EXPORT __declspec(dllimport)
#else
#define FLECS_EXPORT
#endif
#if flecs_EXPORTS && (defined(_MSC_VER) || defined(__MINGW32__))
#define FLECS_EXPORT __declspec(dllexport)
#elif flecs_EXPORTS
#define FLECS_EXPORT __attribute__((__visibility__("default")))
#elif defined _MSC_VER
#define FLECS_EXPORTS __declspec(dllimport)
#else
#define FLECS_EXPORT
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/flecs/private/api_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ extern "C" {
#include <time.h>
#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>

/* Non-standard but required. If not provided by platform, add manually. If
* flecs is built by bake, stdint.h from bake is included. */
Expand Down
2 changes: 2 additions & 0 deletions include/flecs/private/api_support.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef FLECS_API_SUPPORT_H
#define FLECS_API_SUPPORT_H

#include "api_types.h"

/** Supporting types and functions that need to be exposed either in support of
* the public API or for unit tests, but that may change between minor / patch
* releases. */
Expand Down
2 changes: 2 additions & 0 deletions include/flecs/private/api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#ifndef FLECS_API_TYPES_H
#define FLECS_API_TYPES_H

#include "api_defines.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/flecs/private/entity_index.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef FLECS_ENTITY_INDEX_H
#define FLECS_ENTITY_INDEX_H

#include "api_defines.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/flecs/private/map.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef FLECS_MAP_H
#define FLECS_MAP_H

#include "api_defines.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/flecs/private/sparse.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef FLECS_SPARSE_H
#define FLECS_SPARSE_H

#include "api_defines.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/flecs/private/strbuf.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef FLECS_STRBUF_H_
#define FLECS_STRBUF_H_

#include "api_defines.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/flecs/private/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef FLECS_TABLE_H_
#define FLECS_TABLE_H_

#include "api_defines.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/flecs/private/vector.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef FLECS_VECTOR_H
#define FLECS_VECTOR_H

#include "api_defines.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/addon/ringbuf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "flecs/addon/ringbuf.h"
#include "flecs.h"

struct ecs_ringbuf_t {
ecs_vector_t *data;
Expand Down
2 changes: 1 addition & 1 deletion src/map.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "flecs/private/map.h"
#include "flecs.h"

#define LOAD_FACTOR (1.5)
#define KEY_SIZE (sizeof(ecs_map_key_t))
Expand Down
2 changes: 1 addition & 1 deletion src/sparse.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "flecs/private/sparse.h"
#include "flecs.h"

#define CHUNK_ALLOC_SIZE (4096)

Expand Down
2 changes: 1 addition & 1 deletion src/strbuf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "flecs/private/strbuf.h"
#include "flecs.h"

/* Add an extra element to the buffer */
static
Expand Down
2 changes: 1 addition & 1 deletion src/vector.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "flecs/private/vector.h"
#include "flecs.h"

/** Resize the vector buffer */
static
Expand Down

0 comments on commit c3feadf

Please sign in to comment.