Skip to content

Commit bb018bf

Browse files
committed
EHN: Websocket is linked correctly. Instruction added. #209
1 parent ea56c2d commit bb018bf

File tree

4 files changed

+174
-8
lines changed

4 files changed

+174
-8
lines changed

BUILD.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,30 @@ Useful OpenHEVC build intructions:
107107

108108
http://openhevc.github.io/openHEVC/
109109

110+
WebSocket
111+
---------------
112+
You might want to use OpenIGTLink library to perform websocket communication.
113+
114+
* Prerequisites
115+
This functionality is only tested on Mac OSX platform. The websocketpp project needs to be build and installed first.
116+
~~~~
117+
$ git clone https://github.com/zaphoyd/websocketpp
118+
$ mkdir websocketpp-build
119+
$ cd websocketpp-build
120+
$ cmake -DCMAKE_INSTALL_PREFIX=${path-to-your-installation} ../websocketpp
121+
$ make & make install
122+
~~~~
123+
124+
Then go to the build directory of the OpenIGTLink, run these commands:
125+
126+
~~~~
127+
$ cmake -DOpenIGTLink_USE_WEBSOCKET=ON -DBUILD_EXAMPLES=ON -Dwebsocketpp_DIR:PATH=${path-to-your-installation}/lib/cmake/websocketpp ${your-openigtlink_source}
128+
$ make
129+
$ ./bin/WebSocketServer ${your-openigtlink_source}/Examples/WebSocket 9002
130+
~~~~
131+
132+
Open your browser and type: localhost:9002, there will be a connect button on the page, simply click it and you will see updating tracking data.
133+
110134
Other Platforms
111135
---------------
112136

Source/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,11 @@ IF (NOT (${CMAKE_VERSION} VERSION_LESS 3.4))
211211
# Configure WebSocket
212212
# Create the link to the WebSocket libraries
213213
IF(OpenIGTLink_USE_WEBSOCKET)
214-
FIND_PACKAGE(WebSocket REQUIRED)
215-
LIST(APPEND LINK_LIBS WebSocket)
216-
214+
FIND_PACKAGE(websocketpp REQUIRED)
215+
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/WebSocket/UseWebSocket.cmake)
216+
# Copy the UseWebSocket.cmake file to the binary tree for setting up websocket build environment.
217+
CONFIGURE_FILE(${OpenIGTLink_SOURCE_DIR}/Source/WebSocket/UseWebSocket.cmake
218+
${OpenIGTLink_BINARY_DIR}/UseWebSocket.cmake COPYONLY IMMEDIATE)
217219
LIST(APPEND OpenIGTLink_SOURCES
218220
${CMAKE_CURRENT_SOURCE_DIR}/WebSocket/igtlWebServerSocket.cxx
219221
${CMAKE_CURRENT_SOURCE_DIR}/WebSocket/igtlWebClientSocket.cxx
@@ -223,9 +225,9 @@ IF (NOT (${CMAKE_VERSION} VERSION_LESS 3.4))
223225
${CMAKE_CURRENT_SOURCE_DIR}/WebSocket/igtlWebServerSocket.h
224226
${CMAKE_CURRENT_SOURCE_DIR}/WebSocket/igtlWebClientSocket.h
225227
)
226-
227228
LIST(APPEND OpenIGTLink_INCLUDE_DIRS
228229
${CMAKE_CURRENT_SOURCE_DIR}/WebSocket
230+
${WEBSOCKETPP_INCLUDE_DIR}
229231
)
230232
ENDIF()
231233
ELSE()
@@ -262,9 +264,6 @@ IF (NOT (${CMAKE_VERSION} VERSION_LESS 3.4))
262264
add_dependencies(OpenIGTLink AV1)
263265
ENDIF()
264266
ENDIF()
265-
IF(OpenIGTLink_USE_WEBSOCKET)
266-
add_dependencies(OpenIGTLink WebSocket)
267-
ENDIF()
268267
ENDIF()
269268

270269
TARGET_LINK_LIBRARIES(OpenIGTLink PUBLIC ${LINK_LIBS})
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
set (WEBSOCKETPP_PLATFORM_LIBS "")
2+
set (WEBSOCKETPP_PLATFORM_TLS_LIBS "")
3+
set (WEBSOCKETPP_BOOST_LIBS "")
4+
5+
# VC9 and C++11 reasoning
6+
if (ENABLE_CPP11 AND MSVC AND MSVC90)
7+
message("* Detected Visual Studio 9 2008, disabling C++11 support.")
8+
set (ENABLE_CPP11 FALSE)
9+
endif ()
10+
11+
# Detect clang. Not officially reported by cmake.
12+
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-v" ERROR_VARIABLE CXX_VER_STDERR)
13+
if ("${CXX_VER_STDERR}" MATCHES ".*clang.*")
14+
set (CMAKE_COMPILER_IS_CLANGXX 1)
15+
endif ()
16+
17+
# C++11 defines
18+
if (ENABLE_CPP11)
19+
if (MSVC)
20+
add_definitions (-D_WEBSOCKETPP_CPP11_FUNCTIONAL_)
21+
add_definitions (-D_WEBSOCKETPP_CPP11_SYSTEM_ERROR_)
22+
add_definitions (-D_WEBSOCKETPP_CPP11_RANDOM_DEVICE_)
23+
add_definitions (-D_WEBSOCKETPP_CPP11_MEMORY_)
24+
else()
25+
add_definitions (-D_WEBSOCKETPP_CPP11_STL_)
26+
endif()
27+
endif ()
28+
29+
# Visual studio
30+
if (MSVC)
31+
set (WEBSOCKETPP_BOOST_LIBS system thread)
32+
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Gy /GF /Ox /Ob2 /Ot /Oi /MP /arch:SSE2 /fp:fast")
33+
set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
34+
add_definitions (/W3 /wd4996 /wd4995 /wd4355)
35+
add_definitions (-DUNICODE -D_UNICODE)
36+
add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
37+
add_definitions (-DNOMINMAX)
38+
endif ()
39+
40+
# g++
41+
if (CMAKE_COMPILER_IS_GNUCXX)
42+
set (WEBSOCKETPP_PLATFORM_LIBS pthread rt)
43+
set (WEBSOCKETPP_PLATFORM_TLS_LIBS ssl crypto)
44+
set (WEBSOCKETPP_BOOST_LIBS system thread)
45+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
46+
if (NOT APPLE)
47+
add_definitions (-DNDEBUG -Wall -Wcast-align) # todo: should we use CMAKE_C_FLAGS for these?
48+
endif ()
49+
50+
# Try to detect version. Note: Not tested!
51+
execute_process (COMMAND ${CMAKE_CXX_COMPILER} "-dumpversion" OUTPUT_VARIABLE GCC_VERSION)
52+
if ("${GCC_VERSION}" STRGREATER "4.4.0")
53+
message("* C++11 support partially enabled due to GCC version ${GCC_VERSION}")
54+
set (WEBSOCKETPP_BOOST_LIBS system thread)
55+
endif ()
56+
endif ()
57+
58+
# clang
59+
if (CMAKE_COMPILER_IS_CLANGXX)
60+
if (NOT APPLE)
61+
set (WEBSOCKETPP_PLATFORM_LIBS pthread rt)
62+
else()
63+
set (WEBSOCKETPP_PLATFORM_LIBS pthread)
64+
endif()
65+
set (WEBSOCKETPP_PLATFORM_TLS_LIBS ssl crypto)
66+
set (WEBSOCKETPP_BOOST_LIBS system thread)
67+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++") # todo: is libc++ really needed here?
68+
if (NOT APPLE)
69+
add_definitions (-DNDEBUG -Wall -Wno-padded) # todo: should we use CMAKE_C_FLAGS for these?
70+
endif ()
71+
endif ()
72+
73+
# OSX, can override above.
74+
if (APPLE)
75+
add_definitions (-DNDEBUG -Wall)
76+
endif ()
77+
78+
# Set BOOST_ROOT env variable or pass with cmake -DBOOST_ROOT=path.
79+
# BOOST_ROOT can also be defined by a previous run from cmake cache.
80+
if (NOT "$ENV{BOOST_ROOT_CPP11}" STREQUAL "")
81+
# Scons documentation for BOOST_ROOT_CPP11:
82+
# "look for optional second boostroot compiled with clang's libc++ STL library
83+
# this prevents warnings/errors when linking code built with two different
84+
# incompatible STL libraries."
85+
file (TO_CMAKE_PATH "$ENV{BOOST_ROOT_CPP11}" BOOST_ROOT)
86+
set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE)
87+
endif ()
88+
if ("${BOOST_ROOT}" STREQUAL "")
89+
file (TO_CMAKE_PATH "$ENV{BOOST_ROOT}" BOOST_ROOT)
90+
# Cache BOOST_ROOT for runs that do not define $ENV{BOOST_ROOT}.
91+
set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE)
92+
endif ()
93+
94+
if (MSVC)
95+
set (Boost_USE_MULTITHREADED TRUE)
96+
set (Boost_USE_STATIC_LIBS TRUE)
97+
else ()
98+
set (Boost_USE_MULTITHREADED FALSE)
99+
set (Boost_USE_STATIC_LIBS FALSE)
100+
endif ()
101+
102+
if (BOOST_STATIC)
103+
set (Boost_USE_STATIC_LIBS TRUE)
104+
endif ()
105+
106+
if (NOT Boost_USE_STATIC_LIBS)
107+
add_definitions (/DBOOST_TEST_DYN_LINK)
108+
endif ()
109+
110+
set (Boost_FIND_REQUIRED TRUE)
111+
set (Boost_FIND_QUIETLY TRUE)
112+
set (Boost_DEBUG FALSE)
113+
set (Boost_USE_MULTITHREADED TRUE)
114+
set (Boost_ADDITIONAL_VERSIONS "1.39.0" "1.40.0" "1.41.0" "1.42.0" "1.43.0" "1.44.0" "1.46.1") # todo: someone who knows better spesify these!
115+
116+
find_package (Boost 1.39.0 COMPONENTS "${WEBSOCKETPP_BOOST_LIBS}")
117+
118+
if (Boost_FOUND)
119+
# Boost is a project wide global dependency.
120+
include_directories (${Boost_INCLUDE_DIRS})
121+
link_directories (${Boost_LIBRARY_DIRS})
122+
123+
# Pretty print status
124+
message (STATUS "-- Include Directories")
125+
foreach (include_dir ${Boost_INCLUDE_DIRS})
126+
message (STATUS " " ${include_dir})
127+
endforeach ()
128+
message (STATUS "-- Library Directories")
129+
foreach (library_dir ${Boost_LIBRARY_DIRS})
130+
message (STATUS " " ${library_dir})
131+
endforeach ()
132+
message (STATUS "-- Libraries")
133+
foreach (boost_lib ${Boost_LIBRARIES})
134+
message (STATUS " " ${boost_lib})
135+
endforeach ()
136+
message ("")
137+
else ()
138+
message (FATAL_ERROR "Failed to find required dependency: boost")
139+
endif ()
140+
141+
find_package(OpenSSL)
142+
find_package(ZLIB)

UseOpenIGTLink.cmake.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ include(${OpenIGTLink_LIBRARY_TARGETS_FILE})
2525

2626
IF(OpenIGTLink_USE_WEBSOCKET)
2727
SET(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/websocketpp")
28-
find_package(WebSocket REQUIRED)
28+
find_package(websocketpp REQUIRED)
29+
INCLUDE(${OpenIGTLink_DIR}/UseWebSocket.cmake)
2930
ENDIF()

0 commit comments

Comments
 (0)