[WIP] Cmake (#8)

* Adds initial cmake

* Renames include according common convention

* Tries to include examples

* Changes to protokit

* Improves install step

* Removes /protokit

* Fixes some comments

* Adds a few feature tests

* Adds FLOCK includes

* Removes if in feature tests

* Fixes missing normApi.cpp

* Adds missing include

* Fixes bad rename
pull/9/head
mjvk 2020-05-18 16:19:04 +02:00 committed by GitHub
parent a55f796084
commit 8d8c3f0da5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 2406 additions and 2177 deletions

164
CMakeLists.txt Normal file
View File

@ -0,0 +1,164 @@
cmake_minimum_required(VERSION 3.11)
# set the project name
project(norm VERSION 1.5.8)
set(COMMON src/common)
option(NORM_BUILD_EXAMPLES "Enables building of the examples in /examples." OFF)
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(dirfd "dirent.h" HAVE_DIRFD)
if(HAVE_DIRFD)
list(APPEND PLATFORM_DEFINITIONS HAVE_DIRFD)
endif()
check_cxx_symbol_exists(lockf "unistd.h" HAVE_LOCKF)
if(HAVE_LOCKF)
list(APPEND PLATFORM_DEFINITIONS HAVE_LOCKF)
endif()
check_cxx_symbol_exists(flock "sys/file.h" HAVE_FLOCK)
if(HAVE_FLOCK)
list(APPEND PLATFORM_DEFINITIONS HAVE_FLOCK)
endif()
# Check for libraries
find_package(protokit QUIET)
if(NOT protokit_FOUND)
include(FetchContent)
FetchContent_Declare(
protokit
GIT_REPOSITORY https://github.com/USNavalResearchLaboratory/protolib.git
GIT_TAG origin/master
)
FetchContent_MakeAvailable(protokit)
endif()
# List header files
list(APPEND PUBLIC_HEADER_FILES
include/galois.h
include/normApi.h
include/normEncoder.h
include/normEncoderMDP.h
include/normEncoderRS16.h
include/normEncoderRS8.h
include/normFile.h
include/normMessage.h
include/normNode.h
include/normObject.h
include/normPostProcess.h
include/normSegment.h
include/normSession.h
include/normSimAgent.h
include/normVersion.h
)
# List platform-independent source files
list(APPEND COMMON_SOURCE_FILES
${COMMON}/galois.cpp
${COMMON}/normApi.cpp
${COMMON}/normEncoder.cpp
${COMMON}/normEncoderMDP.cpp
${COMMON}/normEncoderRS16.cpp
${COMMON}/normEncoderRS8.cpp
${COMMON}/normFile.cpp
${COMMON}/normMessage.cpp
${COMMON}/normNode.cpp
${COMMON}/normObject.cpp
${COMMON}/normSegment.cpp
${COMMON}/normSession.cpp )
# Setup platform independent include directory
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include )
# Setup platform dependent libraries, defines, source file and compiler flags
if(MSVC)
list(APPEND PLATFORM_LIBS Shell32)
list(APPEND PLATFORM_DEFINITIONS _CONSOLE)
list(APPEND PLATFORM_SOURCE_FILES src/win32/win32PostProcess.cpp)
elseif(UNIX)
list(APPEND PLATFORM_SOURCE_FILES src/unix/unixPostProcess.cpp)
endif()
include(GNUInstallDirs)
# Setup target
add_library(norm ${PLATFORM_SOURCE_FILES} ${COMMON_SOURCE_FILES} ${PUBLIC_HEADER_FILES})
target_link_libraries(norm PRIVATE ${PLATFORM_LIBS} protokit::protokit)
target_compile_definitions(norm PUBLIC ${PLATFORM_DEFINITIONS})
target_compile_options(norm PUBLIC ${PLATFORM_FLAGS})
target_include_directories(norm PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(norm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
# Install target
install( TARGETS norm EXPORT normTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/norm)
install( EXPORT normTargets
FILE normTargets.cmake
NAMESPACE norm::
DESTINATION ${INSTALL_CONFIGDIR}
)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/norm)
# Create a ConfigVersion.cmake file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/normConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/normConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/normConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
# Install the config, configversion and custom find modules
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/normConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/normConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
##############################################
# Exporting from the build tree
export(EXPORT normTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/normTargets.cmake
NAMESPACE norm::)
# Register package in user's package registry
export(PACKAGE norm)
if(NORM_BUILD_EXAMPLES)
# Setup examples
list(APPEND examples
#normDataExample
normDataRecv
normDataSend
normFileRecv
normFileSend
normStreamRecv
normStreamSend
normMsgr
normStreamer
normCast
normClient
normServer
#wintest
)
foreach(example ${examples})
add_executable(${example} examples/${example}.cpp examples/normSocket.cpp)
target_link_libraries(${example} PRIVATE norm protokit::protokit)
endforeach()
endif()

10
cmake/normConfig.cmake.in Normal file
View File

@ -0,0 +1,10 @@
include(GNUInstallDirs)
include(CMakeFindDependencyMacro)
# Same syntax as find_package
find_dependency(protokit REQUIRED)
# Add the targets file
include("${CMAKE_CURRENT_LIST_DIR}/normTargets.cmake")

View File

@ -2,6 +2,7 @@
#include "normApi.h" #include "normApi.h"
#include <stdio.h> // for printf(), etc #include <stdio.h> // for printf(), etc
#include <stdlib.h> // for atoi(), etc #include <stdlib.h> // for atoi(), etc
#include <cassert>
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>

View File

@ -63,7 +63,7 @@ int main(int argc, char* argv[])
// NOTE: These are debugging routines available // NOTE: These are debugging routines available
// (not necessary for normal app use) // (not necessary for normal app use)
// (Need to include "protolib/common/protoDebug.h" for this // (Need to include "common/protoDebug.h" for this
//SetDebugLevel(2); //SetDebugLevel(2);
// Uncomment to turn on debug NORM message tracing // Uncomment to turn on debug NORM message tracing
//NormSetMessageTrace(session, true); //NormSetMessageTrace(session, true);

View File

@ -71,7 +71,7 @@ int main(int argc, char* argv[])
// NOTE: These are some debugging routines available // NOTE: These are some debugging routines available
// (not necessary for normal app use) // (not necessary for normal app use)
// (Need to include "protolib/common/protoDebug.h" for this // (Need to include "common/protoDebug.h" for this
//SetDebugLevel(2); //SetDebugLevel(2);
// Uncomment to turn on debug NORM message tracing // Uncomment to turn on debug NORM message tracing
NormSetMessageTrace(session, true); NormSetMessageTrace(session, true);

View File

@ -48,7 +48,7 @@ int main(int argc, char* argv[])
// NOTE: These are debugging routines available // NOTE: These are debugging routines available
// (not necessary for normal app use) // (not necessary for normal app use)
// (Need to include "protolib/common/protoDebug.h" for this // (Need to include "common/protoDebug.h" for this
NormSetDebugLevel(3); NormSetDebugLevel(3);
// Uncomment to turn on debug NORM message tracing // Uncomment to turn on debug NORM message tracing
NormSetMessageTrace(session, true); NormSetMessageTrace(session, true);

View File

@ -39,7 +39,7 @@ int main(int argc, char** argv)
Win32InputHandler inputHandler; Win32InputHandler inputHandler;
inputHandler.Start(); inputHandler.Open();
while (true) while (true)
{ {
@ -51,7 +51,7 @@ int main(int argc, char** argv)
DWORD dwWritten; DWORD dwWritten;
BOOL fSuccess = WriteFile(hStdout, buffer, numBytes, &dwWritten, NULL); BOOL fSuccess = WriteFile(hStdout, buffer, numBytes, &dwWritten, NULL);
} }
inputHandler.Stop(); inputHandler.Close();
return 0; return 0;
} // end main() } // end main()

View File

@ -17,6 +17,12 @@ static inline int dirfd(DIR *dir) {return (dir->dd_fd);}
#endif // HAVE_DIRFD #endif // HAVE_DIRFD
#endif // if/else WIN32 #endif // if/else WIN32
#ifdef HAVE_FLOCK
#include <sys/file.h>
#elif defined(HAVE_LOCKF)
#include <unistd.h>
#endif
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,6 @@
// Assumes UDP packets in tcpdump trace file (pcap file) are // Assumes UDP packets in tcpdump trace file (pcap file) are
// MGEN packets and parses to build an MGEN log file // MGEN packets and parses to build an MGEN log file
#include <stdio.h> #include <stdio.h>
#include <pcap.h> #include <pcap.h>
#include <sys/socket.h> // for PF_ types (protocol family) #include <sys/socket.h> // for PF_ types (protocol family)
@ -64,8 +63,10 @@ int main(int argc, char* argv[])
if (NULL == pcapDevice) if (NULL == pcapDevice)
{ {
fprintf(stderr, "pcap2norm: pcap_fopen_offline() error: %s\n", pcapErrBuf); fprintf(stderr, "pcap2norm: pcap_fopen_offline() error: %s\n", pcapErrBuf);
if (stdin != infile) fclose(infile); if (stdin != infile)
if (stdout != outfile) fclose(outfile); fclose(infile);
if (stdout != outfile)
fclose(outfile);
return -1; return -1;
} }
@ -80,7 +81,8 @@ int main(int argc, char* argv[])
while (NULL != (pktData = pcap_next(pcapDevice, &hdr))) while (NULL != (pktData = pcap_next(pcapDevice, &hdr)))
{ {
unsigned int numBytes = maxBytes; unsigned int numBytes = maxBytes;
if (hdr.caplen < numBytes) numBytes = hdr.caplen; if (hdr.caplen < numBytes)
numBytes = hdr.caplen;
ProtoPktETH::Type ethType; ProtoPktETH::Type ethType;
unsigned int payloadLength; unsigned int payloadLength;
UINT32 *payloadPtr; UINT32 *payloadPtr;
@ -157,10 +159,12 @@ int main(int argc, char* argv[])
{ {
fprintf(stderr, "eth type = %d\n", ethType); fprintf(stderr, "eth type = %d\n", ethType);
} }
if (!srcAddr.IsValid()) continue; // wasn't an IP packet if (!srcAddr.IsValid())
continue; // wasn't an IP packet
ProtoPktUDP udpPkt; ProtoPktUDP udpPkt;
if (!udpPkt.InitFromPacket(ipPkt)) continue; // not a UDP packet if (!udpPkt.InitFromPacket(ipPkt))
continue; // not a UDP packet
NormMsg msg; NormMsg msg;
if (msg.CopyFromBuffer((const char *)udpPkt.GetPayload(), udpPkt.GetPayloadLength())) if (msg.CopyFromBuffer((const char *)udpPkt.GetPayload(), udpPkt.GetPayloadLength()))
@ -178,7 +182,6 @@ int main(int argc, char* argv[])
} // end main() } // end main()
static UINT8 lastFecId = 0; static UINT8 lastFecId = 0;
void NormTrace2(const struct timeval &currentTime, void NormTrace2(const struct timeval &currentTime,
@ -197,8 +200,7 @@ void NormTrace2(const struct timeval& currentTime,
"CMD", "CMD",
"NACK", "NACK",
"ACK", "ACK",
"REPORT" "REPORT"};
};
static const char *CMD_NAME[] = static const char *CMD_NAME[] =
{ {
"CMD(INVALID)", "CMD(INVALID)",
@ -208,15 +210,13 @@ void NormTrace2(const struct timeval& currentTime,
"CMD(CC)", "CMD(CC)",
"CMD(REPAIR_ADV)", "CMD(REPAIR_ADV)",
"CMD(ACK_REQ)", "CMD(ACK_REQ)",
"CMD(APP)" "CMD(APP)"};
};
static const char *REQ_NAME[] = static const char *REQ_NAME[] =
{ {
"INVALID", "INVALID",
"WATERMARK", "WATERMARK",
"RTT", "RTT",
"APP" "APP"};
};
NormMsg::Type msgType = msg.GetType(); NormMsg::Type msgType = msg.GetType();
UINT16 length = msg.GetLength(); UINT16 length = msg.GetLength();
@ -226,8 +226,6 @@ void NormTrace2(const struct timeval& currentTime,
srcAddr.GetHostString(src, 63); srcAddr.GetHostString(src, 63);
dstAddr.GetHostString(dst, 63); dstAddr.GetHostString(dst, 63);
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
struct tm timeStruct; struct tm timeStruct;
timeStruct.tm_hour = currentTime.tv_sec / 3600; timeStruct.tm_hour = currentTime.tv_sec / 3600;
@ -241,7 +239,6 @@ void NormTrace2(const struct timeval& currentTime,
struct tm *ct = gmtime(&secs); struct tm *ct = gmtime(&secs);
#endif // if/else _WIN32_WCE #endif // if/else _WIN32_WCE
PLOG(PL_ALWAYS, "trace>%02d:%02d:%02d.%06lu ", PLOG(PL_ALWAYS, "trace>%02d:%02d:%02d.%06lu ",
(int)ct->tm_hour, (int)ct->tm_min, (int)ct->tm_sec, (unsigned int)currentTime.tv_usec); (int)ct->tm_hour, (int)ct->tm_min, (int)ct->tm_sec, (unsigned int)currentTime.tv_usec);
PLOG(PL_ALWAYS, "src>%s/%hu dst>%s/%hu id>0x%08x ", src, srcAddr.GetPort(), dst, dstAddr.GetPort(), (UINT32)msg.GetSourceId()); PLOG(PL_ALWAYS, "src>%s/%hu dst>%s/%hu id>0x%08x ", src, srcAddr.GetPort(), dst, dstAddr.GetPort(), (UINT32)msg.GetSourceId());
@ -330,7 +327,8 @@ void NormTrace2(const struct timeval& currentTime,
PLOG(PL_ALWAYS, "ackers>"); PLOG(PL_ALWAYS, "ackers>");
for (UINT16 i = 0; i < nodeCount; i++) for (UINT16 i = 0; i < nodeCount; i++)
{ {
if (i > 0) PLOG(PL_ALWAYS, ","); if (i > 0)
PLOG(PL_ALWAYS, ",");
PLOG(PL_ALWAYS, "0x%08x", (UINT32)flush.GetAckingNodeId(i)); PLOG(PL_ALWAYS, "0x%08x", (UINT32)flush.GetAckingNodeId(i));
} }
PLOG(PL_ALWAYS, " "); PLOG(PL_ALWAYS, " ");
@ -408,4 +406,3 @@ void NormTrace2(const struct timeval& currentTime,
} }
PLOG(PL_ALWAYS, "len>%hu %s\n", length, clrFlag ? "(CLR)" : ""); PLOG(PL_ALWAYS, "len>%hu %s\n", length, clrFlag ? "(CLR)" : "");
} // end NormTrace2(); } // end NormTrace2();

View File

@ -38,7 +38,7 @@
*/ */
// Some portions of this code // Some portions of this code
// Copyright © 1996 Netscape Communications Corporation, // Copyright <EFBFBD> 1996 Netscape Communications Corporation,
// all rights reserved. // all rights reserved.
#include "normPostProcess.h" #include "normPostProcess.h"