forked from tinycthread/tinycthread
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmake: focus on in-tree use, but still allow installing a stacic library
- Loading branch information
Showing
2 changed files
with
45 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters