Skip to content

Commit 63b22b6

Browse files
authored
Merge pull request #37 from rodneyp290/cmake-clean
CMake Build System
2 parents 751e38f + f57ffff commit 63b22b6

File tree

10 files changed

+315
-49
lines changed

10 files changed

+315
-49
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ Makefile
77
*.suo
88
obj/
99
Build/
10+
build/
11+
CMakeCache.txt
12+
*.dir/
13+
CMakeFiles
14+
cmake_install.cmake
15+
CPackConfig.cmake
16+
CPackSourceConfig.cmake

.travis.yml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
language: cpp
22

3+
addons:
4+
apt:
5+
packages:
6+
- cmake
7+
- libsdl2-dev
8+
- libsdl2-net-dev
9+
- rpm
10+
311
install:
4-
# Download and build premake5 from source; the Travis environment doesn't have the right version of glibc6 for the prebuilt binaries to work.
5-
- wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha6/premake-5.0.0-alpha6-src.zip -O premake.zip
6-
- unzip premake.zip
7-
- cd premake-5.0.0-alpha6/build/gmake.unix
8-
- make config=release
9-
- cd ../../..
10-
- mv premake-5.0.0-alpha6/bin/release/premake5 premake5
11-
# Download and build both SDL2 from source
12-
- wget http://libsdl.org/release/SDL2-2.0.9.tar.gz
13-
- tar -xvf SDL2-2.0.9.tar.gz
14-
- pushd SDL2-2.0.9/
15-
- ./configure --prefix=/usr && make && sudo make install
16-
- popd
17-
# Run sdl2-config for debugging -- protentially remove this
18-
- sdl2-config --cflags --libs
19-
# Download and build both SDL2_net from source
20-
- wget https://www.libsdl.org/projects/SDL_net/release/SDL2_net-2.0.1.tar.gz
21-
- tar -xvf SDL2_net-2.0.1.tar.gz
22-
- pushd SDL2_net-2.0.1/
23-
- ./configure --prefix=/usr && make && sudo make install
24-
- popd
2512

2613

2714
# Run premake to generate makefiles.
2815
before_script:
29-
- ./premake5 gmake
16+
- mkdir build
17+
- pushd build
18+
- cmake .. -DCMAKE_INSTALL_PREFIX=./install
19+
- popd
3020

3121
script:
32-
- make config=release
22+
- pushd build
23+
- make install
24+
- make package
25+
- popd

CMakeLists.txt

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
cmake_minimum_required(VERSION 3.2)
2+
project(OpenDIS)
3+
4+
## Libraries
5+
6+
# Add src/ to the include directories
7+
include_directories(src)
8+
9+
# create list of DIS6 source files
10+
file(GLOB DIS6_SOURCES
11+
"src/dis6/*.cpp"
12+
"src/utils/*.cpp"
13+
)
14+
# Define ExampleSender Executable
15+
add_library(OpenDIS6 SHARED ${DIS6_SOURCES})
16+
# Add compile definition EXPORT_LIBRARY for DIS6 msLibMacro.h
17+
target_compile_definitions(OpenDIS6 PRIVATE EXPORT_LIBRARY)
18+
19+
# create list of DIS7 source files
20+
file(GLOB DIS7_SOURCES
21+
"src/dis7/*.cpp"
22+
"src/utils/*.cpp"
23+
)
24+
# Define ExampleSender Executable
25+
add_library(OpenDIS7 SHARED ${DIS7_SOURCES})
26+
# Add compile definition EXPORT_LIBRARY for DIS7 msLibMacro.h
27+
target_compile_definitions(OpenDIS7 PRIVATE EXPORT_LIBRARY)
28+
29+
30+
## Example Programs
31+
include_directories(.)
32+
33+
# if Windows add M_PI definition
34+
# - issues occurred during testing in Visual Studio
35+
if (WIN32)
36+
add_definitions(/DM_PI=3.14159265358979323846)
37+
endif (WIN32)
38+
39+
# create list of ExampleSender source files
40+
file(GLOB EX_SENDER_SOURCES
41+
"examples/main.cpp"
42+
"examples/Connection.cpp"
43+
"examples/Utils.cpp"
44+
"examples/Timer.cpp"
45+
)
46+
47+
# Define ExampleSender Executable
48+
add_executable(ExampleSender ${EX_SENDER_SOURCES})
49+
# Link OpenDIS into ExampleSender
50+
target_link_libraries(ExampleSender PRIVATE OpenDIS6)
51+
target_link_libraries(ExampleSender PRIVATE SDL2main SDL2 SDL2_net)
52+
53+
# create list of ExampleReceiver source files
54+
file(GLOB EX_RECEIVER_SOURCES
55+
"examples/main_receive.cpp"
56+
"examples/Connection.cpp"
57+
"examples/Utils.cpp"
58+
"examples/Timer.cpp"
59+
"examples/EntityStatePduProcessor.cpp"
60+
)
61+
62+
# Define ExampleReciever Executable
63+
add_executable(ExampleReceiver ${EX_RECEIVER_SOURCES})
64+
# Link OpenDIS into ExampleReceiver
65+
target_link_libraries(ExampleReceiver PRIVATE OpenDIS6)
66+
target_link_libraries(ExampleReceiver PRIVATE SDL2main SDL2 SDL2_net)
67+
68+
# Configuring SDL2
69+
#--------------------------------------------------------------------------------------
70+
71+
# If SDL_INC_DIR declared (by user via -D flag)
72+
if(SDL_INC_DIR)
73+
# Inform the user we will use the their specified SDL_INC_DIR
74+
message("Using SDL2 include directory defined with -DSDL_INC_DIR")
75+
message("\tvalue: ${SDL_INC_DIR}")
76+
# Add SDL_INC_DIR to the include directories for both exampe apps
77+
target_include_directories(ExampleSender PUBLIC ${SDL_INC_DIR})
78+
target_include_directories(ExampleReceiver PUBLIC ${SDL_INC_DIR})
79+
else(SDL_INC_DIR)
80+
# Otherwise, try get SDL2 Compiler Flags from sdl2-config
81+
execute_process(
82+
COMMAND sdl2-config --cflags
83+
RESULT_VARIABLE SDL_CERR
84+
OUTPUT_VARIABLE SDL_CFLAGS
85+
OUTPUT_STRIP_TRAILING_WHITESPACE
86+
)
87+
# if sdl2-config errors
88+
if(SDL_CERR)
89+
# warn user that they may have to define the SDL2 include
90+
# directory with the -DSDL_INC_DIR flag
91+
# Most linux systems will probably be fine
92+
message(WARNING "Unable to detect SDL2 include flags")
93+
message("You may need to specify the SDL include manually")
94+
message(" with -DSDL_INC_DIR=<SDL2 include path>")
95+
else(SDL_CERR)
96+
# otherwise split the output of sdl2-config and add to compiler flags to examples
97+
if(WIN32)
98+
separate_arguments(SDL_CFLAGS UNIX_COMMAND "${SDL_CFLAGS}")
99+
else(WIN32)
100+
separate_arguments(SDL_CFLAGS WINDOWS_COMMAND "${SDL_CFLAGS}")
101+
endif(WIN32)
102+
target_compile_options(ExampleSender PRIVATE "${SDL_CFLAGS}")
103+
target_compile_options(ExampleReceiver PRIVATE "${SDL_CFLAGS}")
104+
endif(SDL_CERR)
105+
endif(SDL_INC_DIR)
106+
107+
# If SDL_LIB_DIR declared (by user via -D flag)
108+
if(SDL_LIB_DIR)
109+
message("Using SDL2 include directory defined with -DSDL_LIB_DIR")
110+
message("\tvalue: ${SDL_LIB_DIR}")
111+
target_link_directories(ExampleSender PUBLIC ${SDL_LIB_DIR})
112+
target_link_directories(ExampleReceiver PUBLIC ${SDL_LIB_DIR})
113+
else(SDL_LIB_DIR)
114+
# Otherwise, try get SDL2 Library Flags from sdl2-config
115+
execute_process(
116+
COMMAND sdl2-config --libs
117+
RESULT_VARIABLE SDL_LERR
118+
OUTPUT_VARIABLE SDL_LFLAGS
119+
OUTPUT_STRIP_TRAILING_WHITESPACE
120+
)
121+
# if sdl2-config errors
122+
if(SDL_LERR)
123+
# warn user that they may have to define the SDL2 include
124+
# directory with the -DSDL_LIB_DIR flag
125+
# Most linux systems will probably be fine
126+
message(WARNING "Unable to detect SDL2 library flags using defaults")
127+
message("You may need to specify the SDL library manually with")
128+
message(" -DSDL_LIB_DIR=<SDL2 include path>, especially for Windows users")
129+
else(SDL_LERR)
130+
# otherwise split the output of sdl2-config and add to library flags to examples
131+
if(WIN32)
132+
separate_arguments(SDL_LFLAGS UNIX_COMMAND "${SDL_LFLAGS}")
133+
else(WIN32)
134+
separate_arguments(SDL_LFLAGS WINDOWS_COMMAND "${SDL_LFLAGS}")
135+
endif(WIN32)
136+
target_link_libraries(ExampleSender PRIVATE "${SDL_LFLAGS}")
137+
target_link_libraries(ExampleReceiver PRIVATE "${SDL_LFLAGS}")
138+
endif(SDL_LERR)
139+
endif(SDL_LIB_DIR)
140+
141+
#--------------------------------------------------------------------------------------
142+
143+
# Configure install target (i.e. what files to install)
144+
install(TARGETS OpenDIS6 OpenDIS7 DESTINATION "lib")
145+
install(TARGETS ExampleReceiver ExampleSender DESTINATION "bin")
146+
install(DIRECTORY src/ DESTINATION "include"
147+
FILES_MATCHING PATTERN "*.h"
148+
)
149+
150+
# configure package target (i.e. Package Types, and meta data)
151+
set(CPACK_GENERATOR "DEB" "RPM" "TXZ" "TGZ")
152+
set(CPACK_PACKAGE_VERSION 1.0.0)
153+
set(CPACK_PACKAGE_NAME "OpenDis")
154+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The open DIS cpp library")
155+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}")
156+
set(CPACK_PACKAGE_RPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/_CPack_Packages/Linux/RPM")
157+
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Leif Gruenwoldt <[email protected]>")
158+
set(CPACK_PACKAGE_PACKAGER $ENV{USER})
159+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The open DIS cpp library")
160+
include(CPack)

README.md

Lines changed: 120 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,136 @@ Initially generated with [xmlpg](https://github.com/open-dis/xmlpg).
77

88
## Building Open DIS
99

10-
* [premake5](http://premake.github.io/) is required to build the platform specific projects. Download it and make sure it's available on your path, or specify the path to it.
10+
* [CMake](http://cmake.org/) is required to build the platform specific projects.
11+
It can be downloaded and installed from http://cmake.org/
1112

12-
* SDL2 and SDL2_net are required libraries to compile the examples. See the [.travis.yml](.travis.yml) for more details on setting up a build environment.
13+
* SDL2 and SDL2_net are required libraries to compile the examples.
14+
These can usually be install via Linux package managers.
15+
More details, and instructions for Windows are included [below](#SDL2-and-SDL2_net-Install-Instructions).
1316

14-
### Linux
17+
**NOTE:** Windows users will need to either add the DLL folders to their path, or copy the DLLs to the output directory (`Debug`).
1518

19+
### Linux / GNU Makefiles
20+
21+
1. Run `mkdir build`
22+
1. Run `cd build`
23+
1. Run `cmake ..`
24+
1. Optionally, `-DCMAKE_INSTALL_PREFIX=<custom-path-to-install>` to set a custom directory to install the bin, include, and lib output directories.
25+
1. Run `make` - this will output the libOpenDIS6.so, and libOpenDIS7.so libraries in the build directory along with the Example Applications.
26+
1. The below steps are optional
27+
1. Run `make package` to build Linux package files. Currently this will produce a Red Hat RPM package, Debian DEB package, and 2 compressed tarball (XZ, GZ).
28+
1. Run `make install` to install bin, lib, and dir, into `CMAKE_INSTALL_PREFIX`
29+
WARNING: `CMAKE_INSTALL_PREFIX` default can to somewhere `/usr/local/`, if not specified with the `-D` flag as shown in Step 3.1.
30+
If you're unsure where to install, and want to keep your `/usr/local/` directory clean, run `cmake .. -DCMAKE_INSTALL_PREFIX=./install`.
31+
This will cause `make install` to create a local install directory, from which you can move files elsewhere at a later date.
32+
33+
#### Windows with Visual Studio
34+
1. Open `CMake (cmake-gui)` via the the start menu.
35+
2. Enter the open-dis-cpp directory path into the Source and Build fields.
36+
3. Click the `+ Add Entry` button and enter the following details:
37+
Name: `SDL_INC_DIR`
38+
Type: `PATH`
39+
Value: `<SDL2-install-folder>/include`
40+
(if you follow the below [SDL2 Windows Install Instruction](#Windows-Install-Instructions) this will be `C:/SDL2/include`)
41+
3. Click the `+ Add Entry` button and enter the following details:
42+
Name: `SDL_LIB_DIR`
43+
Type: `PATH`
44+
Value: `<SDL2-install-folder>/lib/x64` (64 bit) or `<SDL2-install-folder>/lib/x86` (32 bit)
45+
(if you follow the below [SDL2 Windows Install Instruction](#Windows-Install-Instructions) this will be `C:/SDL2/lib/x64`)
46+
4. Click Configure and follow the prompts, selecting the correct generator (i.e. Visual Studio version).
47+
5. Click Generate
48+
6. Click Open Project - This should open the generates solution file in Visual Studio
49+
7. Build the Solution (`Ctrl + Shift + B`)
50+
51+
These steps were tested with Visual Studio 16 2019 (Community Edition).
52+
Currently, only OpenDIS 6 and the Example Applications compile.
53+
The library and executable files are output to a `Debug` directory.
54+
55+
To run the executables, either the value of the `SDL_LIB_DIR` variable should be added to your path,
56+
or `SDL2.dll` and `SDL2_net.dll` need to be copied to the `Debug` directory.
57+
58+
### Cleaning CMake files
59+
60+
To quickly clean up CMake output files, use `git clean -xdf`.
61+
**Note:** Use with care if you are actually developing open-dis-cpp, as `git clean` removes untracked files.
62+
63+
### Old Pre-make build instructions
64+
65+
* [premake5](http://premake.github.io/) is required to build the platform specific projects. Download it and make sure it's available on your path, or specify the path to it.
66+
67+
#### Linux / GNU Makefiles
1668
1. Run `premake5 gmake`
1769
1. Run `make config=release`
1870

19-
### Windows
2071

72+
#### Windows with Visual Studio 2015
2173
1. Run `premake5 vs2015`
2274
1. Open the solution and build.
2375

2476
## Developer Docs
2577

2678
The latest doxygen docs for the Open DIS master branch can be found [here](https://codedocs.xyz/open-dis/open-dis-cpp/).
79+
80+
## SDL2 and SDL2_net Install Instructions
81+
82+
### Linux Package Managers
83+
84+
Arch: ```sudo pacman -S sdl2 sdl2_net```
85+
86+
Fedora: ```sudo dnf install SDL2-devel SDL2_net-devel```
87+
88+
Ubuntu: ```sudo apt-get install libsdl2-dev libsdl2-net-dev```
89+
90+
If you're unable to install the correct packages, try [installing from source](#POSIX-Source-Installation)
91+
92+
### Windows Install Instructions
93+
94+
These are the installation steps that have been tested with open-dis-cpp, however there are other methods for installation.
95+
Experienced users should feel free to customise their install.
96+
97+
#### (Core) SDL2 Instructions
98+
99+
1. Navigate to the SDL2 [Download](https://www.libsdl.org/download-2.0.php) page, and download the latest Development Libraries.
100+
101+
Alternatively, the version tested with open-dis-cpp, 2.0.12-VC, can be downloaded from this [direct link](https://www.libsdl.org/release/SDL2-devel-2.0.12-VC.zip).
102+
103+
2. Extract the SDL2-devel-2.0.12-VC.zip file directly to your `C:\`.
104+
3. Rename the resulting `SDL2-2.0.12` folder to `SDL2`.
105+
4. Add `C:\SDL2\lib\x64` to your System Path for 64-bit systems,
106+
or add `C:\SDL2\lib\x86` for 32-bit systems.
107+
108+
#### SDL2_net Instructions
109+
110+
1. Navigate to the SDL2_net [project](https://www.libsdl.org/projects/SDL_net/) page, and download the latest Development Libraries.
111+
112+
Alternatively, the version tested with open-dis-cpp, 2.0.1-VC, can be downloaded from this [direct link](https://www.libsdl.org/projects/SDL_net/release/SDL2_net-devel-2.0.1-VC.zip).
113+
114+
2. Extract the SDL2-devel-2.0.12-VC.zip
115+
3. Copy the `include` and `lib` directories from the resulting folder into you `C:\SDL2\` folder
116+
117+
### POSIX Source Installation
118+
119+
#### (Core) SDL2
120+
Run the following commands:
121+
1. `wget http://libsdl.org/release/SDL2-2.0.12.tar.gz`
122+
123+
Or, Download via your favourite web browser.
124+
125+
**NOTE:** check the [download](https://www.libsdl.org/download-2.0.php) page for new releases
126+
127+
2. `tar -xvf SDL2-2.0.9.tar.gz`
128+
3. `pushd SDL2-2.0.9/`
129+
4. `./configure --prefix=/usr && make && sudo make install`
130+
5. `popd`
131+
132+
#### SDL2_net
133+
1. `wget https://www.libsdl.org/projects/SDL_net/release/SDL2_net-2.0.1.tar.gz`
134+
135+
Or, Download via your favourite web browser.
136+
137+
**NOTE:** check [https://www.libsdl.org/projects/SDL_net](project) page for new releases
138+
139+
2. `tar -xvf SDL2_net-2.0.1.tar.gz`
140+
3. `pushd SDL2_net-2.0.1/`
141+
4. `./configure --prefix=/usr && make && sudo make install`
142+
5. `popd`

examples/Connection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <sstream>
55
#include <cstring>
66

7-
#include <SDL2/SDL.h>
8-
#include <SDL2/SDL_net.h>
7+
#include <SDL.h>
8+
#include <SDL_net.h>
99

1010
using namespace Example;
1111

examples/Connection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <string> // for param
55
#include <cstddef> // for size_t definition
66

7-
#include <SDL2/SDL.h>
8-
#include <SDL2/SDL_net.h>
7+
#include <SDL.h>
8+
#include <SDL_net.h>
99

1010

1111
namespace Example

0 commit comments

Comments
 (0)