Skip to content

Commit

Permalink
Update docs and cleanup CMake script
Browse files Browse the repository at this point in the history
  • Loading branch information
cboulay committed Aug 20, 2020
1 parent f8a1220 commit 7956a7a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 84 deletions.
64 changes: 22 additions & 42 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
# CBSDK Build Instructions

## Using the solution file (deprecated)

This method isn't really supported anymore because it is not future proof,
and as such this description is here for legacy purposes but may be insufficient
for newcomers.

You can try using the provided CereLink.sln file in Visual Studio 2005.
This seems to require an environment variable called QTDIR to be set and pointing to Qt4.

If you are building mex files then this also requires the Matlab folder
to be populated with Matlab include and library files. You will probably need to match
the Matlab version with the Visual Studio version for compiler compatibility.

## Using the CMake build system (supported)

### Dependencies
## Requirements

* Windows:
* [CMake](https://cmake.org/download/)
Expand All @@ -27,49 +12,44 @@ the Matlab version with the Visual Studio version for compiler compatibility.
* Ubuntu (/Debian)
* `sudo apt-get install build-essential cmake qt5-default`

#### Matlab (optional)
### Matlab (optional)

If you want to build then Matlab wrappers then you will need to have Matlab development libraries available.
In most cases, if you have Matlab installed in a default location, then cmake should be able to find it.
If you want to build the Matlab wrappers then you will need to have Matlab development libraries available. In most cases, if you have Matlab installed in a default location, then cmake should be able to find it.

### Create your build directory
## Create your build directory

Use Terminal or Windows users should use "x64 Native Tools Command Prompt for VS 2017".
`cd` into the CereLink directory.
If the `build` directory already exists then delete it
(Win: `rmdir /S build`, Others: `rm -Rf build`).
Using Terminal or "x64 Native Tools Command Prompt for VS 2017" on Windows:
* `cd` into the CereLink directory.
* If the `build` directory already exists then delete it:
* (Windows: `rmdir /S build`, Others: `rm -Rf build`).
* `mkdir build && cd build`

`mkdir build && cd build`

### Try me first
## Cmake command line - Try me first

Here are some cmake one-liners that work if your development environment
happens to match perfectly. If not, then modify the cmake options following the instructions below.
Here are some cmake one-liners that work if your development environment happens to match perfectly. If not, then modify the cmake options according to the CMake Options instructions below.

* Windows:
* `cmake .. -G "Visual Studio 15 2017 Win64" -DQt5_DIR=C:\Qt\5.13.1\msvc2017_64\lib\cmake\Qt5 -DCMAKE_INSTALL_PREFIX=..\dist -DBUILD_CLI=ON`
* `cmake .. -G "Visual Studio 15 2017 Win64" -DQt5_DIR=C:\Qt\5.9.9\msvc2017_64\lib\cmake\Qt5 -DCMAKE_INSTALL_PREFIX=..\dist -DBUILD_CLI=ON`
* MacOS
* `cmake .. -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5`
* Linux
* `cmake ..`

Then follow that up with
```
cmake --build . --config Release
```

Then follow that up with:
* `cmake --build . --config Release`

The build products should appear in the CereLink/dist directory.

### CMake Options

Note: If you want to learn more about CMake or try VS 2017's fancy integrated CMake,
then read [here](http://preshing.com/20170511/how-to-build-a-cmake-based-project/)
for a primer.
Note: This may generate an error related to the CLI builds. Please see further instructions in the cli\README.md

### CMake Options

* `-G <generator name>`
* [Generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#cmake-generators)
* `-DQt5_DIR=<path/to/qt/binaries>/lib/cmake/Qt5`
* This is the path to the folder holding Qt5Config.cmake for the compiler+architecture you are using.
* `-DBUILD_STATIC=ON`
* Whether or not to build cbsdk_static lib. This is required by the Python and Matlab wrappers.
* `-DBUILD_CBMEX=ON`
* To build Matlab binaries. Will only build if Matlab development libraries are found.
* `-DBUILD_CBOCT=ON`
Expand All @@ -84,12 +64,12 @@ for a primer.
* `-DCBMEX_INSTALL_PREFIX` can be used to install cbmex to given directory.
* `-DBUILD_CLI=ON`

# cerebus (Python lib) Build Instructions
# cerebus.cbpy (Python lib) Build Instructions

* Open a Terminal or Anaconda prompt and activate your Python environment.
* Your Python environment must already have Cython installed and pip should be installed too.
* Change to the CereLink directory.
* Set the QTDIR environment variable: `set QTDIR=C:\Qt\5.13.1\msvc2017_64`
* Set the QTDIR environment variable: `set QTDIR=C:\Qt\5.9.9\msvc2017_64`
* Make sure the CereLink Visual Studio project is closed.
* `pip install .`
* or, if you are making a wheel to bring to another machine,
Expand Down
81 changes: 45 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ SET( INSTALL_TARGET_LIST ${LIB_NAME} )
SET( LIB_NAME_STATIC cbsdk_static )
SET( LIB_NAME_CBMEX cbmex )
SET( LIB_NAME_CBOCT cboct )
SET( TEST_NAME testcbsdk )
SET( TEST_COMMENTS_NAME test_comments )
SET( TEST_ANAOUT_NAME test_analog_out )
SET( N2H5_NAME n2h5 )

Expand Down Expand Up @@ -334,59 +332,70 @@ IF( ${BUILD_CBOCT} AND OCTAVE_FOUND )
)
ENDIF( ${BUILD_CBOCT} AND OCTAVE_FOUND )

# Some Test applications.
# These all use deployqt so let's create some helper functions for that.
function(findQtInstallationTool qtdeploytoolname)
if(QT_DEPLOYQT_EXECUTABLE)
return()
endif()
get_target_property(QT_QMAKE_EXE Qt5::qmake IMPORTED_LOCATION)
get_filename_component(QT_BIN_DIR "${QT_QMAKE_EXE}" DIRECTORY)
find_program (QT_DEPLOYQT_EXECUTABLE ${qtdeploytoolname} HINTS "${QT_BIN_DIR}")
if (QT_DEPLOYQT_EXECUTABLE)
message(STATUS "Qt deploy tool found at ${QT_DEPLOYQT_EXECUTABLE}")
else()
message(WARNING "Qt deploy tool wasn't found, installing ${PROJECT_NAME} will fail!")
return()
endif()
endfunction()

##
# test
IF(${BUILD_TEST})
ADD_EXECUTABLE( ${TEST_NAME} ${PROJECT_SOURCE_DIR}/cbmex/testcbsdk.cpp )
TARGET_INCLUDE_DIRECTORIES( ${TEST_NAME} PRIVATE ${LIB_INCL_DIRS})
TARGET_LINK_LIBRARIES( ${TEST_NAME} ${LIB_NAME} )
LIST(APPEND INSTALL_TARGET_LIST ${TEST_NAME})

ADD_EXECUTABLE(testcbsdk ${PROJECT_SOURCE_DIR}/cbmex/testcbsdk.cpp )
TARGET_INCLUDE_DIRECTORIES(testcbsdk PRIVATE ${LIB_INCL_DIRS})
TARGET_LINK_LIBRARIES(testcbsdk ${LIB_NAME} )

ADD_EXECUTABLE(test_io ${PROJECT_SOURCE_DIR}/cbmex/test_io.cpp )
TARGET_INCLUDE_DIRECTORIES(test_io PRIVATE ${LIB_INCL_DIRS})
TARGET_LINK_LIBRARIES(test_io ${LIB_NAME} )

LIST(APPEND INSTALL_TARGET_LIST testcbsdk test_io)

IF(WIN32)
get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
get_filename_component(QT5_WINDEPLOYQT_EXECUTABLE ${QT5_QMAKE_EXECUTABLE} PATH)
set(QT5_WINDEPLOYQT_EXECUTABLE "${QT5_WINDEPLOYQT_EXECUTABLE}/windeployqt.exe")
add_custom_command(TARGET ${TEST_NAME} POST_BUILD
COMMAND ${QT5_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)

ADD_EXECUTABLE( test_io ${PROJECT_SOURCE_DIR}/cbmex/test_io.cpp )
TARGET_INCLUDE_DIRECTORIES( test_io PRIVATE ${LIB_INCL_DIRS})
TARGET_LINK_LIBRARIES( test_io ${LIB_NAME} )
LIST(APPEND INSTALL_TARGET_LIST test_io)
findQtInstallationTool("windeployqt")
add_custom_command(TARGET testcbsdk POST_BUILD
COMMAND ${QT_DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
add_custom_command(TARGET test_io POST_BUILD
COMMAND ${QT5_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
COMMAND ${QT_DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
ENDIF(WIN32)
ENDIF(${BUILD_TEST})

IF(${BUILD_TEST_COMMENTS})
ADD_EXECUTABLE( ${TEST_COMMENTS_NAME} ${PROJECT_SOURCE_DIR}/samples/TestComments/test_comments.cpp )
TARGET_INCLUDE_DIRECTORIES( ${TEST_COMMENTS_NAME} PRIVATE
ADD_EXECUTABLE(test_comments ${PROJECT_SOURCE_DIR}/samples/TestComments/test_comments.cpp )
TARGET_INCLUDE_DIRECTORIES(test_comments PRIVATE
${LIB_INCL_DIRS}
${PROJECT_SOURCE_DIR}/cbmex)
TARGET_LINK_LIBRARIES( ${TEST_COMMENTS_NAME} ${LIB_NAME} )
LIST(APPEND INSTALL_TARGET_LIST ${TEST_COMMENTS_NAME})
TARGET_LINK_LIBRARIES(test_comments ${LIB_NAME} )
LIST(APPEND INSTALL_TARGET_LIST test_comments)
IF(WIN32)
get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
get_filename_component(QT5_WINDEPLOYQT_EXECUTABLE ${QT5_QMAKE_EXECUTABLE} PATH)
set(QT5_WINDEPLOYQT_EXECUTABLE "${QT5_WINDEPLOYQT_EXECUTABLE}/windeployqt.exe")
add_custom_command(TARGET ${TEST_COMMENTS_NAME} POST_BUILD
COMMAND ${QT5_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
findQtInstallationTool("windeployqt")
add_custom_command(TARGET test_comments POST_BUILD
COMMAND ${QT_DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
ENDIF(WIN32)
ENDIF(${BUILD_TEST_COMMENTS})

IF(${BUILD_TEST_ANAOUT})
ADD_EXECUTABLE( ${TEST_ANAOUT_NAME} ${PROJECT_SOURCE_DIR}/samples/TestAnalogOut/test_analog_out.cpp )
TARGET_INCLUDE_DIRECTORIES( ${TEST_ANAOUT_NAME} PRIVATE
ADD_EXECUTABLE(test_analog_out ${PROJECT_SOURCE_DIR}/samples/TestAnalogOut/test_analog_out.cpp )
TARGET_INCLUDE_DIRECTORIES(test_analog_out PRIVATE
${LIB_INCL_DIRS}
${PROJECT_SOURCE_DIR}/cbmex)
TARGET_LINK_LIBRARIES( ${TEST_ANAOUT_NAME} ${LIB_NAME} )
LIST(APPEND INSTALL_TARGET_LIST ${TEST_ANAOUT_NAME})
TARGET_LINK_LIBRARIES(test_analog_out ${LIB_NAME})
LIST(APPEND INSTALL_TARGET_LIST test_analog_out)
IF(WIN32)
get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
get_filename_component(QT5_WINDEPLOYQT_EXECUTABLE ${QT5_QMAKE_EXECUTABLE} PATH)
set(QT5_WINDEPLOYQT_EXECUTABLE "${QT5_WINDEPLOYQT_EXECUTABLE}/windeployqt.exe")
add_custom_command(TARGET ${TEST_ANAOUT_NAME} POST_BUILD
COMMAND ${QT5_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
findQtInstallationTool("windeployqt")
add_custom_command(TARGET test_analog_out POST_BUILD
COMMAND ${QT_DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
ENDIF(WIN32)
ENDIF(${BUILD_TEST_ANAOUT})

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ https://github.com/dashesy/CereLink/wiki

# Build

Some build information can be found in the comments at the top of the CMakeLists.txt.
Additional information can be found in the wiki.
The BUILD.md document has the most up to date build instructions.
6 changes: 4 additions & 2 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ option(BUILD_CLI "Build C++/CLI" OFF)

IF(${BUILD_CLI})
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CSharp_FLAGS "/langversion:latest")
SET( LIB_NAME_CLI cbsdk_cli)
SET(cbsdk_cli_SOURCE
${CMAKE_CURRENT_LIST_DIR}/cbsdk_native.h ${CMAKE_CURRENT_LIST_DIR}/cbsdk_native.cpp
${CMAKE_CURRENT_LIST_DIR}/cbsdk_native.h
${CMAKE_CURRENT_LIST_DIR}/cbsdk_native.cpp
${CMAKE_CURRENT_LIST_DIR}/AssemblyInfo.cpp)
set_source_files_properties(${cbsdk_cli_SOURCE} PROPERTIES LANGUAGE "CXX")
ADD_LIBRARY(${LIB_NAME_CLI} MODULE ${cbsdk_cli_SOURCE})
Expand All @@ -22,7 +24,7 @@ IF(${BUILD_CLI})
PROPERTIES
COMMON_LANGUAGE_RUNTIME ""
#DEBUG_POSTFIX "" # With d postfix then the C# app can't find it.
)
)
# target_compile_options(${LIB_NAME_CLI} PRIVATE /clr)
# target_compile_options(${LIB_NAME_CLI} PRIVATE /EHa)
# STRING(REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
Expand Down
17 changes: 15 additions & 2 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@ Requires CMake >= 3.12.
Only tested on Windows VS 2017.
Add the `-DBUILD_CLI=ON` option to the build command described in ../BUILD.md.

Build the INSTALL target. This will generate at least one `setlocal` error you can ignore.
It will also generate a specific error for the C++/CLI interface described below.
If you followed the instructions in ../BUILD.md then you will have already built the release and this will have generated some errors.
Next, built the INSTALL target:
* `cmake --build . --config Release --target install`

This will generate at least one `setlocal` error you can ignore.
It will also generate a specific error for the C++/CLI interface. The fix is described below.

## C++/CLI Interface

I couldn't figure out how to use CMake to get the C++/CLI test project (in TestCLI folder) to
reference the cbsdk_cli.dll properly. So you'll have to do that manually in the project.

Under the TestCLI target, delete the cbsdk_cli reference and add a new reference pointing to
dist/lib64/cbsdk_cli.dll

* Open the build\CBSDK.sln file.
* Change the config from Debug to Release
* Expand the TestCLI target (click on right arrow)
* Expand "References"
* Right click on `cbsdk_cli` and remove it.
* Right click on References and select `Add Reference...`
* In the new dialog window, browse to dist/lib64/cbsdk_cli.dll

## C# Interface using P/Invoke

An example is provided in TestCSharp.
Expand Down

0 comments on commit 7956a7a

Please sign in to comment.