Skip to content

Commit c7dff90

Browse files
committed
Make TestAPI a C file and update build targets
1 parent 1171616 commit c7dff90

File tree

6 files changed

+522
-12
lines changed

6 files changed

+522
-12
lines changed

src/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
cmake_minimum_required(VERSION 3.10)
2-
project(kanzi)
2+
project(kanzi LANGUAGES C CXX)
33

44
# Set C++ standard
55
set(CMAKE_CXX_STANDARD 17)
66
#set(CMAKE_CXX_STANDARD_REQUIRED True)
77
#set(CMAKE_CXX_COMPILER "clang++")
88

9+
# Set C standard (for TestAPI.c)
10+
set(CMAKE_C_STANDARD 11)
11+
#set(CMAKE_C_STANDARD_REQUIRED True)
12+
#set(CMAKE_C_COMPILER "clang")
13+
914
if(CONCURRENCY_DISABLED)
1015
add_definitions(-DCONCURRENCY_DISABLED)
1116
endif()
1217

13-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -O3 -fomit-frame-pointer -fPIC -DNDEBUG -pedantic -march=native -fno-rtti")
18+
set(COMMON_FLAGS "-Wall -Wextra -O3 -fomit-frame-pointer -fPIC -DNDEBUG -pedantic -march=native -fno-rtti")
19+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
20+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
21+
1422

1523
if(MSVC)
1624
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
@@ -95,7 +103,7 @@ set_target_properties(libkanzi_shared PROPERTIES OUTPUT_NAME "kanzi")
95103
#add_library(libkanzi_comp_shared SHARED ${LIB_COMP_SOURCES})
96104
#add_library(libkanzi_decomp_shared SHARED ${LIB_DECOMP_SOURCES})
97105

98-
# Test executables
106+
# Executable target for C++
99107
add_executable(testBWT test/TestBWT.cpp)
100108
target_link_libraries(testBWT libkanzi)
101109

@@ -111,8 +119,11 @@ target_link_libraries(testDefaultBitStream libkanzi)
111119
add_executable(testCompressedStream test/TestCompressedStream.cpp)
112120
target_link_libraries(testCompressedStream libkanzi)
113121

114-
add_executable(testAPI test/TestAPI.cpp)
122+
# Executable target for C API test (TestAPI.c)
123+
add_executable(testAPI test/TestAPI.c)
115124
target_link_libraries(testAPI libkanzi)
125+
# IMPORTANT: Force use of C++ Linker because we link against C++ lib 'archon_static'
126+
set_target_properties(testAPI PROPERTIES LINKER_LANGUAGE CXX)
116127

117128
# Main executable
118129

src/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#CC=clang
12
#CXX=clang++
23
OBJ_DIR = obj
34
TEST_OBJ_DIR=$(OBJ_DIR)/test
@@ -16,6 +17,8 @@ ifeq ($(CONCURRENCY_DISABLED), 1)
1617
CONCURRENCY_FLAG = -DCONCURRENCY_DISABLED
1718
endif
1819

20+
CFLAGS=-c -std=c11 -Wall -Wextra -O3 -fPIC -pedantic -march=native
21+
1922
ifeq ($(OS),Windows_NT)
2023
CXXFLAGS=-c -std=c++11 -Wall -Wextra -O3 -fomit-frame-pointer -fPIC -DNDEBUG -pedantic -march=native -fno-rtti $(CONCURRENCY_FLAG)
2124
LDFLAGS=-lpthread
@@ -86,7 +89,8 @@ TEST_SOURCES=test/TestEntropyCodec.cpp \
8689
test/TestBWT.cpp \
8790
test/TestCompressedStream.cpp \
8891
test/TestDefaultBitStream.cpp \
89-
test/TestTransforms.cpp
92+
test/TestTransforms.cpp \
93+
test/TestAPI.c
9094

9195
APP_SOURCES=app/Kanzi.cpp \
9296
app/InfoPrinter.cpp \
@@ -281,3 +285,7 @@ $(OBJ_DIR)/%.o: %.cpp
281285
@$(MKDIR)
282286
$(CXX) $(CXXFLAGS) $< -o $@
283287

288+
$(OBJ_DIR)/%.o: %.c
289+
@$(MKDIR)
290+
$(CC) $(CFLAGS) $< -o $@
291+

src/api/Compressor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ limitations under the License.
3939
#endif
4040

4141

42-
static constexpr unsigned KANZI_COMP_VERSION_MAJOR = 1;
43-
static constexpr unsigned KANZI_COMP_VERSION_MINOR = 0;
44-
static constexpr unsigned KANZI_COMP_VERSION_PATCH = 0;
42+
#define KANZI_COMP_VERSION_MAJOR 1
43+
#define KANZI_COMP_VERSION_MINOR 0
44+
#define KANZI_COMP_VERSION_PATCH 0
4545

4646

4747
#ifdef __cplusplus

src/api/Decompressor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ KANZI_API int CDECL initDecompressor(struct dData* pData, FILE* src, struct dCon
185185
}
186186

187187

188-
KANZI_API int CDECL decompress(struct dContext* pCtx, unsigned char* dst,
188+
KANZI_API int CDECL decompress(struct dContext* pCtx, unsigned char* dst,
189189
size_t* inSize, size_t* outSize) KANZI_NOEXCEPT
190190
{
191191
if ((pCtx == nullptr) || (outSize == nullptr)) {

src/api/Decompressor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ limitations under the License.
3939
#endif
4040

4141

42-
static constexpr unsigned KANZI_DECOMP_VERSION_MAJOR = 1;
43-
static constexpr unsigned KANZI_DECOMP_VERSION_MINOR = 0;
44-
static constexpr unsigned KANZI_DECOMP_VERSION_PATCH = 0;
42+
#define KANZI_DECOMP_VERSION_MAJOR 1
43+
#define KANZI_DECOMP_VERSION_MINOR 0
44+
#define KANZI_DECOMP_VERSION_PATCH 0
4545

4646

4747
#ifdef __cplusplus

0 commit comments

Comments
 (0)