From 90fbf407f3e78048e95714dbfa3ec2a903262951 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Fri, 27 Jul 2018 18:01:09 -0700 Subject: [PATCH 1/3] Add Header-Only cmake project structure --- .gitignore | 1 + CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++++++ test/example.cpp | 2 +- test/test.cpp | 4 ++-- 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index 2b513ca..6ec82c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ test/** !test/test.cpp !test/example.cpp +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..11f6a75 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required( VERSION 3.2.2 ) +project( mio ) + +### Standard +set( CMAKE_CXX_STANDARD 11 ) +set( CMAKE_CXX_STANDARD_REQUIRED ON ) +set( CMAKE_CXX_EXTENSIONS ON ) + +### Verbosity +set( CMAKE_COLOR_MAKEFILE ON ) +set( CMAKE_VERBOSE_MAKEFILE ON ) + +# Generate 'compile_commands.json' for clang_complete +set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) + +### Flags +if( MSVC ) + add_compile_options( /W3 ) +elseif( CMAKE_COMPILER_IS_GNUCXX ) + add_compile_options( -Wall ) + add_compile_options( -Wextra ) +endif() + +### Library targets +add_library( mio INTERFACE) +target_include_directories( mio INTERFACE include ) + +### Test targets + +## test +add_executable( + test + test/test.cpp +) +target_link_libraries( test PRIVATE mio ) + +## example +add_executable( + example + test/example.cpp +) +target_link_libraries( example PRIVATE mio ) diff --git a/test/example.cpp b/test/example.cpp index 304e3e6..5385ffc 100644 --- a/test/example.cpp +++ b/test/example.cpp @@ -1,4 +1,4 @@ -#include "../include/mio/mmap.hpp" +#include #include // for std::error_code #include // for std::printf #include diff --git a/test/test.cpp b/test/test.cpp index 4284cd0..01536a6 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,5 +1,5 @@ -#include "../include/mio/mmap.hpp" -#include "../include/mio/shared_mmap.hpp" +#include +#include #include #include From 2db812da58f0082bc6a9b96f6f659e33f49caba0 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Fri, 27 Jul 2018 18:58:10 -0700 Subject: [PATCH 2/3] Update README with CMake info --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 8499935..cd955f5 100644 --- a/README.md +++ b/README.md @@ -140,3 +140,17 @@ Though generally not needed, since mio maps users requested offsets to page boun ### Installation mio is a header-only library, so just copy the contents in `mio/include` into your system wide include path, such as `/usr/include`, or into your project's lib folder. + +## CMake +A `CMakeLists.txt` is provided to allow easy git submodule usage or installation. + +To use as a submodule, clone mio within your project's dependencies/externals folder and add: +``` +add_subdirectory( dependencies_folder/mio ) +target_link_libraries( MyCoolProject mio ) +``` +to your project's `CMakeLists.txt` to add mio into `MyCoolProject`'s include-space. + +To install, do an out-of-source build(such as making a `build` folder and running `cmake ..` inside of it) and then run `sudo make install` to copy relevant include files to + +The optional `BUILD_TESTS` option can be used to build unit tests(off by default) by instead using `cmake -DBUILD_TESTS=ON ..` From b6517e711f25f6c2644ccc135a9372315e123fec Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Fri, 27 Jul 2018 18:58:41 -0700 Subject: [PATCH 3/3] Add BUILD_TESTS option, installation Remove compiler flags/warnings, makefile verbosity and colors --- CMakeLists.txt | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11f6a75..72ef501 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,40 +3,34 @@ project( mio ) ### Standard set( CMAKE_CXX_STANDARD 11 ) -set( CMAKE_CXX_STANDARD_REQUIRED ON ) -set( CMAKE_CXX_EXTENSIONS ON ) - -### Verbosity -set( CMAKE_COLOR_MAKEFILE ON ) -set( CMAKE_VERBOSE_MAKEFILE ON ) # Generate 'compile_commands.json' for clang_complete set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) -### Flags -if( MSVC ) - add_compile_options( /W3 ) -elseif( CMAKE_COMPILER_IS_GNUCXX ) - add_compile_options( -Wall ) - add_compile_options( -Wextra ) -endif() +### Flags/Options +option( BUILD_TESTS "Enable the building of mio unit tests" OFF ) ### Library targets add_library( mio INTERFACE) target_include_directories( mio INTERFACE include ) +install( + DIRECTORY include/ + DESTINATION include +) ### Test targets - -## test -add_executable( - test - test/test.cpp -) -target_link_libraries( test PRIVATE mio ) - -## example -add_executable( - example - test/example.cpp -) -target_link_libraries( example PRIVATE mio ) +if( BUILD_TESTS ) + ## test + add_executable( + test + test/test.cpp + ) + target_link_libraries( test PRIVATE mio ) + + ## example + add_executable( + example + test/example.cpp + ) + target_link_libraries( example PRIVATE mio ) +endif()