Skip to content

Commit 483fc21

Browse files
committed
Add example.
1 parent 28cfa3e commit 483fc21

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(cppp-platform VERSION 1.3.0)
33

4+
option(BUILD_EXAMPLE "Build example" OFF)
5+
46
# Read source files
57
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/architectures.h" ARCHITECTURES)
68
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/compilers.h" COMPILERS)
79
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/languagestandards.h" LANGUAGESTANDARDS)
810
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/platforms.h" PLATFORMS)
911

1012
# Genetate header
11-
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/cppp/cppp-platform.h.in" "${output_includedir}/cppp/cppp-platform.h")
13+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/cppp/cppp-platform.h.in" "${CMAKE_BINARY_DIR}/include/cppp/cppp-platform.h")
14+
15+
# Build example
16+
if(BUILD_EXAMPLE)
17+
add_executable(example "${CMAKE_CURRENT_SOURCE_DIR}/src/example.c")
18+
target_include_directories(example PRIVATE "${CMAKE_BINARY_DIR}/include")
19+
endif()
20+
1221

1322
# Install
1423
# Includes
1524
# PERMISSIONS 0644
16-
install(FILES "${output_includedir}/cppp/cppp-platform.h"
17-
DESTINATION "${install_includedir}"
25+
install(FILES "${CMAKE_BINARY_DIR}/include/cppp/cppp-platform.h"
26+
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
1827
RENAME "cppp/cppp-platform.h"
1928
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ )

README.md

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,22 @@
1-
# Introduction
2-
cppp-platform is a portable platform check library for C+++.
1+
# cppp-platfrom -- Portable platform check library
2+
3+
## Build
4+
5+
### Dependencies
36

4-
# Build
5-
## Dependence
67
+ CMake (version >= 3.10)
78

8-
## Command
9+
### Command
10+
911
```shell
1012
mkdir build
1113
cd build
1214
cmake .. -DCMAKE_INSTALL_PREFIX=[[PREFIX]]
15+
# If you want to build the example, add -DBUILD_EXAMPLE=ON
1316
cmake --build .
1417
cmake --install .
1518
```
1619

17-
# Example
18-
After install, you can use cppp-platform in C/C++
19-
```c
20-
#include <cppp/cppp-platform.h>
21-
#include <stdio.h>
22-
int main()
23-
{
24-
if(__has_windows__)
25-
{
26-
printf("Compile in Windows!\n");
27-
}
28-
else
29-
{
30-
printf("Compile non-Windows!\n");
31-
}
32-
printf("Target arch:%s\n",__arch__);
33-
printf("Target arch name:%s\n",__arch_name__);
34-
printf("Pointer width:%d\n",__POINTER_WIDTH__);
35-
}
36-
```
20+
## Documentation
3721

38-
# Manual
39-
[User Manual](doc/doc.md)
22+
[Documentation](doc/doc.md)

src/example.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <cppp/cppp-platform.h>
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
6+
int main(int argc, char *argv[])
7+
{
8+
if (argc != 1)
9+
{
10+
fprintf(stderr, "Usage: %s\n", argv[0]);
11+
return EXIT_FAILURE;
12+
}
13+
14+
if (__has_windows__)
15+
{
16+
printf("Running on Windows!\n");
17+
}
18+
else
19+
{
20+
printf("Running non-Windows!\n");
21+
}
22+
printf("Target architcture id: %d\n", __arch__);
23+
printf("Target arch name: %s\n", __arch_name__);
24+
printf("Pointer width: %d\n", __POINTER_WIDTH__);
25+
26+
return EXIT_SUCCESS;
27+
}

0 commit comments

Comments
 (0)