Skip to content

Commit

Permalink
Make snowhouse a CMake library
Browse files Browse the repository at this point in the history
This moves headers into a new include/ directory
and turns off default running/building of tests.
Document the CMake-based installation.
Support for CMake < 3.0.0 is retained.
  • Loading branch information
HauserV authored and sbeyer committed Jan 9, 2019
1 parent 98c8d81 commit 5d08afa
Show file tree
Hide file tree
Showing 46 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ environment:
- CXX_STANDARD: 14

build_script:
- cmake -G "Visual Studio 14" -DSNOWHOUSE_RUN_TESTS=0 -DSNOWHOUSE_CXX_STANDARD=C++%CXX_STANDARD%
- cmake -G "Visual Studio 14" -DSNOWHOUSE_RUN_TESTS=0 -DSNOWHOUSE_BUILD_TESTS=1 -DSNOWHOUSE_CXX_STANDARD=C++%CXX_STANDARD%
- cmake --build .
test_script:
- bin\Debug\snowhouse-tests.exe
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ cmake_minimum_required(VERSION 2.8)

project(snowhouse)

option(SNOWHOUSE_BUILD_TESTS "Build the Snowhouse tests" ON)
option(SNOWHOUSE_RUN_TESTS "Run the Snowhouse tests" ON)
option(SNOWHOUSE_BUILD_TESTS "Build the Snowhouse tests" OFF)
option(SNOWHOUSE_RUN_TESTS "Run the Snowhouse tests" OFF)
set(SNOWHOUSE_CXX_STANDARD "C++03" CACHE STRING "The C++ standard the examples are compiled with")
set_property(CACHE SNOWHOUSE_CXX_STANDARD PROPERTY STRINGS "C++98" "C++03" "C++11" "C++14")

include_directories("${PROJECT_SOURCE_DIR}")
if (NOT ${CMAKE_VERSION} VERSION_LESS "3.0.0")
add_library(snowhouse INTERFACE)
target_include_directories(snowhouse INTERFACE include)
endif()

if(SNOWHOUSE_CXX_STANDARD STREQUAL "C++98")
set(std_name "c++98")
Expand Down Expand Up @@ -45,6 +48,11 @@ message(STATUS "C++ compiler flags: ${CMAKE_CXX_FLAGS}")
if (SNOWHOUSE_BUILD_TESTS)
FILE(GLOB SnowhouseSpecSourceFiles example/*.cpp)
add_executable(snowhouse-tests ${SnowhouseSpecSourceFiles})
if (NOT ${CMAKE_VERSION} VERSION_LESS "3.0.0")
target_link_libraries(snowhouse-tests PRIVATE snowhouse)
else()
include_directories("${PROJECT_SOURCE_DIR}/include")
endif()
endif()

if (SNOWHOUSE_BUILD_TESTS AND SNOWHOUSE_RUN_TESTS)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ git submodule add -b headers-only https://github.com/banditcpp/snowhouse snowhou
git submodule update --init --recursive
```

As an alternative, CMake >= 3.0 users can use Snowhouse with the provided library target.
Assuming you have cloned the `master` branch into a `snowhouse` subdirectory,
your `CMakeLists.txt` might contain lines like the following:

```cmake
add_subdirectory(snowhouse)
add_executable(app main.cpp)
target_link_libraries(app snowhouse)
```

## Usage

```C++
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion util/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ echo " * build path: $buildpath"

mkdir -p "$SRCDIR/$buildpath"
cd "$SRCDIR/$buildpath" || exit
cmake -D"SNOWHOUSE_CXX_STANDARD=C++$cxxstandard" "$SRCDIR" || exit
cmake -DSNOWHOUSE_BUILD_TESTS=1 -DSNOWHOUSE_RUN_TESTS=1 -D"SNOWHOUSE_CXX_STANDARD=C++$cxxstandard" "$SRCDIR" || exit
cmake --build . || exit

0 comments on commit 5d08afa

Please sign in to comment.