Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake support #41

Merged
merged 6 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
obj/
tools/*.svg
build/
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.0.0)
project(BioSim4 VERSION 0.2.0)

include(CTest)
enable_testing()

add_subdirectory(src)


install(FILES ./biosim4.ini DESTINATION ./)
install(DIRECTORY ./tools/ DESTINATION tools)
install (DIRECTORY DESTINATION "logs" DIRECTORY_PERMISSIONS
OWNER_WRITE OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_READ GROUP_EXECUTE
GROUP_READ WORLD_READ WORLD_EXECUTE)
install (DIRECTORY DESTINATION "images" DIRECTORY_PERMISSIONS
OWNER_WRITE OWNER_READ OWNER_EXECUTE
GROUP_READ GROUP_READ GROUP_EXECUTE
GROUP_READ WORLD_READ WORLD_EXECUTE)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RESINC =
LIBDIR =
ARCH = `arch`
LIB = /usr/lib/$(ARCH)-linux-gnu/libopencv_core.so /usr/lib/$(ARCH)-linux-gnu/libopencv_video.so /usr/lib/$(ARCH)-linux-gnu/libopencv_videoio.so
LDFLAGS = -lX11 -lpthread -lgomp
LDFLAGS = -lpthread -lgomp

INC_DEBUG = $(INC)
CFLAGS_DEBUG = $(CFLAGS) -g -fopenmp
Expand Down
56 changes: 50 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,24 @@ cimg-dev is replaced with version 2.8.4 or later.
<a name="Compiling"></a>
### Compiling

Two (and a half) ways to compile:
You have several options:

* The file named "biosim4.cbp" is a configuration file for the Code::Blocks IDE version 20.03.
#### Code::Blocks project file

* A Makefile is provided which
was created from biosim4.cbp with cbp2make, but is not tested. A default "make" will generate a debug and a
release version.
The file named "biosim4.cbp" is a configuration file for the Code::Blocks IDE version 20.03.

#### Makefile

* A Dockerfile is provided which leverages the aforementioned Makefile.
A Makefile is provided which was created from biosim4.cbp with cbp2make. Possible make commands include:

* "make" with no arguments makes release and debug versions in ./bin/Release and ./bin/Debug
* "make release" makes a release version in ./bin/Release
* "make debug" makes a debug version in ./bin/Debug
* "make clean" removes the intermediate build files

#### Docker

A Dockerfile is provided which leverages the aforementioned Makefile.

To build a Docker environment in which you can compile the program:

Expand All @@ -237,6 +245,42 @@ docker run --rm -ti -v `pwd`:/app --name biosim biosim4 make
```
When you exit the container, the files compiled in your container files will persist in `./bin`.

#### CMake

A `CMakeList.txt` file is provided to allow development, build, test, installation and packaging with the CMake tool chain and all IDE's that support CMake.

To build with cmake you need to install cmake. Once installed use the procedure below:

```sh
mkdir build
cd build
cmake ../
cmake --build ./
```

To make a test installation and run the program:

```sh
mkdir build
cd build
cmake ../
cmake --build ./
mkdir test_install
cmake --install ./ --prefix ./test_install
cd test_install
./bin/biosim4
```

To make a release package:

```sh
mkdir build
cd build
cmake ../
cmake --build ./
cpack ./
```

<a name="Bugs"></a>
## Bugs
--------------------
Expand Down
31 changes: 31 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

FILE(GLOB MyCppSources ./*.cpp)
FILE(GLOB MyCppheaders ./*.h)

# TODO move the unit test to test build and include in test mechanims of cmake
#list(REMOVE_ITEM MyCppSources "./unitTestBasicTypes.cpp")
#list(REMOVE_ITEM MyCppSources "./unitTestConnectNeuralNetWiringFromGenome.cpp")
#list(REMOVE_ITEM MyCppSources "./unitTestGridVisitNeighborhood.cpp")

find_package(OpenCV REQUIRED)

include_directories( ${OpenCV_INCLUDE_DIRS} )

SET(GCC_COVERAGE_COMPILE_FLAGS "-O3 -Wall -fexceptions -fopenmp")
SET(GCC_COVERAGE_LINK_FLAGS "-lpthread -O3 -lz -lgomp")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
set( CMAKE_VERBOSE_MAKEFILE on )

add_executable(biosim4 ${MyCppSources} ${MyCppheaders})
target_link_libraries( biosim4 PUBLIC ${OpenCV_LIBS} )


install(TARGETS biosim4 DESTINATION bin)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)


1 change: 1 addition & 0 deletions src/imageWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "simulator.h"
#include "imageWriter.h"
#define cimg_use_opencv 1
#define cimg_display 0
#include "CImg.h"

namespace BS {
Expand Down