Skip to content

Commit f6d2f02

Browse files
committed
msvc: fix build for windows compiler cl.exe
Signed-off-by: junka <[email protected]>
1 parent 69f6dae commit f6d2f02

20 files changed

+1743
-151
lines changed

.github/workflows/cmake.yml

+104-41
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,111 @@ name: CMake
22

33
on: [push]
44

5-
env:
6-
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
7-
BUILD_TYPE: Release
8-
95
jobs:
10-
build:
11-
# The CMake configure and build commands are platform agnostic and should work equally
12-
# well on Windows or Mac. You can convert this to a matrix build if you need
13-
# cross-platform coverage.
14-
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
6+
build_on_ubuntu_gcc:
157
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- name: Install Pybind11 ubuntu
12+
run: sudo apt install python3-pybind11
13+
14+
- name: cmake
15+
run: >
16+
cmake -B ${{ github.workspace }}/build
17+
-DCMAKE_BUILD_TYPE=Release
18+
-DCMAKE_C_COMPILER=gcc
19+
-DCMAKE_CXX_COMPILER=g++
20+
-S ${{github.workspace}}
21+
22+
- name: Build
23+
run: cmake --build ${{ github.workspace }}/build --config Release
24+
25+
- name: Test
26+
working-directory: ${{ github.workspace }}/build
27+
shell: bash
28+
run: ctest --build-config Release
29+
30+
build_on_ubuntu_clang:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v3
1634

35+
- name: Install Pybind11 ubuntu
36+
run: sudo apt install python3-pybind11
37+
38+
- name: cmake
39+
# Some projects don't allow in-source building, so create a separate build directory
40+
# We'll use this as our working directory for all subsequent commands
41+
run: >
42+
cmake -B ${{ github.workspace }}/build
43+
-DCMAKE_BUILD_TYPE=Release
44+
-DCMAKE_C_COMPILER=clang
45+
-DCMAKE_CXX_COMPILER=clang++
46+
-S ${{github.workspace}}
47+
48+
- name: Build
49+
# Execute the build. You can specify a specific target with "--target <NAME>"
50+
run: cmake --build ${{ github.workspace }}/build --config Release
51+
52+
- name: Test
53+
working-directory: ${{ github.workspace }}/build
54+
shell: bash
55+
run: ctest --build-config Release
56+
57+
build_on_macos_clang:
58+
runs-on: macos-latest
1759
steps:
18-
- uses: actions/checkout@v2
19-
20-
- name: Install Pybind11
21-
run: sudo apt install python3-pybind11
22-
23-
- name: Create Build Environment
24-
# Some projects don't allow in-source building, so create a separate build directory
25-
# We'll use this as our working directory for all subsequent commands
26-
run: cmake -E make_directory ${{github.workspace}}/build
27-
28-
- name: Configure CMake
29-
# Use a bash shell so we can use the same syntax for environment variable
30-
# access regardless of the host operating system
31-
shell: bash
32-
working-directory: ${{github.workspace}}/build
33-
# Note the current convention is to use the -S and -B options here to specify source
34-
# and build directories, but this is only available with CMake 3.13 and higher.
35-
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
36-
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
37-
38-
- name: Build
39-
working-directory: ${{github.workspace}}/build
40-
shell: bash
41-
# Execute the build. You can specify a specific target with "--target <NAME>"
42-
run: cmake --build . --config $BUILD_TYPE
43-
44-
- name: Test
45-
working-directory: ${{github.workspace}}/build
46-
shell: bash
47-
# Execute tests defined by the CMake configuration.
48-
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
49-
run: ctest -C $BUILD_TYPE
60+
- uses: actions/checkout@v3
61+
62+
- name: Install Pybind11 macos
63+
run: brew install pybind11
64+
65+
- name: cmake
66+
run: >
67+
cmake -B ${{ github.workspace }}/build
68+
-DCMAKE_BUILD_TYPE=Release
69+
-DCMAKE_C_COMPILER=clang
70+
-DCMAKE_CXX_COMPILER=clang++
71+
-S ${{github.workspace}}
72+
73+
- name: Build
74+
run: cmake --build ${{ github.workspace }}/build --config Release
75+
76+
- name: Test
77+
working-directory: ${{ github.workspace }}/build
78+
shell: bash
79+
run: ctest --build-config Release
80+
81+
build_on_windows_cl:
82+
runs-on: windows-latest
83+
steps:
84+
- uses: actions/checkout@v3
85+
86+
- name: Install Pybind11 windows
87+
run: >
88+
git clone https://github.com/Microsoft/vcpkg.git &&
89+
cd vcpkg &&
90+
.\bootstrap-vcpkg.bat &&
91+
.\vcpkg integrate install &&
92+
vcpkg install pybind11
93+
94+
- name: cmake
95+
# Some projects don't allow in-source building, so create a separate build directory
96+
# We'll use this as our working directory for all subsequent commands
97+
run: >
98+
cmake -B ${{ github.workspace }}/build
99+
-DCMAKE_BUILD_TYPE=Release
100+
-DCMAKE_C_COMPILER=cl
101+
-DCMAKE_CXX_COMPILER=cl
102+
-S ${{github.workspace}}
103+
104+
- name: Build
105+
# Execute the build. You can specify a specific target with "--target <NAME>"
106+
run: cmake --build ${{ github.workspace }}/build --config Release
107+
108+
- name: Test
109+
working-directory: ${{ github.workspace }}/build
110+
shell: bash
111+
run: ctest --build-config Release
112+

CMakeLists.txt

+13-5
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,29 @@ set(CMAKE_CXX_STANDARD 11)
1010
# SET(CMAKE_C_COMPILER "/usr/local/opt/llvm/bin/clang")
1111
# SET(CMAKE_CXX_COMPILER "/usr/local/opt/llvm/bin/clang++")
1212

13-
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -Wfatal-errors -Wstrict-prototypes -Wshadow -Wno-unused-parameter")
14-
13+
IF (WIN32)
14+
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
15+
ELSE()
16+
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -Wfatal-errors -Wstrict-prototypes -Wshadow -Wno-unused-parameter")
17+
ENDIF()
1518

1619
IF(${CMAKE_BUILD_TYPE} MATCHES "debug")
1720
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")
1821
add_compile_options(-fno-omit-frame-pointer -fmacro-backtrace-limit=0)
1922
add_compile_options(-fsanitize=address -fsanitize=leak -fsanitize-recover=all)
2023
add_link_options(-fsanitize=address -fsanitize=leak -fsanitize-recover=all)
24+
ELSE()
25+
IF (WIN32)
26+
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Od")
2127
ELSE()
2228
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
2329
ENDIF()
30+
ENDIF()
2431

2532
ADD_EXECUTABLE(tsanalyze ${SRC_LIST})
2633

27-
find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
28-
find_package(pybind11 REQUIRED)
34+
#find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
35+
#find_package(pybind11 REQUIRED)
36+
#python3 -m pybind11 --includes
2937

30-
pybind11_add_module(tsana ./pybind/binding.cpp ${SRC_LIST})
38+
#pybind11_add_module(tsana ./pybind/binding.cpp ${SRC_LIST})

Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
AUTOMAKE_OPTIONS = foreign subdir-objects
22
bin_PROGRAMS = tsanalyze
3-
tsanalyze_SOURCES = src/main.c src/ts.c src/pes.c src/filter.c src/io.c \
3+
tsanalyze_SOURCES = src/main.c src/ts.c src/pes.c src/filter.c src/tsio.c \
44
src/ps.c src/crc32.c src/fileio.c src/descriptor.c \
55
src/table.c src/utils.c src/udp.c src/options.c src/result.c \
6-
src/scte.c src/subtitle.c src/teletext.c
6+
src/scte.c src/subtitle.c src/teletext.c src/win_getopt.c
77
tsanalyze_CPPFLAGS = -I$(top_srcdir)/include/
88

99
AM_CFLAGS = -D_GNU_SOURCE -std=c11 -W -Wall -Wfatal-errors -Wstrict-prototypes -Wshadow -Wno-unused-parameter -fno-omit-frame-pointer

include/comm.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
extern "C" {
66
#endif
77

8+
#ifndef _MSC_VER
89
#define likely(x) __builtin_expect(!!(x), 1)
910
#define unlikely(x) __builtin_expect(!!(x), 0)
11+
#else
12+
#define likely(x) !!(x)
13+
#define unlikely(x) !!(x)
14+
#endif
1015

1116
#define stringify(x) #x
1217

@@ -22,13 +27,20 @@ extern "C" {
2227
#define container_of(item, type, member) ((type *)((char *)item - (char *)(&((type *)0)->member)))
2328
#endif
2429

25-
#if HAVE_TYPEOF
30+
//For msvc cl.exe see https://learn.microsoft.com/zh-cn/cpp/c-language/typeof-c?view=msvc-170
31+
// see https://learn.microsoft.com/zh-cn/cpp/overview/compiler-versions?view=msvc-170
32+
33+
#if _MSC_VER >= 1939
34+
#define typeof(x) __typeof__(x)
35+
#endif
36+
37+
#if (defined HAVE_TYPEOF) || (_MSC_VER >= 1939)
2638
#define container_of_var(member_ptr, container_var, member) container_of(member_ptr, typeof(*container_var), member)
2739
#else
2840
#define container_of_var(member_ptr, container_var, member) \
2941
((void *)((char *)(member_ptr) - container_off_var(container_var, member)))
3042
#endif
31-
#if HAVE_TYPEOF
43+
#if (defined HAVE_TYPEOF) || (_MSC_VER >= 1939)
3244
#define container_off_var(var, member) container_off(typeof(*var), member)
3345
#else
3446
#define container_off_var(var, member) ((const char *)&(var)->member - (const char *)(var))

include/descriptor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ foreach_enum_descriptor
582582
#undef __m1
583583
#undef __m
584584

585-
extern struct descriptor_ops des_ops[];
585+
extern struct descriptor_ops des_ops[256];
586586

587587
/* dump function macros*/
588588
#define __m(type, name, bits) DUMP_MEMBER(lv, dr, type, name);

include/dvb/descriptor.h

+4
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,11 @@ struct crid {
899899
union {
900900
struct {
901901
uint8_t length;
902+
#ifdef _MSC_VER
903+
uint8_t byte[1];
904+
#else
902905
uint8_t byte[0];
906+
#endif
903907
};
904908
uint16_t ref;
905909
};

include/scte/descriptor.h

+4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ struct splice_desciptor {
4545
uint8_t splice_descriptor_tag;
4646
uint8_t descriptor_length;
4747
uint32_t identifier;
48+
#ifdef _MSC_VER
49+
uint8_t private_byte[1];
50+
#else
4851
uint8_t private_byte[0];
52+
#endif
4953
};
5054

5155
#define foreach_avail_member \

include/subtitle.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ struct segment_header {
2727
uint8_t segment_type;
2828
uint16_t page_id;
2929
uint16_t segment_length;
30-
uint8_t data[0];
30+
#ifdef _MSC_VER
31+
uint8_t data[1];
32+
#else
33+
uint8_t data[0];
34+
#endif
3135
};
3236

3337
/* Table 8-1 in EN 300743 */

include/table.h

+4
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,11 @@ typedef struct
391391
uint16_t reserved_future_use : 1;
392392
uint16_t reserved : 2;
393393
uint16_t section_length : 12;
394+
#ifdef _MSC_VER
395+
uint8_t data_byte[1];
396+
#else
394397
uint8_t data_byte[0];
398+
#endif
395399
} st_t;
396400

397401
typedef struct
+48-46
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
1-
#ifndef _IO_H_
2-
#define _IO_H_
3-
4-
#include <stddef.h>
5-
6-
#ifdef __cplusplus
7-
extern "C" {
8-
#endif
9-
10-
struct io_ops
11-
{
12-
int type;
13-
int fd;
14-
int block_size;
15-
size_t total_size;
16-
size_t offset;
17-
unsigned char *ptr;
18-
int (* open)(const char *filename);
19-
int (* read)(void **ptr, size_t *len);
20-
int (* close)(void);
21-
int (* end)(void);
22-
int (* wip)(void); /* tell us the process percentage */
23-
};
24-
25-
typedef enum {
26-
IO_FILE = 0,
27-
IO_UDP = 1,
28-
} io_enum;
29-
30-
struct io_ops *lookup_io_ops(int type);
31-
32-
int register_io_ops(struct io_ops *ops);
33-
34-
int unregister_io_ops(struct io_ops *ops);
35-
36-
#define REGISTER_IO_OPS(nm, x) \
37-
static void __attribute__((constructor)) register_io_ops_##nm(void) \
38-
{ \
39-
register_io_ops(x); \
40-
}
41-
42-
#ifdef __cplusplus
43-
}
44-
#endif
45-
46-
#endif
1+
#ifndef _TSIO_H_
2+
#define _TSIO_H_
3+
4+
#include <stddef.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
struct io_ops
11+
{
12+
int type;
13+
#ifndef _MSC_VER
14+
int fd;
15+
#else
16+
long long fd;
17+
#endif
18+
int block_size;
19+
size_t total_size;
20+
size_t offset;
21+
unsigned char *ptr;
22+
int (* open)(const char *filename);
23+
int (* read)(void **ptr, size_t *len);
24+
int (* close)(void);
25+
int (* end)(void);
26+
int (* wip)(void); /* tell us the process percentage */
27+
};
28+
29+
typedef enum {
30+
IO_FILE = 0,
31+
IO_UDP = 1,
32+
} io_enum;
33+
34+
struct io_ops *lookup_io_ops(int type);
35+
36+
int register_io_ops(struct io_ops *ops);
37+
38+
int unregister_io_ops(struct io_ops *ops);
39+
40+
41+
void udp_io_init(void);
42+
void fileio_init(void);
43+
44+
#ifdef __cplusplus
45+
}
46+
#endif
47+
48+
#endif

0 commit comments

Comments
 (0)