From 2a651aa4414adfac72d7e63b92425b567cc31b29 Mon Sep 17 00:00:00 2001 From: Mario Badr Date: Tue, 29 Nov 2016 11:40:47 -0500 Subject: [PATCH] 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 dfd768d..76b2d50 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) if (MSVC) target_compile_options(example PUBLIC /W2) @@ -27,5 +28,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 686e1f6..e738b11 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) if (MSVC) target_compile_options(options_test PUBLIC /W2) 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: