From 8aaafd462f214a6d453dcad0c1359c4cb8f60456 Mon Sep 17 00:00:00 2001 From: Zopolis4 Date: Wed, 20 Jul 2022 10:07:41 +1000 Subject: [PATCH 1/2] Transition to CMake --- .github/workflows/test.yml | 4 ++-- CMakeLists.txt | 21 +++++++++++++++++++++ Makefile | 30 ------------------------------ 3 files changed, 23 insertions(+), 32 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6eec910..66bbcd9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: cpp11: [0, 1] steps: - uses: actions/checkout@v3 - - run: make test WARN=1 + - run: cmake ./ && make test env: CC: ${{ matrix.compiler }} CPP11: ${{ matrix.cpp11 }} @@ -21,4 +21,4 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v3 - - run: make test WARN=1 + - run: cmake ./ && make test diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..167eb0a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.18) + +project(cpp-optparse) + +set(CMAKE_CXX_STANDARD 11) + +if ((CMAKE_CXX_COMPILER_ID MATCHES GNU) OR (CMAKE_CXX_COMPILER_ID MATCHES Clang)) + set(CMAKE_CXX_FLAGS "-O3 -g -Wall -Wextra -Werror") +# Not sure if these flags still apply to IntelLLVM +elseif (CMAKE_CXX_COMPILER_ID MATCHES Intel) + set(CMAKE_CXX_FLAGS "-O3 -ipo -g -Wall -wd981 -wd383 -wd2259 -Werror") +endif() + +add_library(cpp-optparse OBJECT OptionParser.cpp OptionParser.h) + +add_executable(testprog testprog.cpp) + +target_link_libraries(testprog cpp-optparse) + +enable_testing() +add_test(NAME Test COMMAND testprog "${CMAKE_SOURCE_DIR}/test.sh") diff --git a/Makefile b/Makefile deleted file mode 100644 index 19cab9d..0000000 --- a/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -ifeq ($(WARN),1) -ifeq ($(CXX),g++) -WARN_FLAGS = -O3 -g -Wall -Wextra -Werror # -Weffc++ -else ifeq ($(CXX),clang++) -WARN_FLAGS = -O3 -g -Wall -Wextra -Werror -else ifeq ($(CXX),icpc) -WARN_FLAGS = -O3 -ipo -g -Wall -wd981 -wd383 -wd2259 -Werror # -Weffc++ -endif -endif - -ifeq ($(CPP11),1) -STD_FLAGS = -std=c++0x -endif - -BIN = testprog -OBJECTS = OptionParser.o testprog.o - -$(BIN): $(OBJECTS) - $(CXX) -o $@ $(OBJECTS) $(WARN_FLAGS) $(STD_FLAGS) $(LINKFLAGS) - -%.o: %.cpp OptionParser.h - $(CXX) $(WARN_FLAGS) $(STD_FLAGS) $(CXXFLAGS) -c $< -o $@ - -.PHONY: clean test - -test: testprog - ./test.sh - -clean: - rm -f *.o $(BIN) From 30880f8fb40ae9dda0ec5c5e0a3410b42b906219 Mon Sep 17 00:00:00 2001 From: Zopolis4 Date: Thu, 18 Aug 2022 12:01:23 +1000 Subject: [PATCH 2/2] Add installation and pkg-config --- CMakeLists.txt | 10 +++++++++- pkg-config.pc.in | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 pkg-config.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 167eb0a..b1bfa02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES Intel) set(CMAKE_CXX_FLAGS "-O3 -ipo -g -Wall -wd981 -wd383 -wd2259 -Werror") endif() -add_library(cpp-optparse OBJECT OptionParser.cpp OptionParser.h) +add_library(cpp-optparse OptionParser.cpp OptionParser.h) add_executable(testprog testprog.cpp) @@ -19,3 +19,11 @@ target_link_libraries(testprog cpp-optparse) enable_testing() add_test(NAME Test COMMAND testprog "${CMAKE_SOURCE_DIR}/test.sh") + +include(GNUInstallDirs) + +configure_file("pkg-config.pc.in" "cpp-optparse.pc" @ONLY) + +install(TARGETS cpp-optparse) +install(FILES OptionParser.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cpp-optparse.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") diff --git a/pkg-config.pc.in b/pkg-config.pc.in new file mode 100644 index 0000000..3bbe621 --- /dev/null +++ b/pkg-config.pc.in @@ -0,0 +1,9 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ +includedir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: cpp-optparse +Description: Python's excellent OptionParser in C++ +Version: 1.0 +Libs: -L${libdir} -lcpp-optparse +Cflags: -I${includedir}