Skip to content

Commit a94a3cd

Browse files
2 parents d1c9e2c + 580d483 commit a94a3cd

File tree

5 files changed

+144
-13
lines changed

5 files changed

+144
-13
lines changed

CMakeLists.txt

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@
55
cmake_minimum_required(VERSION 2.8.11)
66
project (mFAST CXX)
77

8+
# options to build tests, examples and packages
9+
option(BUILD_TESTS "Build tests" ON)
10+
option(BUILD_EXAMPLES "Build examples" ON)
11+
option(BUILD_PACKAGES "Build packages" ON)
12+
13+
# debug build by default
14+
if(NOT CMAKE_BUILD_TYPE)
15+
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build" FORCE)
16+
endif(NOT CMAKE_BUILD_TYPE)
17+
818
if(POLICY CMP0054)
919
cmake_policy(SET CMP0054 OLD)
1020
endif()
1121

12-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
22+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1323

1424
set(MFAST_MAJOR_VERSION 1)
1525
set(MFAST_MINOR_VERSION 3)
1626
set(MFAST_PATCH_VERSION 0)
1727
set(MFAST_VERSION ${MFAST_MAJOR_VERSION}.${MFAST_MINOR_VERSION}.${MFAST_PATCH_VERSION})
1828
set(MFAST_SOVERSION ${MFAST_MAJOR_VERSION}.${MFAST_MINOR_VERSION})
1929

20-
set(CPACK_PACKAGE_VERSION ${MFAST_VERSION})
21-
set(CPACK_PACKAGE_NAME "mfast")
22-
23-
include(CPack)
2430
include(SetInstallPaths)
2531
include(Emscripten)
2632
include(SetCXXStandard)
@@ -30,6 +36,30 @@ include(SetupCoverage)
3036
# flag to enable building shared/dynamic library
3137
set(BUILD_SHARED_LIBS OFF CACHE BOOL "build shared/dynamic library")
3238

39+
if(BUILD_PACKAGES)
40+
# Build deb package by default
41+
if(NOT CPACK_GENERATOR)
42+
set(CPACK_GENERATOR "DEB" CACHE STRING "List of generators.")
43+
endif(NOT CPACK_GENERATOR)
44+
45+
if(CUSTOM_INSTALL_PREFIX)
46+
set(CMAKE_INSTALL_PREFIX ${CUSTOM_INSTALL_PREFIX} CACHE STRING "Custom installation prefix.")
47+
set(CPACK_SET_DESTDIR true)
48+
set(CPACK_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
49+
endif(CUSTOM_INSTALL_PREFIX)
50+
51+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A FAST (FIX Adapted for STreaming) encoder/decoder")
52+
set(CPACK_PACKAGE_NAME "mfast")
53+
set(CPACK_PACKAGE_VERSION ${MFAST_VERSION})
54+
set(CPACK_PACKAGE_VENDOR "Object Computing, Inc.")
55+
set(CPACK_PACKAGE_CONTACT "[email protected]")
56+
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Huang-Ming Huang")
57+
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
58+
59+
include(CPack)
60+
61+
endif(BUILD_PACKAGES)
62+
3363
find_package(Boost 1.56.0 REQUIRED)
3464
include_directories(${Boost_INCLUDE_DIR})
3565
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/tinyxml2)
@@ -48,27 +78,27 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
4878
add_subdirectory (src)
4979
include(FastTypeGenTarget)
5080

51-
enable_testing()
52-
add_subdirectory (tests)
81+
if(BUILD_TESTS)
82+
enable_testing()
83+
add_subdirectory (tests)
84+
endif(BUILD_TESTS)
5385

5486
if (BUILD_SHARED_LIBS)
5587
set(MFAST_LIBRARIES "${MFAST_SHARED_LIBRARIES}")
5688
else (BUILD_SHARED_LIBS)
5789
set(MFAST_LIBRARIES "${MFAST_STATIC_LIBRARIES}")
5890
endif (BUILD_SHARED_LIBS)
5991

60-
add_subdirectory (examples)
61-
92+
if(BUILD_EXAMPLES)
93+
add_subdirectory (examples)
94+
endif(BUILD_EXAMPLES)
6295

6396
# Setting up dist target
64-
# ===============================
65-
6697
set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${MFAST_VERSION})
6798
add_custom_target(dist
6899
COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
69100
| bzip2 > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
70101
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
71-
72102

73103
include(GenProjectConfig)
74104

@@ -77,4 +107,18 @@ install(FILES
77107
${schema_files}
78108
DESTINATION ${INSTALL_DATA_DIR}/mfast)
79109

80-
110+
# Print summary
111+
message(STATUS "")
112+
message(STATUS "CMAKE_COMMAND: " ${CMAKE_COMMAND})
113+
message(STATUS "CMAKE_SYSTEM: " ${CMAKE_SYSTEM})
114+
message(STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
115+
116+
message(STATUS "CMAKE_CXX_COMPILER: " ${CMAKE_CXX_COMPILER})
117+
message(STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})
118+
message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
119+
120+
message(STATUS "BUILD_SHARED_LIBS: " ${BUILD_SHARED_LIBS})
121+
message(STATUS "BUILD_TESTS: " ${BUILD_TESTS})
122+
message(STATUS "BUILD_EXAMPLES: " ${BUILD_EXAMPLES})
123+
message(STATUS "BUILD_PACKAGES: " ${BUILD_PACKAGES})
124+
message(STATUS "")

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_subdirectory (performance_test)
22
add_subdirectory (message_printer)
3+
add_subdirectory (hello_world)
34
# add_subdirectory (Model)

examples/hello_world/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#########################################################################
2+
# The following lines shows how to write CMakeLists.txt for mFAST applications
3+
# when the applications are not in the mFAST source tree.
4+
##########################################################################
5+
6+
# cmake_minimum_required(VERSION 2.8)
7+
# find_package(mFAST REQUIRED COMPONENTS coder)
8+
#
9+
# include_directories(${MFAST_INCLUDE_DIR})
10+
# link_directories(${MFAST_LIBRARY_DIRS})
11+
12+
add_executable (hello_world hello_world.cpp)
13+
target_link_libraries (hello_world ${MFAST_LIBRARIES})

examples/hello_world/hello_world.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
#include <mfast.h>
5+
#include <mfast/coder/fast_decoder.h>
6+
#include <mfast/json/json.h>
7+
#include <mfast/xml_parser/dynamic_templates_description.h>
8+
9+
using std::string;
10+
using std::ostringstream;
11+
using std::cout;
12+
using std::endl;
13+
14+
using mfast::templates_description;
15+
using mfast::dynamic_templates_description;
16+
using mfast::fast_decoder;
17+
using mfast::message_cref;
18+
using mfast::ascii_string_cref;
19+
using mfast::json::encode;
20+
21+
// example from http://jettekfix.com/node/36
22+
static const string fast_template =
23+
"\
24+
<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\
25+
<templates xmlns=\"http://www.fixprotocol.org/ns/fast/td/1.1\">\
26+
<template dictionary=\"1\" id=\"1\" name=\"HelloWorld\">\
27+
<string id=\"58\" name=\"Text\">\
28+
<default value=\"\"></default>\
29+
</string>\
30+
</template>\
31+
</templates>\
32+
";
33+
34+
// 58=HelloWorld<SOH>
35+
static const string fast_message =
36+
"\xE0\x81\x48\x65\x6C\x6C\x6F\x57\x6F\x72\x6C\xE4";
37+
38+
int main() {
39+
dynamic_templates_description description(fast_template);
40+
41+
const templates_description* descriptions[] = {&description};
42+
43+
fast_decoder decoder;
44+
decoder.include(descriptions);
45+
46+
const char* start = fast_message.c_str();
47+
const char* end = start + fast_message.length();
48+
49+
cout << "Decoding message \"58=HelloWorld<SOH>\":" << endl;
50+
cout << endl;
51+
52+
message_cref msg = decoder.decode(start, end);
53+
54+
cout << "Template id: " << msg.id() << endl;
55+
cout << "Template name: " << msg.name() << endl;
56+
cout << endl;
57+
58+
ascii_string_cref field = static_cast<ascii_string_cref>((msg)[0]);
59+
60+
cout << "Field id: " << field.id() << endl;
61+
cout << "Field name: " << field.name() << endl;
62+
cout << "Field content: " << field.c_str() << endl;
63+
cout << endl;
64+
65+
cout << "Encoding message to JSON:" << endl;
66+
67+
ostringstream json_message;
68+
bool result = encode(json_message, msg, 0);
69+
if (result) cout << "Success: " << json_message.str() << endl;
70+
71+
return 0;
72+
}

src/mfast/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
1010
set(mfast_SRCS ${sources} ${instruction_sources} ${headers} ${instruction_headers})
1111

1212
add_library(mfast_static STATIC ${mfast_SRCS})
13+
target_include_directories(mfast_static PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
1314

1415
if (UNIX)
1516
set_target_properties(mfast_static PROPERTIES OUTPUT_NAME mfast)

0 commit comments

Comments
 (0)