Skip to content

Commit e830d48

Browse files
committed
updated to use cmake
1 parent d8ddc43 commit e830d48

File tree

2 files changed

+69
-13
lines changed

2 files changed

+69
-13
lines changed

CMakeLists.txt

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(vdwreader)
3+
set(CMAKE_CXX_STANDARD 17)
4+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
5+
6+
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
7+
set(LINUX TRUE)
8+
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
9+
set(DARWIN TRUE)
10+
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
11+
set(FREEBSD TRUE)
12+
endif()
13+
14+
# checking if we are called in the correct way:
15+
# with a -B argument. and without a cache file in the source directory.
16+
if (CMAKE_CACHEFILE_DIR STREQUAL "${CMAKE_SOURCE_DIR}")
17+
message(FATAL_ERROR "\nUnexpected CMakeCache.txt file in the source directory. Please remove it.")
18+
return()
19+
endif()
20+
21+
if (EXISTS ${CMAKE_BINARY_DIR}/CMakeLists.txt)
22+
message(FATAL_ERROR "\nRun cmake with an explicit -B buildpath")
23+
return()
24+
endif()
25+
26+
if(MSVC)
27+
# /MP = multithreaded build
28+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
29+
# /utf-8 = utf8 source and execution
30+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
31+
endif()
32+
33+
if (WIN32)
34+
add_definitions(-DNOMINMAX -DNOGDI)
35+
endif()
36+
37+
add_library(itslib ../../itslib/src/stringutils.cpp)
38+
target_include_directories(itslib PUBLIC ../../itslib/include/itslib)
39+
target_compile_definitions(itslib PUBLIC _UNIX _NO_RAPI)
40+
41+
#add_library(cpputils INTERFACE)
42+
#target_include_directories(cpputils INTERFACE ../../cpputils)
43+
44+
45+
find_package(OpenSSL REQUIRED)
46+
find_package(ZLIB REQUIRED)
47+
48+
add_executable(vdwreader ${CMAKE_SOURCE_DIR}/vdwreader.cpp)
49+
target_link_libraries(vdwreader OpenSSL::Crypto)
50+
target_link_libraries(vdwreader ZLIB::ZLIB)
51+
target_link_libraries(vdwreader itslib)
52+
#target_link_libraries(vdwreader cpputils)
53+
54+

Makefile

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
ITSLIB=$(HOME)/myprj/itslib
22
all: vdwreader
33

4-
ifeq ($(D),)
5-
OPT=-O3
6-
else
7-
OPT=-O0
8-
endif
4+
cmake:
5+
cmake -B build . $(if $(D),-DCMAKE_BUILD_TYPE=Debug,-DCMAKE_BUILD_TYPE=Release) $(CMAKEARGS)
6+
$(MAKE) -C build $(if $(V),VERBOSE=1)
97

108
clean:
119
$(RM) -r $(wildcard *.o) *.dSYM vdwreader
10+
$(RM) -r build CMakeFiles CMakeCache.txt CMakeOutput.log
1211

1312
vdwreader: vdwreader.o stringutils.o
1413

15-
CXXFLAGS=-g -Wall -c $(OPT) -I $(ITSLIB)/include/itslib -D_UNIX -D_NO_RAPI -I /usr/local/opt/openssl/include -I . -std=c++17
14+
CFLAGS=-g -Wall $(if $(D),-O0,-O3)
15+
CFLAGS+=-I $(ITSLIB)/include/itslib
16+
CFLAGS+=-D_UNIX -D_NO_RAPI
17+
CFLAGS+=-I /usr/local/opt/openssl/include
18+
CFLAGS+=-I .
19+
20+
CXXFLAGS=-std=c++17
1621

1722
# include CDEFS from make commandline
18-
CXXFLAGS+=$(CDEFS) -MD
23+
CFLAGS+=$(CDEFS)
1924

20-
LDFLAGS+=-g -Wall -L/usr/local/opt/openssl/lib -std=c++17 -lcrypto -lz
25+
LDFLAGS+=-g -Wall -L/usr/local/opt/openssl/lib -lcrypto -lz
2126

2227
vpath .cpp $(ITSLIB)/src .
2328

2429
%.o: $(ITSLIB)/src/%.cpp
25-
$(CXX) $(CXXFLAGS) $^ -o $@
30+
$(CXX) -c $(CFLAGS) $(CXXFLAGS) $^ -o $@
2631

2732
%.o: %.cpp
28-
$(CXX) $(CXXFLAGS) $(filter %.cpp,$^) -o $@
33+
$(CXX) -c $(CFLAGS) $(CXXFLAGS) $(filter %.cpp,$^) -o $@
2934

3035
%: %.o
3136
$(CXX) $(LDFLAGS) $^ -o $@
3237

33-
34-
install:
35-
cp ext2rd ~/bin/

0 commit comments

Comments
 (0)