Skip to content

Commit 5836f1a

Browse files
authored
Add how to build program "Hello PLCnext" (#19)
1 parent 3f8afb5 commit 5836f1a

File tree

6 files changed

+209
-0
lines changed

6 files changed

+209
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.vscode/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.*
2+
out
3+
bin*
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
project(hello_PLCnext)
4+
5+
if(NOT CMAKE_BUILD_TYPE)
6+
set(CMAKE_BUILD_TYPE Release)
7+
endif()
8+
9+
################# create target #######################################################
10+
11+
set (WILDCARD_SOURCE *.cpp)
12+
set (WILDCARD_HEADER *.h *.hpp *.hxx)
13+
14+
file(GLOB_RECURSE Headers src/${WILDCARD_HEADER})
15+
file(GLOB_RECURSE Sources src/${WILDCARD_SOURCE})
16+
add_executable(hello_PLCnext ${Headers} ${Sources})
17+
18+
#######################################################################################
19+
20+
################# project include-paths ###############################################
21+
22+
target_include_directories(hello_PLCnext
23+
PUBLIC
24+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
25+
26+
#######################################################################################
27+
28+
################# include arp cmake module path #######################################
29+
30+
list(INSERT CMAKE_MODULE_PATH 0 "${ARP_TOOLCHAIN_CMAKE_MODULE_PATH}")
31+
32+
#######################################################################################
33+
34+
################# set link options ####################################################
35+
# WARNING: Without --no-undefined the linker will not check, whether all necessary #
36+
# libraries are linked. When a library which is necessary is not linked, #
37+
# the firmware will crash and there will be NO indication why it crashed. #
38+
#######################################################################################
39+
40+
target_link_options(hello_PLCnext PRIVATE LINKER:--no-undefined)
41+
42+
#######################################################################################
43+
44+
################# add link targets ####################################################
45+
46+
find_package(ArpDevice REQUIRED)
47+
find_package(ArpProgramming REQUIRED)
48+
49+
target_link_libraries(hello_PLCnext PRIVATE ArpDevice ArpProgramming)
50+
51+
#######################################################################################
52+
53+
################# install ############################################################
54+
55+
string(REGEX REPLACE "^.*\\(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*$" "\\1" _ARP_SHORT_DEVICE_VERSION ${ARP_DEVICE_VERSION})
56+
install(TARGETS hello_PLCnext
57+
LIBRARY DESTINATION ${ARP_DEVICE}_${_ARP_SHORT_DEVICE_VERSION}/$<CONFIG>/lib
58+
ARCHIVE DESTINATION ${ARP_DEVICE}_${_ARP_SHORT_DEVICE_VERSION}/$<CONFIG>/lib
59+
RUNTIME DESTINATION ${ARP_DEVICE}_${_ARP_SHORT_DEVICE_VERSION}/$<CONFIG>/bin)
60+
unset(_ARP_SHORT_DEVICE_VERSION)
61+
62+
#######################################################################################
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"version": 3,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 21,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "default",
11+
"hidden": true,
12+
"displayName": "Default Config",
13+
"description": "Default build using Ninja generator",
14+
"generator": "Ninja",
15+
"toolchainFile": "$env{PLCNEXT_SDK_ROOT}/toolchain.cmake",
16+
"binaryDir": "${sourceDir}/bin/$env{ARP_DEVICE}_$env{ARP_DEVICE_VERSION}",
17+
"installDir": "${sourceDir}/deploy",
18+
"cacheVariables": {
19+
"ARP_DEVICE": "$env{ARP_DEVICE}",
20+
"ARP_DEVICE_VERSION": "$env{ARP_DEVICE_VERSION}",
21+
"CMAKE_BUILD_WITH_INSTALL_RPATH": true
22+
}
23+
},
24+
{
25+
"name": "build-windows-AXCF2152-2021.0.3.35554",
26+
"inherits": "default",
27+
"displayName": "AXCF2152-2021.0.3",
28+
"environment": {
29+
"ARP_DEVICE": "AXCF2152",
30+
"ARP_DEVICE_VERSION": "2021.0.3 LTS (21.0.3.35554)",
31+
"PLCNEXT_SDK_ROOT": "c:/CLI/SDKs/AXCF2152/2021_0"
32+
},
33+
"condition": {
34+
"type": "equals",
35+
"lhs": "${hostSystemName}",
36+
"rhs": "Windows"
37+
},
38+
"cacheVariables": {
39+
"CMAKE_TOOLCHAIN_FILE": {
40+
"value": "$env{PLCNEXT_SDK_ROOT}/toolchain.cmake",
41+
"type": "FILEPATH"
42+
}
43+
}
44+
},
45+
{
46+
"name": "build-linux-AXCF2152-2021.0.3.35554",
47+
"inherits": "default",
48+
"displayName": "AXCF2152-2021.0.3",
49+
"environment": {
50+
"ARP_DEVICE": "AXCF2152",
51+
"ARP_DEVICE_VERSION": "2021.0.3 LTS (21.0.3.35554)",
52+
"PLCNEXT_SDK_ROOT": "/opt/pxc/SDKs/AXCF2152/2021_0"
53+
},
54+
"condition": {
55+
"type": "equals",
56+
"lhs": "${hostSystemName}",
57+
"rhs": "Linux"
58+
}
59+
}
60+
],
61+
"buildPresets": [
62+
{
63+
"name": "build-windows-AXCF2152-2021.0.3.35554",
64+
"displayName": "AXCF2152-2021.0.3",
65+
"configurePreset": "build-windows-AXCF2152-2021.0.3.35554"
66+
}
67+
],
68+
"testPresets": [
69+
{
70+
"name": "default",
71+
"configurePreset": "default",
72+
"output": {
73+
"outputOnFailure": true
74+
},
75+
"execution": {
76+
"noTestsAction": "error",
77+
"stopOnFailure": true
78+
}
79+
}
80+
]
81+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
cout << "Hello PLCnext!" << endl;
8+
return 0;
9+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# How to build a simple "Hello PLCnext" application #
2+
3+
> Based on the official [documentation](https://github.com/PLCnext/SampleRuntime/blob/master/getting-started/Part-01/README.md).
4+
5+
## Using command line (pure **CMake**) ##
6+
7+
After cloning repository execute this steps inside `"HowTo build program Hello PLCnext\Hello-PLCnext"` working direcrory.
8+
9+
Configure:
10+
```sh
11+
cmake --preset=build-windows-AXCF2152-2021.0.3.35554 .
12+
```
13+
14+
Build:
15+
```sh
16+
cmake --build --preset=build-windows-AXCF2152-2021.0.3.35554 --target all
17+
```
18+
19+
Deploy:
20+
```sh
21+
cmake --build --preset=build-windows-AXCF2152-2021.0.3.35554 --target install
22+
```
23+
24+
In above commands the `build-windows-AXCF2152-2021.0.3.35554` preset name specifies build parameters on OS Windows for AXC 2152. It is stored in `"HowTo build program Hello PLCnext\Hello-PLCnext\CMakePresets.json"` file. Inside this file you can found parameters:
25+
26+
- The `PLCNEXT_SDK_ROOT` parameter specifies the full path to the root directory of the SDK.
27+
- The `ARP_DEVICE` and `ARP_DEVICE_VERSION` parameters should specify the SDK device and version.
28+
29+
You can change it, if necessary, to the SDK device, version and path of the SDK that you are using.
30+
31+
After you can find executable here:
32+
>deploy\AXCF2152_21.0.3.35554\Release\bin\hello_PLCnext
33+
34+
On **Linux OS** use `build-linux-AXCF2152-2021.0.3.35554` preset name.
35+
36+
## Using MS Visual Code ##
37+
38+
Open directory `"HowTo build program Hello PLCnext\Hello-PLCnext"` in MS Visual Code.
39+
40+
Thus you have opened CMake-based project. Set auto-suggested configuration and build the application.
41+
42+
## Using MS Visual Studio 2019 Community (Windows OS) ##
43+
44+
Open directory `"HowTo build program Hello PLCnext\Hello-PLCnext"` in MS Visual Studio.
45+
46+
Thus you have opened CMake-based project. Set auto-suggested configuration and build the application (press **F7** to start build process).
47+
48+
## Using other IDE which support CMake presets ##
49+
50+
Open directory `"HowTo build program Hello PLCnext\Hello-PLCnext"` in IDE.
51+
52+
Thus you have opened CMake-based project. Set auto-suggested configuration and build the application.

0 commit comments

Comments
 (0)