Skip to content

Commit 7956a7a

Browse files
committed
Update docs and cleanup CMake script
1 parent f8a1220 commit 7956a7a

File tree

5 files changed

+87
-84
lines changed

5 files changed

+87
-84
lines changed

BUILD.md

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
# CBSDK Build Instructions
22

3-
## Using the solution file (deprecated)
4-
5-
This method isn't really supported anymore because it is not future proof,
6-
and as such this description is here for legacy purposes but may be insufficient
7-
for newcomers.
8-
9-
You can try using the provided CereLink.sln file in Visual Studio 2005.
10-
This seems to require an environment variable called QTDIR to be set and pointing to Qt4.
11-
12-
If you are building mex files then this also requires the Matlab folder
13-
to be populated with Matlab include and library files. You will probably need to match
14-
the Matlab version with the Visual Studio version for compiler compatibility.
15-
16-
## Using the CMake build system (supported)
17-
18-
### Dependencies
3+
## Requirements
194

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

30-
#### Matlab (optional)
15+
### Matlab (optional)
3116

32-
If you want to build then Matlab wrappers then you will need to have Matlab development libraries available.
33-
In most cases, if you have Matlab installed in a default location, then cmake should be able to find it.
17+
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.
3418

35-
### Create your build directory
19+
## Create your build directory
3620

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

42-
`mkdir build && cd build`
43-
44-
### Try me first
27+
## Cmake command line - Try me first
4528

46-
Here are some cmake one-liners that work if your development environment
47-
happens to match perfectly. If not, then modify the cmake options following the instructions below.
29+
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.
4830

4931
* Windows:
50-
* `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`
32+
* `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`
5133
* MacOS
5234
* `cmake .. -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5`
5335
* Linux
5436
* `cmake ..`
55-
56-
Then follow that up with
57-
```
58-
cmake --build . --config Release
59-
```
37+
38+
Then follow that up with:
39+
* `cmake --build . --config Release`
40+
6041
The build products should appear in the CereLink/dist directory.
61-
62-
### CMake Options
6342

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

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

87-
# cerebus (Python lib) Build Instructions
67+
# cerebus.cbpy (Python lib) Build Instructions
8868

8969
* Open a Terminal or Anaconda prompt and activate your Python environment.
9070
* Your Python environment must already have Cython installed and pip should be installed too.
9171
* Change to the CereLink directory.
92-
* Set the QTDIR environment variable: `set QTDIR=C:\Qt\5.13.1\msvc2017_64`
72+
* Set the QTDIR environment variable: `set QTDIR=C:\Qt\5.9.9\msvc2017_64`
9373
* Make sure the CereLink Visual Studio project is closed.
9474
* `pip install .`
9575
* or, if you are making a wheel to bring to another machine,

CMakeLists.txt

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ SET( INSTALL_TARGET_LIST ${LIB_NAME} )
5454
SET( LIB_NAME_STATIC cbsdk_static )
5555
SET( LIB_NAME_CBMEX cbmex )
5656
SET( LIB_NAME_CBOCT cboct )
57-
SET( TEST_NAME testcbsdk )
58-
SET( TEST_COMMENTS_NAME test_comments )
5957
SET( TEST_ANAOUT_NAME test_analog_out )
6058
SET( N2H5_NAME n2h5 )
6159

@@ -334,59 +332,70 @@ IF( ${BUILD_CBOCT} AND OCTAVE_FOUND )
334332
)
335333
ENDIF( ${BUILD_CBOCT} AND OCTAVE_FOUND )
336334

335+
# Some Test applications.
336+
# These all use deployqt so let's create some helper functions for that.
337+
function(findQtInstallationTool qtdeploytoolname)
338+
if(QT_DEPLOYQT_EXECUTABLE)
339+
return()
340+
endif()
341+
get_target_property(QT_QMAKE_EXE Qt5::qmake IMPORTED_LOCATION)
342+
get_filename_component(QT_BIN_DIR "${QT_QMAKE_EXE}" DIRECTORY)
343+
find_program (QT_DEPLOYQT_EXECUTABLE ${qtdeploytoolname} HINTS "${QT_BIN_DIR}")
344+
if (QT_DEPLOYQT_EXECUTABLE)
345+
message(STATUS "Qt deploy tool found at ${QT_DEPLOYQT_EXECUTABLE}")
346+
else()
347+
message(WARNING "Qt deploy tool wasn't found, installing ${PROJECT_NAME} will fail!")
348+
return()
349+
endif()
350+
endfunction()
351+
337352
##
338353
# test
339354
IF(${BUILD_TEST})
340-
ADD_EXECUTABLE( ${TEST_NAME} ${PROJECT_SOURCE_DIR}/cbmex/testcbsdk.cpp )
341-
TARGET_INCLUDE_DIRECTORIES( ${TEST_NAME} PRIVATE ${LIB_INCL_DIRS})
342-
TARGET_LINK_LIBRARIES( ${TEST_NAME} ${LIB_NAME} )
343-
LIST(APPEND INSTALL_TARGET_LIST ${TEST_NAME})
344-
355+
ADD_EXECUTABLE(testcbsdk ${PROJECT_SOURCE_DIR}/cbmex/testcbsdk.cpp )
356+
TARGET_INCLUDE_DIRECTORIES(testcbsdk PRIVATE ${LIB_INCL_DIRS})
357+
TARGET_LINK_LIBRARIES(testcbsdk ${LIB_NAME} )
358+
359+
ADD_EXECUTABLE(test_io ${PROJECT_SOURCE_DIR}/cbmex/test_io.cpp )
360+
TARGET_INCLUDE_DIRECTORIES(test_io PRIVATE ${LIB_INCL_DIRS})
361+
TARGET_LINK_LIBRARIES(test_io ${LIB_NAME} )
362+
363+
LIST(APPEND INSTALL_TARGET_LIST testcbsdk test_io)
364+
345365
IF(WIN32)
346-
get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
347-
get_filename_component(QT5_WINDEPLOYQT_EXECUTABLE ${QT5_QMAKE_EXECUTABLE} PATH)
348-
set(QT5_WINDEPLOYQT_EXECUTABLE "${QT5_WINDEPLOYQT_EXECUTABLE}/windeployqt.exe")
349-
add_custom_command(TARGET ${TEST_NAME} POST_BUILD
350-
COMMAND ${QT5_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
351-
352-
ADD_EXECUTABLE( test_io ${PROJECT_SOURCE_DIR}/cbmex/test_io.cpp )
353-
TARGET_INCLUDE_DIRECTORIES( test_io PRIVATE ${LIB_INCL_DIRS})
354-
TARGET_LINK_LIBRARIES( test_io ${LIB_NAME} )
355-
LIST(APPEND INSTALL_TARGET_LIST test_io)
366+
findQtInstallationTool("windeployqt")
367+
add_custom_command(TARGET testcbsdk POST_BUILD
368+
COMMAND ${QT_DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
356369
add_custom_command(TARGET test_io POST_BUILD
357-
COMMAND ${QT5_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
370+
COMMAND ${QT_DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
358371
ENDIF(WIN32)
359372
ENDIF(${BUILD_TEST})
360373

361374
IF(${BUILD_TEST_COMMENTS})
362-
ADD_EXECUTABLE( ${TEST_COMMENTS_NAME} ${PROJECT_SOURCE_DIR}/samples/TestComments/test_comments.cpp )
363-
TARGET_INCLUDE_DIRECTORIES( ${TEST_COMMENTS_NAME} PRIVATE
375+
ADD_EXECUTABLE(test_comments ${PROJECT_SOURCE_DIR}/samples/TestComments/test_comments.cpp )
376+
TARGET_INCLUDE_DIRECTORIES(test_comments PRIVATE
364377
${LIB_INCL_DIRS}
365378
${PROJECT_SOURCE_DIR}/cbmex)
366-
TARGET_LINK_LIBRARIES( ${TEST_COMMENTS_NAME} ${LIB_NAME} )
367-
LIST(APPEND INSTALL_TARGET_LIST ${TEST_COMMENTS_NAME})
379+
TARGET_LINK_LIBRARIES(test_comments ${LIB_NAME} )
380+
LIST(APPEND INSTALL_TARGET_LIST test_comments)
368381
IF(WIN32)
369-
get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
370-
get_filename_component(QT5_WINDEPLOYQT_EXECUTABLE ${QT5_QMAKE_EXECUTABLE} PATH)
371-
set(QT5_WINDEPLOYQT_EXECUTABLE "${QT5_WINDEPLOYQT_EXECUTABLE}/windeployqt.exe")
372-
add_custom_command(TARGET ${TEST_COMMENTS_NAME} POST_BUILD
373-
COMMAND ${QT5_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
382+
findQtInstallationTool("windeployqt")
383+
add_custom_command(TARGET test_comments POST_BUILD
384+
COMMAND ${QT_DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
374385
ENDIF(WIN32)
375386
ENDIF(${BUILD_TEST_COMMENTS})
376387

377388
IF(${BUILD_TEST_ANAOUT})
378-
ADD_EXECUTABLE( ${TEST_ANAOUT_NAME} ${PROJECT_SOURCE_DIR}/samples/TestAnalogOut/test_analog_out.cpp )
379-
TARGET_INCLUDE_DIRECTORIES( ${TEST_ANAOUT_NAME} PRIVATE
389+
ADD_EXECUTABLE(test_analog_out ${PROJECT_SOURCE_DIR}/samples/TestAnalogOut/test_analog_out.cpp )
390+
TARGET_INCLUDE_DIRECTORIES(test_analog_out PRIVATE
380391
${LIB_INCL_DIRS}
381392
${PROJECT_SOURCE_DIR}/cbmex)
382-
TARGET_LINK_LIBRARIES( ${TEST_ANAOUT_NAME} ${LIB_NAME} )
383-
LIST(APPEND INSTALL_TARGET_LIST ${TEST_ANAOUT_NAME})
393+
TARGET_LINK_LIBRARIES(test_analog_out ${LIB_NAME})
394+
LIST(APPEND INSTALL_TARGET_LIST test_analog_out)
384395
IF(WIN32)
385-
get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
386-
get_filename_component(QT5_WINDEPLOYQT_EXECUTABLE ${QT5_QMAKE_EXECUTABLE} PATH)
387-
set(QT5_WINDEPLOYQT_EXECUTABLE "${QT5_WINDEPLOYQT_EXECUTABLE}/windeployqt.exe")
388-
add_custom_command(TARGET ${TEST_ANAOUT_NAME} POST_BUILD
389-
COMMAND ${QT5_WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
396+
findQtInstallationTool("windeployqt")
397+
add_custom_command(TARGET test_analog_out POST_BUILD
398+
COMMAND ${QT_DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${LIB_NAME}>)
390399
ENDIF(WIN32)
391400
ENDIF(${BUILD_TEST_ANAOUT})
392401

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ https://github.com/dashesy/CereLink/wiki
2020

2121
# Build
2222

23-
Some build information can be found in the comments at the top of the CMakeLists.txt.
24-
Additional information can be found in the wiki.
23+
The BUILD.md document has the most up to date build instructions.

cli/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ option(BUILD_CLI "Build C++/CLI" OFF)
22

33
IF(${BUILD_CLI})
44
cmake_minimum_required(VERSION 3.12)
5+
set(CMAKE_CSharp_FLAGS "/langversion:latest")
56
SET( LIB_NAME_CLI cbsdk_cli)
67
SET(cbsdk_cli_SOURCE
7-
${CMAKE_CURRENT_LIST_DIR}/cbsdk_native.h ${CMAKE_CURRENT_LIST_DIR}/cbsdk_native.cpp
8+
${CMAKE_CURRENT_LIST_DIR}/cbsdk_native.h
9+
${CMAKE_CURRENT_LIST_DIR}/cbsdk_native.cpp
810
${CMAKE_CURRENT_LIST_DIR}/AssemblyInfo.cpp)
911
set_source_files_properties(${cbsdk_cli_SOURCE} PROPERTIES LANGUAGE "CXX")
1012
ADD_LIBRARY(${LIB_NAME_CLI} MODULE ${cbsdk_cli_SOURCE})
@@ -22,7 +24,7 @@ IF(${BUILD_CLI})
2224
PROPERTIES
2325
COMMON_LANGUAGE_RUNTIME ""
2426
#DEBUG_POSTFIX "" # With d postfix then the C# app can't find it.
25-
)
27+
)
2628
# target_compile_options(${LIB_NAME_CLI} PRIVATE /clr)
2729
# target_compile_options(${LIB_NAME_CLI} PRIVATE /EHa)
2830
# STRING(REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

cli/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,29 @@ Requires CMake >= 3.12.
1111
Only tested on Windows VS 2017.
1212
Add the `-DBUILD_CLI=ON` option to the build command described in ../BUILD.md.
1313

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

1721
## C++/CLI Interface
1822

1923
I couldn't figure out how to use CMake to get the C++/CLI test project (in TestCLI folder) to
2024
reference the cbsdk_cli.dll properly. So you'll have to do that manually in the project.
25+
2126
Under the TestCLI target, delete the cbsdk_cli reference and add a new reference pointing to
2227
dist/lib64/cbsdk_cli.dll
2328

29+
* Open the build\CBSDK.sln file.
30+
* Change the config from Debug to Release
31+
* Expand the TestCLI target (click on right arrow)
32+
* Expand "References"
33+
* Right click on `cbsdk_cli` and remove it.
34+
* Right click on References and select `Add Reference...`
35+
* In the new dialog window, browse to dist/lib64/cbsdk_cli.dll
36+
2437
## C# Interface using P/Invoke
2538

2639
An example is provided in TestCSharp.

0 commit comments

Comments
 (0)