Skip to content

Commit 0fde169

Browse files
author
Benjamin Sergeant
committed
restructure project
1 parent c09015e commit 0fde169

26 files changed

+120
-45
lines changed

CMakeLists.txt

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ set (CMAKE_CXX_STANDARD 14)
1212
set (CXX_STANDARD_REQUIRED ON)
1313
set (CMAKE_CXX_EXTENSIONS OFF)
1414

15-
# -Wshorten-64-to-32 does not work with clang
16-
if (NOT WIN32)
15+
if (UNIX)
1716
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
1817
endif()
1918

@@ -211,6 +210,15 @@ install(TARGETS ixwebsocket
211210
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include/ixwebsocket/
212211
)
213212

214-
if (USE_WS)
215-
add_subdirectory(ws)
213+
if (USE_WS OR USE_TEST)
214+
add_subdirectory(ixcore)
215+
add_subdirectory(ixcrypto)
216+
add_subdirectory(ixcobra)
217+
218+
if (USE_WS)
219+
add_subdirectory(ws)
220+
endif()
221+
if (USE_TEST)
222+
add_subdirectory(test)
223+
endif()
216224
endif()

ixcobra/CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Author: Benjamin Sergeant
3+
# Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
4+
#
5+
6+
set (IXCOBRA_SOURCES
7+
ixcobra/IXCobraConnection.cpp
8+
ixcobra/IXCobraMetricsThreadedPublisher.cpp
9+
ixcobra/IXCobraMetricsPublisher.cpp
10+
)
11+
12+
set (IXCOBRA_HEADERS
13+
ixcobra/IXCobraConnection.h
14+
ixcobra/IXCobraMetricsThreadedPublisher.h
15+
ixcobra/IXCobraMetricsPublisher.h
16+
)
17+
18+
add_library(ixcobra STATIC
19+
${IXCOBRA_SOURCES}
20+
${IXCOBRA_HEADERS}
21+
)
22+
23+
set(IXCOBRA_INCLUDE_DIRS
24+
.
25+
../ixcore
26+
../ixcrypto
27+
../ixwebsocket
28+
../third_party)
29+
30+
target_include_directories( ixcobra PUBLIC ${IXCOBRA_INCLUDE_DIRS} )
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

ixcore/CMakeLists.txt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Author: Benjamin Sergeant
3+
# Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
4+
#
5+
6+
set (IXCORE_SOURCES
7+
ixcore/utils/IXCoreLogger.cpp
8+
)
9+
10+
set (IXCORE_HEADERS
11+
ixcore/utils/IXCoreLogger.h
12+
)
13+
14+
add_library(ixcore STATIC
15+
${IXCORE_SOURCES}
16+
${IXCORE_HEADERS}
17+
)
18+
19+
target_include_directories( ixcore PUBLIC . )
File renamed without changes.
File renamed without changes.

ixcrypto/CMakeLists.txt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# Author: Benjamin Sergeant
3+
# Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
4+
#
5+
6+
set (IXCRYPTO_SOURCES
7+
ixcrypto/IXHMac.cpp
8+
ixcrypto/IXBase64.cpp
9+
ixcrypto/IXUUid.cpp
10+
ixcrypto/IXHash.cpp
11+
)
12+
13+
set (IXCRYPTO_HEADERS
14+
ixcrypto/IXHMac.h
15+
ixcrypto/IXBase64.h
16+
ixcrypto/IXUUid.h
17+
ixcrypto/IXHash.h
18+
)
19+
20+
add_library(ixcrypto STATIC
21+
${IXCRYPTO_SOURCES}
22+
${IXCRYPTO_HEADERS}
23+
)
24+
25+
set(IXCRYPTO_INCLUDE_DIRS
26+
.
27+
../ixcore)
28+
29+
target_include_directories( ixcrypto PUBLIC ${IXCRYPTO_INCLUDE_DIRS} )
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ install: brew
99
# on osx it is good practice to make /usr/local user writable
1010
# sudo chown -R `whoami`/staff /usr/local
1111
brew:
12-
mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 .. ; make -j install)
12+
mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_TEST=1 .. ; make -j install)
1313

1414
ws:
1515
mkdir -p build && (cd build ; cmake -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; make -j)
@@ -57,8 +57,9 @@ test_server:
5757
# env TEST=Websocket_server make test
5858
# env TEST=Websocket_chat make test
5959
# env TEST=heartbeat make test
60-
test:
61-
python2.7 test/run.py
60+
test: brew
61+
# (cd test ; ../build/test/ixwebsocket_unittest)
62+
(cd test ; python2.7 run.py -r)
6263

6364
ws_test: ws
6465
(cd ws ; env DEBUG=1 PATH=../ws/build:$$PATH bash test_ws.sh)

test/CMakeLists.txt

+4-13
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ if (MAC)
1515
option(USE_TLS "Add TLS support" ON)
1616
endif()
1717

18-
add_subdirectory(${PROJECT_SOURCE_DIR}/.. ixwebsocket)
19-
2018
set (WS ../ws)
2119

2220
include_directories(
@@ -36,17 +34,6 @@ set (SOURCES
3634
../third_party/msgpack11/msgpack11.cpp
3735
../third_party/jsoncpp/jsoncpp.cpp
3836

39-
${WS}/ixcore/utils/IXCoreLogger.cpp
40-
41-
${WS}/ixcrypto/IXBase64.cpp
42-
${WS}/ixcrypto/IXHash.cpp
43-
${WS}/ixcrypto/IXUuid.cpp
44-
${WS}/ixcrypto/IXHMac.cpp
45-
46-
${WS}/ixcobra/IXCobraConnection.cpp
47-
${WS}/ixcobra/IXCobraMetricsPublisher.cpp
48-
${WS}/ixcobra/IXCobraMetricsThreadedPublisher.cpp
49-
5037
${WS}/snake/IXSnakeServer.cpp
5138
${WS}/snake/IXSnakeProtocol.cpp
5239
${WS}/snake/IXAppConfig.cpp
@@ -99,5 +86,9 @@ if (APPLE AND USE_TLS)
9986
target_link_libraries(ixwebsocket_unittest "-framework foundation" "-framework security")
10087
endif()
10188

89+
target_link_libraries(ixwebsocket_unittest ixcore)
90+
target_link_libraries(ixwebsocket_unittest ixcrypto)
91+
target_link_libraries(ixwebsocket_unittest ixcobra)
10292
target_link_libraries(ixwebsocket_unittest ixwebsocket)
93+
10394
install(TARGETS ixwebsocket_unittest DESTINATION bin)

test/IXCobraChatTest.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ TEST_CASE("Cobra_chat", "[cobra_chat]")
309309
timeout -= 10;
310310
if (timeout <= 0)
311311
{
312+
snakeServer.stop();
312313
REQUIRE(false); // timeout
313314
}
314315
}
@@ -332,6 +333,7 @@ TEST_CASE("Cobra_chat", "[cobra_chat]")
332333
timeout -= 10;
333334
if (timeout <= 0)
334335
{
336+
snakeServer.stop();
335337
REQUIRE(false); // timeout
336338
}
337339
}

test/run.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,22 @@ def generateXmlOutput(results, xmlOutput, testRunName, runTime):
350350

351351

352352
def run(testName, buildDir, sanitizer, xmlOutput,
353-
testRunName, buildOnly, useLLDB, cpuCount):
353+
testRunName, buildOnly, useLLDB, cpuCount, runOnly):
354354
'''Main driver. Run cmake, compiles, execute and validate the testsuite.'''
355355

356356
# gen build files with CMake
357-
runCMake(sanitizer, buildDir)
358-
359-
if platform.system() == 'Linux':
360-
# build with make -j
361-
runCommand('make -C {} -j 2'.format(buildDir))
362-
elif platform.system() == 'Darwin':
363-
# build with make
364-
runCommand('make -C {} -j 8'.format(buildDir))
365-
else:
366-
# build with cmake on recent
367-
runCommand('cmake --build --parallel {}'.format(buildDir))
357+
if not runOnly:
358+
runCMake(sanitizer, buildDir)
359+
360+
if platform.system() == 'Linux':
361+
# build with make -j
362+
runCommand('make -C {} -j 2'.format(buildDir))
363+
elif platform.system() == 'Darwin':
364+
# build with make
365+
runCommand('make -C {} -j 8'.format(buildDir))
366+
else:
367+
# build with cmake on recent
368+
runCommand('cmake --build --parallel {}'.format(buildDir))
368369

369370
if buildOnly:
370371
return
@@ -454,6 +455,8 @@ def main():
454455
help='Validate XML output.')
455456
parser.add_argument('--build_only', '-b', action='store_true',
456457
help='Stop after building. Do not run the unittest.')
458+
parser.add_argument('--run_only', '-r', action='store_true',
459+
help='Only run the test, do not build anything.')
457460
parser.add_argument('--output', '-o', help='Output XML file.')
458461
parser.add_argument('--lldb', action='store_true',
459462
help='Run the test through lldb.')
@@ -492,7 +495,7 @@ def main():
492495
if platform.system() == 'Windows':
493496
TEST_EXE_PATH = os.path.join(buildDir, BUILD_TYPE, 'ixwebsocket_unittest.exe')
494497
else:
495-
TEST_EXE_PATH = os.path.join(buildDir, 'ixwebsocket_unittest')
498+
TEST_EXE_PATH = '../build/test/ixwebsocket_unittest'
496499

497500
if args.list:
498501
# catch2 exit with a different error code when requesting the list of files
@@ -511,7 +514,7 @@ def main():
511514
args.lldb = False
512515

513516
return run(args.test, buildDir, sanitizer, xmlOutput,
514-
testRunName, args.build_only, args.lldb, args.cpu_count)
517+
testRunName, args.build_only, args.lldb, args.cpu_count, args.run_only)
515518

516519

517520
if __name__ == '__main__':

ws/CMakeLists.txt

+3-11
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ add_executable(ws
3535
../third_party/jsoncpp/jsoncpp.cpp
3636
${STATSD_CLIENT_SOURCES}
3737

38-
ixcore/utils/IXCoreLogger.cpp
39-
40-
ixcrypto/IXBase64.cpp
41-
ixcrypto/IXHash.cpp
42-
ixcrypto/IXUuid.cpp
43-
ixcrypto/IXHMac.cpp
44-
45-
ixcobra/IXCobraConnection.cpp
46-
ixcobra/IXCobraMetricsPublisher.cpp
47-
ixcobra/IXCobraMetricsThreadedPublisher.cpp
48-
4938
snake/IXSnakeServer.cpp
5039
snake/IXSnakeProtocol.cpp
5140
snake/IXAppConfig.cpp
@@ -73,6 +62,9 @@ add_executable(ws
7362
ws_autobahn.cpp
7463
ws.cpp)
7564

65+
target_link_libraries(ws ixcore)
66+
target_link_libraries(ws ixcrypto)
67+
target_link_libraries(ws ixcobra)
7668
target_link_libraries(ws ixwebsocket)
7769

7870
if(NOT APPLE AND NOT USE_MBED_TLS)

0 commit comments

Comments
 (0)