From f4b2e15649303fbfc78c243fcb6ad952a4226db3 Mon Sep 17 00:00:00 2001 From: Mario Badr Date: Tue, 29 Nov 2016 11:40:47 -0500 Subject: [PATCH 1/8] Use cmake interface library --- CMakeLists.txt | 15 +++++++++++---- {src => include/cxxopts}/cxxopts.hpp | 0 src/CMakeLists.txt | 5 ++--- src/example.cpp | 2 +- test/CMakeLists.txt | 1 + test/options.cpp | 2 +- 6 files changed, 16 insertions(+), 9 deletions(-) rename {src => include/cxxopts}/cxxopts.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08ef64f..259378b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ RETURN() ENDIF() -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.1) project(cxxopts) enable_testing() @@ -37,9 +37,7 @@ option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON) option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" OFF) set(CXXOPTS_LINKER_LIBRARIES "") - set(CXXOPTS_USE_UNICODE_HELP FALSE CACHE BOOL "Use ICU Unicode library") - if(CXXOPTS_USE_UNICODE_HELP) find_package(PkgConfig) @@ -48,8 +46,17 @@ if(CXXOPTS_USE_UNICODE_HELP) set(CXXOPTS_LINKER_LIBRARIES "${ICU_LIBRARIES}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCXXOPTS_USE_UNICODE") - endif() +add_library(cxxopts INTERFACE) +target_sources( + cxxopts INTERFACE + ${CMAKE_SOURCE_DIR}/include/cxxopts/cxxopts.hpp + ) +target_include_directories( + cxxopts INTERFACE + ${CMAKE_SOURCE_DIR}/include + ) + add_subdirectory(src) add_subdirectory(test) diff --git a/src/cxxopts.hpp b/include/cxxopts/cxxopts.hpp similarity index 100% rename from src/cxxopts.hpp rename to include/cxxopts/cxxopts.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fd21e5d..d300e74 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,8 @@ # THE SOFTWARE. if(CXXOPTS_BUILD_EXAMPLES) - add_executable(example example.cpp cxxopts.hpp) + add_executable(example example.cpp) + target_link_libraries(example PRIVATE cxxopts) target_link_libraries(example ${CXXOPTS_LINKER_LIBRARIES}) @@ -29,5 +30,3 @@ if(CXXOPTS_BUILD_EXAMPLES) target_compile_options(example PUBLIC -std=c++11 -Wall) endif() endif() - -install(FILES cxxopts.hpp DESTINATION include) diff --git a/src/example.cpp b/src/example.cpp index dbe8a52..7ac596b 100644 --- a/src/example.cpp +++ b/src/example.cpp @@ -24,7 +24,7 @@ THE SOFTWARE. #include -#include "cxxopts.hpp" +#include "cxxopts/cxxopts.hpp" int main(int argc, char* argv[]) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4378e2a..a593baa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,6 @@ if (CXXOPTS_BUILD_TESTS) add_executable(options_test options.cpp) + target_link_libraries(options_test PRIVATE cxxopts) target_link_libraries(options_test ${CXXOPTS_LINKER_LIBRARIES}) diff --git a/test/options.cpp b/test/options.cpp index c15f6a3..01ea64e 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -3,7 +3,7 @@ #include -#include "../src/cxxopts.hpp" +#include "cxxopts/cxxopts.hpp" class Argv { public: From 01417cf3900babec93eaf17abe29e7b201cca369 Mon Sep 17 00:00:00 2001 From: Mario Badr Date: Tue, 29 Nov 2016 12:04:02 -0500 Subject: [PATCH 2/8] Do not use CMAKE_SOURCE_DIR on include dirs CMAKE_SOURCE_DIR can be different depending on where add_subdirectory is called. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 259378b..62fc14e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,7 @@ target_sources( ) target_include_directories( cxxopts INTERFACE - ${CMAKE_SOURCE_DIR}/include + include/ ) add_subdirectory(src) From f7cb4765d322b6df41bdf8a65ed540442338c24b Mon Sep 17 00:00:00 2001 From: Mario Badr Date: Tue, 29 Nov 2016 12:54:38 -0500 Subject: [PATCH 3/8] Use current source directory for target sources --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62fc14e..def2076 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ endif() add_library(cxxopts INTERFACE) target_sources( cxxopts INTERFACE - ${CMAKE_SOURCE_DIR}/include/cxxopts/cxxopts.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/cxxopts/cxxopts.hpp ) target_include_directories( cxxopts INTERFACE From dc3d58833bbf836406814b4711e5fd6cef305f85 Mon Sep 17 00:00:00 2001 From: Mario Badr Date: Wed, 30 Nov 2016 09:26:20 -0500 Subject: [PATCH 4/8] Do not break backward compatibility cxxopts.hpp is a single file and should not be in its own directory for its namespace. --- CMakeLists.txt | 2 +- include/{cxxopts => }/cxxopts.hpp | 0 src/example.cpp | 2 +- test/options.cpp | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename include/{cxxopts => }/cxxopts.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index def2076..b4dfbf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ endif() add_library(cxxopts INTERFACE) target_sources( cxxopts INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR}/include/cxxopts/cxxopts.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/cxxopts.hpp ) target_include_directories( cxxopts INTERFACE diff --git a/include/cxxopts/cxxopts.hpp b/include/cxxopts.hpp similarity index 100% rename from include/cxxopts/cxxopts.hpp rename to include/cxxopts.hpp diff --git a/src/example.cpp b/src/example.cpp index 7ac596b..dbe8a52 100644 --- a/src/example.cpp +++ b/src/example.cpp @@ -24,7 +24,7 @@ THE SOFTWARE. #include -#include "cxxopts/cxxopts.hpp" +#include "cxxopts.hpp" int main(int argc, char* argv[]) { diff --git a/test/options.cpp b/test/options.cpp index 01ea64e..76fad97 100644 --- a/test/options.cpp +++ b/test/options.cpp @@ -3,7 +3,7 @@ #include -#include "cxxopts/cxxopts.hpp" +#include "cxxopts.hpp" class Argv { public: From 8fefcdf3c0892fdf304b110668fc450692abb6f5 Mon Sep 17 00:00:00 2001 From: Mario Badr Date: Wed, 30 Nov 2016 09:28:10 -0500 Subject: [PATCH 5/8] Remove superfluous PRIVATE links from executables --- src/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d300e74..ae6e7bf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,7 @@ if(CXXOPTS_BUILD_EXAMPLES) add_executable(example example.cpp) - target_link_libraries(example PRIVATE cxxopts) + target_link_libraries(example cxxopts) target_link_libraries(example ${CXXOPTS_LINKER_LIBRARIES}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a593baa..cb126f8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,6 @@ if (CXXOPTS_BUILD_TESTS) add_executable(options_test options.cpp) - target_link_libraries(options_test PRIVATE cxxopts) + target_link_libraries(options_test cxxopts) target_link_libraries(options_test ${CXXOPTS_LINKER_LIBRARIES}) From 9a2305e0208439798d5adbadde02cebbc64fb15c Mon Sep 17 00:00:00 2001 From: Mario Badr Date: Tue, 29 Nov 2016 11:40:47 -0500 Subject: [PATCH 6/8] Merge in unicode fixes --- src/CMakeLists.txt | 4 +--- test/CMakeLists.txt | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ae6e7bf..030ca95 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,9 +20,7 @@ if(CXXOPTS_BUILD_EXAMPLES) add_executable(example example.cpp) - target_link_libraries(example cxxopts) - - target_link_libraries(example ${CXXOPTS_LINKER_LIBRARIES}) + target_link_libraries(example cxxopts ${CXXOPTS_LINKER_LIBRARIES}) if (MSVC) target_compile_options(example PUBLIC /W2) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cb126f8..c7a09e1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,6 @@ if (CXXOPTS_BUILD_TESTS) add_executable(options_test options.cpp) - target_link_libraries(options_test cxxopts) - - target_link_libraries(options_test ${CXXOPTS_LINKER_LIBRARIES}) + target_link_libraries(options_test cxxopts ${CXXOPTS_LINKER_LIBRARIES}) if (MSVC) target_compile_options(options_test PUBLIC /W2) From b1795c27e41b131dcbeec69c21d3860b0adcb6fb Mon Sep 17 00:00:00 2001 From: Mario Badr Date: Wed, 30 Nov 2016 10:10:30 -0500 Subject: [PATCH 7/8] Use INTERFACE to pass on unicode dependency Linking the cxxopts library with the unicode libraries and specifying INTERFACE should ensure executables that link with cxxopts will also link with the unicode libraries. --- CMakeLists.txt | 5 +++++ src/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4dfbf3..8007b5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,11 @@ target_include_directories( cxxopts INTERFACE include/ ) +target_link_libraries( + cxxopts + INTERFACE ${CXXOPTS_LINKER_LIBRARIES} + ) + add_subdirectory(src) add_subdirectory(test) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 030ca95..9a79b08 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,7 @@ if(CXXOPTS_BUILD_EXAMPLES) add_executable(example example.cpp) - target_link_libraries(example cxxopts ${CXXOPTS_LINKER_LIBRARIES}) + target_link_libraries(example cxxopts) if (MSVC) target_compile_options(example PUBLIC /W2) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c7a09e1..19aa960 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,6 @@ if (CXXOPTS_BUILD_TESTS) add_executable(options_test options.cpp) - target_link_libraries(options_test cxxopts ${CXXOPTS_LINKER_LIBRARIES}) + target_link_libraries(options_test cxxopts) if (MSVC) target_compile_options(options_test PUBLIC /W2) From 471476d35897df04a7ef7adc7f7cecf903171df9 Mon Sep 17 00:00:00 2001 From: Mario Badr Date: Wed, 30 Nov 2016 17:54:32 -0500 Subject: [PATCH 8/8] Add install destination for library --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8007b5e..35648d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,9 @@ target_link_libraries( INTERFACE ${CXXOPTS_LINKER_LIBRARIES} ) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION include) add_subdirectory(src) add_subdirectory(test) + +