Skip to content

Commit

Permalink
add cmake support
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed May 23, 2020
1 parent 7252216 commit 864e9d2
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
81 changes: 81 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#################################################################
# CMake configure file for ZMat
# Qianqian Fang <q.fang at neu.edu>
# 2020/05/23
#################################################################

cmake_minimum_required(VERSION 3.3)

project(zmat)

find_package(ZLIB REQUIRED)
find_package(Matlab)

option(STATIC_LIB "Build static library" ON)

# C Options
set(CMAKE_C_FLAGS "-g -Wall -O3 -fPIC")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../)

# Add include directories
include_directories(lz4)
include_directories(easylzma)
include_directories(easylzma/pavlov)

# Add all project units

if(STATIC_LIB)
add_library(zmat STATIC
zmatlib.c
lz4/lz4.c
lz4/lz4hc.c
easylzma/compress.c
easylzma/decompress.c
easylzma/lzma_header.c
easylzma/lzip_header.c
easylzma/common_internal.c
easylzma/pavlov/LzmaEnc.c
easylzma/pavlov/LzmaDec.c
easylzma/pavlov/LzmaLib.c
easylzma/pavlov/LzFind.c
easylzma/pavlov/Bra.c
easylzma/pavlov/BraIA64.c
easylzma/pavlov/Alloc.c
easylzma/pavlov/7zCrc.c
)
else()
# Add all project units
add_library(zmat SHARED
zmatlib.c
lz4/lz4.c
lz4/lz4hc.c
easylzma/compress.c
easylzma/decompress.c
easylzma/lzma_header.c
easylzma/lzip_header.c
easylzma/common_internal.c
easylzma/pavlov/LzmaEnc.c
easylzma/pavlov/LzmaDec.c
easylzma/pavlov/LzmaLib.c
easylzma/pavlov/LzFind.c
easylzma/pavlov/Bra.c
easylzma/pavlov/BraIA64.c
easylzma/pavlov/Alloc.c
easylzma/pavlov/7zCrc.c
)
endif()

# Link options
target_link_libraries(
zmat
ZLIB::ZLIB
)

if(Matlab_FOUND)
matlab_add_mex(
NAME zipmat
SRC zmat.cpp
LINK_TO mex mx zmat
)
endif()

8 changes: 6 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ROOTDIR ?= ..
ZMATDIR ?= $(ROOTDIR)
MCXSRC :=$(ZMATDIR)/src

MKDIR := mkdir
MKDIR :=mkdir

MEX=mex
AR=$(CC)
Expand Down Expand Up @@ -85,6 +85,10 @@ ifeq ($(MAKECMDGOALS),lib)
LINKOPT :=
endif

ifeq ($(MAKECMDGOALS),dll)
BINARY :=libzmat.so
endif

dll: CPPOPT +=$(DLLFLAG)
dll: AR :=gcc
dll: ARFLAGS :=-shared -Wl,-soname,$(BINARY).1
Expand All @@ -102,7 +106,7 @@ oct: CXX=mkoctfile
mex: CXX=$(MEX)
mex: OUTPUTFLAG:=-output
mex: AR=$(MEX) zmat.cpp $(INCLUDEDIRS)
mex: LINKOPT+= -cxx CXXLIBS='$$CXXLIBS -lz' -outdir $(ZMATDIR)
mex: LINKOPT+= -cxx CXXLIBS='$$CXXLIBS -lz -static-libgcc -static-libstdc++' -outdir $(ZMATDIR)
mex: ARFLAGS :=
mex: OUTPUT_DIR=..

Expand Down

0 comments on commit 864e9d2

Please sign in to comment.