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 compile options for example applications and tests #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
179 changes: 99 additions & 80 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ cmake_minimum_required(VERSION 3.20)

project(Open1722 VERSION 0.1)

option(OPEN1722_BUILD_TESTS "Build tests" OFF)
option(OPEN1722_BUILD_EXAMPLES "Build tests" OFF)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED TRUE)

#### Libraries ################################################################

add_library(open1722 SHARED
set(SOURCES
"src/avtp/CommonHeader.c"
"src/avtp/Crf.c"
"src/avtp/Rvf.c"
Expand All @@ -29,7 +33,15 @@ add_library(open1722 SHARED
"src/avtp/cvf/Cvf.c"
"src/avtp/cvf/H264.c"
"src/avtp/cvf/Jpeg2000.c"
"src/avtp/cvf/Mjpeg.c")
"src/avtp/cvf/Mjpeg.c"
)

if(BUILD_SHARED_LIBS)
add_library(open1722 SHARED ${SOURCES})
else()
add_library(open1722 STATIC ${SOURCES})
endif()

set_target_properties(open1722 PROPERTIES VERSION ${PROJECT_VERSION})

target_include_directories(open1722 PRIVATE
Expand All @@ -38,96 +50,103 @@ target_include_directories(open1722 PRIVATE

#### Examples #################################################################

# Common library accross all examples
add_library(open1722examples STATIC "examples/common/common.c")
target_include_directories(open1722examples PRIVATE "examples" "include")

# AAF listener app
add_executable(aaf-listener "examples/aaf/aaf-listener.c")
target_include_directories(aaf-listener PRIVATE "examples" "include")
target_link_libraries(aaf-listener open1722 open1722examples)

# AAF talker app
add_executable(aaf-talker "examples/aaf/aaf-talker.c")
target_include_directories(aaf-talker PRIVATE "examples" "include")
target_link_libraries(aaf-talker open1722 open1722examples)

# CAN talker app
add_executable(acf-can-talker "examples/acf-can/acf-can-talker.c" "examples/acf-can/acf-can-common.c")
target_include_directories(acf-can-talker PRIVATE "examples" "include")
target_link_libraries(acf-can-talker open1722 open1722examples)

# CAN listener app
add_executable(acf-can-listener "examples/acf-can/acf-can-listener.c" "examples/acf-can/acf-can-common.c")
target_include_directories(acf-can-listener PRIVATE "examples" "include")
target_link_libraries(acf-can-listener open1722 open1722examples)

# CRF talker app
add_executable(crf-talker "examples/crf/crf-talker.c")
target_include_directories(crf-talker PRIVATE "examples" "include")
target_link_libraries(crf-talker open1722 open1722examples m)

# CRF listener app
add_executable(crf-listener "examples/crf/crf-listener.c")
target_include_directories(crf-listener PRIVATE "examples" "include")
target_link_libraries(crf-listener open1722 open1722examples m)

# CVF talker app
add_executable(cvf-talker "examples/cvf/cvf-talker.c")
target_include_directories(cvf-talker PRIVATE "examples" "include")
target_link_libraries(cvf-talker open1722 open1722examples)

# CVF listener app
add_executable(cvf-listener "examples/cvf/cvf-listener.c")
target_include_directories(cvf-listener PRIVATE "examples" "include")
target_link_libraries(cvf-listener open1722 open1722examples)

# Hello-world talker app
add_executable(hello-world-talker "examples/hello-world/hello-world-talker.c")
target_include_directories(hello-world-talker PRIVATE "examples" "include")
target_link_libraries(hello-world-talker open1722 open1722examples)

# Hello-world listener app
add_executable(hello-world-listener "examples/hello-world/hello-world-listener.c")
target_include_directories(hello-world-listener PRIVATE "examples" "include")
target_link_libraries(hello-world-listener open1722 open1722examples)
if (OPEN1722_BUILD_EXAMPLES)
# Common library accross all examples
add_library(open1722examples STATIC "examples/common/common.c")
target_include_directories(open1722examples PRIVATE "examples" "include")

# AAF listener app
add_executable(aaf-listener "examples/aaf/aaf-listener.c")
target_include_directories(aaf-listener PRIVATE "examples" "include")
target_link_libraries(aaf-listener open1722 open1722examples)

# AAF talker app
add_executable(aaf-talker "examples/aaf/aaf-talker.c")
target_include_directories(aaf-talker PRIVATE "examples" "include")
target_link_libraries(aaf-talker open1722 open1722examples)

# CAN talker app
add_executable(acf-can-talker "examples/acf-can/acf-can-talker.c" "examples/acf-can/acf-can-common.c")
target_include_directories(acf-can-talker PRIVATE "examples" "include")
target_link_libraries(acf-can-talker open1722 open1722examples)

# CAN listener app
add_executable(acf-can-listener "examples/acf-can/acf-can-listener.c" "examples/acf-can/acf-can-common.c")
target_include_directories(acf-can-listener PRIVATE "examples" "include")
target_link_libraries(acf-can-listener open1722 open1722examples)

# CRF talker app
add_executable(crf-talker "examples/crf/crf-talker.c")
target_include_directories(crf-talker PRIVATE "examples" "include")
target_link_libraries(crf-talker open1722 open1722examples m)

# CRF listener app
add_executable(crf-listener "examples/crf/crf-listener.c")
target_include_directories(crf-listener PRIVATE "examples" "include")
target_link_libraries(crf-listener open1722 open1722examples m)

# CVF talker app
add_executable(cvf-talker "examples/cvf/cvf-talker.c")
target_include_directories(cvf-talker PRIVATE "examples" "include")
target_link_libraries(cvf-talker open1722 open1722examples)

# CVF listener app
add_executable(cvf-listener "examples/cvf/cvf-listener.c")
target_include_directories(cvf-listener PRIVATE "examples" "include")
target_link_libraries(cvf-listener open1722 open1722examples)

# Hello-world talker app
add_executable(hello-world-talker "examples/hello-world/hello-world-talker.c")
target_include_directories(hello-world-talker PRIVATE "examples" "include")
target_link_libraries(hello-world-talker open1722 open1722examples)

# Hello-world listener app
add_executable(hello-world-listener "examples/hello-world/hello-world-listener.c")
target_include_directories(hello-world-listener PRIVATE "examples" "include")
target_link_libraries(hello-world-listener open1722 open1722examples)
endif()

#### Tests ####################################################################

enable_testing()
if (OPEN1722_BUILD_TESTS)
enable_testing()

# find_package(cmocka 1.1.0 REQUIRED)
# find_package(cmocka 1.1.0 REQUIRED)

list(APPEND TEST_TARGETS test-aaf)
list(APPEND TEST_TARGETS test-avtp)
list(APPEND TEST_TARGETS test-can)
list(APPEND TEST_TARGETS test-crf)
list(APPEND TEST_TARGETS test-cvf)
list(APPEND TEST_TARGETS test-rvf)
# list(APPEND TEST_TARGETS test-stream)
list(APPEND TEST_TARGETS test-aaf)
list(APPEND TEST_TARGETS test-avtp)
list(APPEND TEST_TARGETS test-can)
list(APPEND TEST_TARGETS test-crf)
list(APPEND TEST_TARGETS test-cvf)
list(APPEND TEST_TARGETS test-rvf)
# list(APPEND TEST_TARGETS test-stream)

foreach(TEST_TARGET IN LISTS TEST_TARGETS)
add_executable(${TEST_TARGET} "unit/${TEST_TARGET}.c")
target_include_directories(${TEST_TARGET} PRIVATE "include")
target_link_libraries(${TEST_TARGET} open1722 cmocka m)
add_test(NAME ${TEST_TARGET} COMMAND "${PROJECT_BINARY_DIR}/${TEST_TARGET}")
endforeach()
foreach(TEST_TARGET IN LISTS TEST_TARGETS)
add_executable(${TEST_TARGET} "unit/${TEST_TARGET}.c")
target_include_directories(${TEST_TARGET} PRIVATE "include")
target_link_libraries(${TEST_TARGET} open1722 cmocka m)
add_test(NAME ${TEST_TARGET} COMMAND "${PROJECT_BINARY_DIR}/${TEST_TARGET}")
endforeach()
endif()

#### Install ##################################################################

install(TARGETS open1722 EXPORT Open1722Targets DESTINATION lib)
install(TARGETS
aaf-listener
aaf-talker
acf-can-listener
acf-can-talker
crf-listener
crf-talker
cvf-listener
cvf-talker
DESTINATION bin)
install(DIRECTORY "include/" DESTINATION include)

if (OPEN1722_BUILD_EXAMPLES)
install(TARGETS
aaf-listener
aaf-talker
acf-can-listener
acf-can-talker
crf-listener
crf-talker
cvf-listener
cvf-talker
DESTINATION bin)
endif()

#### Export Configuration #####################################################

install(EXPORT Open1722Targets FILE Open1722Targets.cmake DESTINATION lib/cmake/Open1722)
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ Before building Open1722 make sure you have installed the following software :

Alternatively, you can use VS Code to run the provided dev container which takes care of the dependencies.

The first step to build Open1722 is to generate the Makefile and build the project.
The first step to build Open1722 is to generate the Makefile and build the project (including example applications and tests).
```
$ mkdir build
$ cd buid
$ cmake ..
$ cmake -DOPEN1722_BUILD_TESTS=ON -DOPEN1722_BUILD_EXAMPLES=ON ..
$ make
```

To build a static library you need to pass the following parameter to CMake
```
$ cmake -DBUILD_SHARED_LIBS=OFF
```

The build can be cleaned using the following command:
```
$ make clean
Expand Down
2 changes: 1 addition & 1 deletion build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -ev
rm -rf build
mkdir build
cd build
cmake ..
cmake -DOPEN1722_BUILD_TESTS=ON -DOPEN1722_BUILD_EXAMPLES=ON ..
make -j`nproc`