Skip to content

Commit

Permalink
cmake: focus on in-tree use, but still allow installing a stacic library
Browse files Browse the repository at this point in the history
  • Loading branch information
nemequ committed Jun 8, 2016
1 parent bff856d commit 68f7950
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
66 changes: 36 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
cmake_minimum_required(VERSION 3.1)

project(TinyCThread C)

set(LIBRARY_NAME tinycthread)

## Define COMPILER_OPTIONS_FORMAT to match compiler we are using
if (CMAKE_COMPILER_IS_GNUCC OR ${CMAKE_C_COMPILER_ID} STREQUAL Clang)
set(COMPILER_OPTIONS_FORMAT "GNU")
elseif (${CMAKE_C_COMPILER_ID} STREQUAL MSVC)
set(COMPILER_OPTIONS_FORMAT "MSVC")
endif ()

## Enable extra warnings and make warnings errors
if (${COMPILER_OPTIONS_FORMAT} STREQUAL GNU)
add_compile_options(-Wall -Wextra -Werror -pedantic)
elseif (${COMPILER_OPTIONS_FORMAT} STREQUAL MSVC)
add_compile_options(/W4 /WX /EHsc)
endif ()

include_directories(source)

set(SOURCE_FILES source/tinycthread.c source/tinycthread.h)

add_library(${LIBRARY_NAME} ${SOURCE_FILES})
set_target_properties(${LIBRARY_NAME} PROPERTIES C_STANDARD 11)

install(TARGETS ${LIBRARY_NAME} ARCHIVE DESTINATION lib)
install(FILES source/tinycthread.h DESTINATION include)

cmake_minimum_required(VERSION 2.8.4)
project(TinyCThread)
enable_testing()

find_package(Threads REQUIRED)

add_library(tinycthread STATIC source/tinycthread.c)
target_link_libraries(tinycthread Threads::Threads)
set_property(TARGET tinycthread APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/source")
set_property(TARGET tinycthread APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/source")
set_property(TARGET tinycthread PROPERTY POSITION_INDEPENDENT_CODE True)

option(TINYCTHREAD_DISABLE_TESTS "Disable TinyCThread unit tests")
option(TINYCTHREAD_INSTALL "Install a static library for TinyCThread")

if(NOT TINYCTHREAD_DISABLE_TESTS)
add_executable(test-tinycthread "${CMAKE_CURRENT_SOURCE_DIR}/test/test.c")
target_link_libraries(test-tinycthread tinycthread)

add_test(NAME tinycthread
COMMAND $<TARGET_FILE:test-tinycthread>)
endif(NOT TINYCTHREAD_DISABLE_TESTS)

if(TINYCTHREAD_INSTALL)
if(CMAKE_INSTALL_LIBDIR)
install(TARGETS tinycthread ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
else()
install(TARGETS tinycthread ARCHIVE DESTINATION lib)
endif()

if(CMAKE_INSTALL_INCLUDEDIR)
install(FILES source/tinycthread.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
else()
install(FILES source/tinycthread.h DESTINATION include)
endif()
endif(TINYCTHREAD_INSTALL)
12 changes: 9 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ tinycthread.h to your project. In your own code, do:

#include <tinycthread.h>

TinyCThread also includes CMake support, so if your project uses CMake
you can just `add_subdirectory(tinycthread)`. Then simply add the
tinycthread target (using `target_link_libraries`) where necessary and
CMake will take care of everything else, including adding the correct
include directory and CTest integration.


Building the test programs
--------------------------
Expand All @@ -48,7 +54,8 @@ v1.2 - Unreleased
- Improved Windows support, including TSS destructors
- Added once support
- Improved unit testing
- Assorted bug fixes.
- Added CMake support
- Assorted bug fixes

v1.1 - 2012.9.8
- First release.
Expand All @@ -65,7 +72,7 @@ License
-------

Copyright (c) 2012 Marcus Geelnard
2013-2014 Evan Nemerson
2013-2016 Evan Nemerson

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand All @@ -85,4 +92,3 @@ freely, subject to the following restrictions:

3. This notice may not be removed or altered from any source
distribution.

0 comments on commit 68f7950

Please sign in to comment.