diff --git a/.appveyor.yml b/.appveyor.yml index 5572092..bacdae5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,20 +2,20 @@ version: "{build}" environment: matrix: - - ARCHITECTURE: x64 - MSVC_VER: 14 - - ARCHITECTURE: x86 - MSVC_VER: 14 - - ARCHITECTURE: x64 - MSVC_VER: 12 - - ARCHITECTURE: x86 - MSVC_VER: 12 - - ARCHITECTURE: x86 - MSVC_VER: 11 - - ARCHITECTURE: x86 - MSVC_VER: 10 - - ARCHITECTURE: x86 - MSVC_VER: 9 + - ARCHITECTURE: x64 + MSVC_VER: 14 + - ARCHITECTURE: x86 + MSVC_VER: 14 + - ARCHITECTURE: x64 + MSVC_VER: 12 + - ARCHITECTURE: x86 + MSVC_VER: 12 + - ARCHITECTURE: x86 + MSVC_VER: 11 + - ARCHITECTURE: x86 + MSVC_VER: 10 + - ARCHITECTURE: x86 + MSVC_VER: 9 branches: except: @@ -29,6 +29,6 @@ install: before_build: - call "C:\Program Files (x86)\Microsoft Visual Studio %MSVC_VER%.0\VC\vcvarsall.bat" %ARCHITECTURE% -build_script: cl.exe /W4 /WX /Feexample munit.c example.c +build_script: cl.exe /W4 /WX /Feexample /I .\ munit.c example.c test_script: example.exe --color always diff --git a/.gitignore b/.gitignore index 115d637..10ece21 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ /example /*.exe /*.dll +build/ +lib/ +bin/ +.DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..eb2acc2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,67 @@ +cmake_minimum_required(VERSION 3.7...3.18) + +if(${CMAKE_VERSION} VERSION_LESS 3.12) + cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) +endif() + +project("munit" VERSION 0.2.0 + DESCRIPTION "µnit Testing Library for C" + LANGUAGES C + ) + +# Options +option(BUILD_SHARED_LIBS "Build shared library" ON) +option(BUILD_STATIC_LIBS "Build static library" ON) +option(BUILD_EXAMPLE "Build example program" OFF) + +if(NOT(${BUILD_SHARED_LIBS} OR ${BUILD_STATIC_LIBS})) + message(FATAL_ERROR "Error: At least one of the static library and the shared library must be built.") +endif() + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +configure_file(munit.pc.in ${CMAKE_SOURCE_DIR}/lib/pkgconfig/munit.pc @ONLY) + +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra -Wpedantic") +set(CMAKE_BUILD_TYPE Release) + +add_library(munit_mod MODULE) +target_sources(munit_mod PRIVATE munit.c) +target_include_directories(munit_mod PRIVATE ./) + +if(${BUILD_SHARED_LIBS}) + add_library(munit SHARED $) + target_include_directories(munit PUBLIC ./) + set_target_properties(munit PROPERTIES OUTPUT_NAME "munit") +endif() + +if(${BUILD_STATIC_LIBS}) + add_library(munit_static STATIC $) + target_include_directories(munit_static PUBLIC ./) + set_target_properties(munit_static PROPERTIES OUTPUT_NAME "munit") + install(TARGETS munit_static ARCHIVE) +endif() + +if(${BUILD_EXAMPLE}) + add_executable(munit_example) + target_sources(munit_example PRIVATE example.c) + if(${BUILD_STATIC_LIBS}) + target_link_libraries(munit_example munit_static) + else() + target_link_libraries(munit_example munit) + endif() +endif() + +# Installation +install(FILES ${CMAKE_SOURCE_DIR}/lib/pkgconfig/munit.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) +install(FILES munit.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include) + +if(${BUILD_SHARED_LIBS}) + install(TARGETS munit LIBRARY) +endif() + +if(${BUILD_STATIC_LIBS}) + install(TARGETS munit_static LIBRARY) +endif() diff --git a/Makefile b/Makefile index 65d33fc..bd92cb0 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,8 @@ ifneq ($(CC),pgcc) endif endif -example$(EXTENSION): munit.h munit.c example.c - $(CC) $(CFLAGS) -o $@ munit.c example.c +example$(EXTENSION): + $(CC) $(CFLAGS) -o $@ -I ./ munit.c example.c test: $(TEST_ENV) ./example$(EXTENSION) diff --git a/README.md b/README.md index 9f861f2..ad0ec7f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,8 @@ # µnit -µnit is a small but full-featured unit testing framework for C. It has -no dependencies (beyond libc), is permissively licensed (MIT), and is -easy to include into any project. +µnit is a small but full-featured unit testing framework for C. It has no dependencies (beyond libc), is permissively licensed (MIT), and is easy to include into any project. -For more information, see -[the µnit web site](https://nemequ.github.io/munit). +For more information, see [the µnit web site](https://nemequ.github.io/munit). [![Build status](https://travis-ci.org/nemequ/munit.svg?branch=master)](https://travis-ci.org/nemequ/munit) [![Windows build status](https://ci.appveyor.com/api/projects/status/db515g5ifcwjohq7/branch/master?svg=true)](https://ci.appveyor.com/project/quixdb/munit/branch/master) @@ -14,24 +11,20 @@ For more information, see Features µnit currently includes include: - * Handy assertion macros which make for nice error messages. - * Reproducible cross-platform random number generation, including - support for supplying a seed via CLI. - * Timing of both wall-clock and CPU time. - * Parameterized tests. - * Nested test suites. - * Flexible CLI. - * Forking - ([except on Windows](https://github.com/nemequ/munit/issues/2)). - * Hiding output of successful tests. +- Handy assertion macros which make for nice error messages. +- Reproducible cross-platform random number generation, including support for supplying a seed via CLI. +- Timing of both wall-clock and CPU time. +- Parameterized tests. +- Nested test suites. +- Flexible CLI. +- Forking ([except on Windows](https://github.com/nemequ/munit/issues/2)). +- Hiding output of successful tests. -Features µnit does not currently include, but some day may include -(a.k.a., if you file a PR…), include: +Features µnit does not currently include, but some day may include (a.k.a., if you file a PR…), include: - * [TAP](http://testanything.org/) support; feel free to discuss in - [issue #1](https://github.com/nemequ/munit/issues/1) +- [TAP](http://testanything.org/) support; feel free to discuss in [issue #1](https://github.com/nemequ/munit/issues/1) -### Include into your project with meson +### Integrate µnit into your project with meson In your `subprojects` folder put a `munit.wrap` file containing: @@ -42,13 +35,28 @@ url=https://github.com/nemequ/munit/ revision=head ``` -Then you can use a subproject fallback when you include munit as a -dependency to your project: `dependency('munit', fallback: ['munit', 'munit_dep'])` +Then you can use a subproject fallback when you include munit as a dependency to your project: `dependency('munit', fallback: ['munit', 'munit_dep'])` + +### Integrate µnit into your project with CMake + +You can include µnit as a git submodule and this will expose a `munit` target which can be linked to in your project. Assuming your project is located at `$PROJECT_ROOT`, first add µnit as a submodule: + +``` +cd $PROJECT_ROOT +mkdir extern && cd extern +> git submodule add https://github.com/nemequ/munit +``` + +Then, in your `CMakeLists.txt` file (again, assumed to be located in `$PROJECT_ROOT`), add the following line: + +``` +add_subdirectory(${CMAKE_SOURCE_DIR}/extern/munit) +``` + +and this will expose the `munit` and `munit_static` targets, which can be linked against in your project with `target_link_libraries`. These targets also have the relevant header file embedded within them. ## Documentation See [the µnit web site](https://nemequ.github.io/munit). -Additionally, there is a heavily-commented -[example.c](https://github.com/nemequ/munit/blob/master/example.c) in -the repository. +Additionally, there is a heavily-commented [example.c](https://github.com/nemequ/munit/blob/master/example.c) in the repository. diff --git a/meson.build b/meson.build index c15b405..3f48238 100644 --- a/meson.build +++ b/meson.build @@ -1,16 +1,15 @@ -project('munit', 'c') +project('munit', 'c', default_options : ['c_std=c99']) conf_data = configuration_data() conf_data.set('version', '0.2.0') -add_project_arguments('-std=c99', language : 'c') - cc = meson.get_compiler('c') root_include = include_directories('.') munit = library('munit', ['munit.c'], + include_directories: root_include, install: meson.is_subproject()) if meson.is_subproject() diff --git a/munit.pc.in b/munit.pc.in new file mode 100644 index 0000000..8cfa49b --- /dev/null +++ b/munit.pc.in @@ -0,0 +1,9 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: munit +Description: µnit Testing Library for C +Version: 0.4.1 +Libs: -L${libdir} -lmunit +Cflags: -I${includedir}