-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake and no-warn MSVC support #118
Open
SamuelMarks
wants to merge
4
commits into
silentbicycle:release
Choose a base branch
from
SamuelMarks:cmake-and-msvc
base: release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
41b2f2f
CMake and no-warn MSVC support
SamuelMarks 28cad5e
MinGW support
SamuelMarks bc3c9ed
[greatest.h] Exclude custom `strncat_s` implementation ; [cmake] Move…
SamuelMarks 28a3e28
[CMakeLists.txt] MinGW and Cygwin support ; [cmake -> contrib] Move a…
SamuelMarks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
cmake_minimum_required(VERSION 3.11) | ||
|
||
project(greatest VERSION 1.5.0 LANGUAGES C) | ||
|
||
#===============# | ||
# Compiler args # | ||
#===============# | ||
|
||
set(CMAKE_C_VISIBILITY_PRESET hidden) | ||
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) | ||
set(CMAKE_C_STANDARD 90 CACHE STRING "") | ||
|
||
add_library("${PROJECT_NAME}_compiler_flags" INTERFACE) | ||
if ((NOT DEFINED MSVC_VERSION | ||
OR MSVC_VERSION STRGREATER "1900") # 2015 | ||
AND NOT (CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")) | ||
target_compile_features("${PROJECT_NAME}_compiler_flags" INTERFACE "c_std_${CMAKE_C_STANDARD}") | ||
else () | ||
message(STATUS "not adding compile features") | ||
endif () | ||
|
||
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15") | ||
# add compiler warning flags just when building this project via | ||
# the BUILD_INTERFACE genex | ||
set(gcc_like "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC>") | ||
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>") | ||
target_compile_options( | ||
"${PROJECT_NAME}_compiler_flags" | ||
INTERFACE | ||
"$<${gcc_like}:$<BUILD_INTERFACE:-Wshadow;-Wformat=2;-Wall;-pedantic;-Wno-format-nonliteral;-Wno-unused-function;-Wno-long-long>>" | ||
"$<${msvc}:$<BUILD_INTERFACE:-W3;-WX;-Zi;-permissive->>" | ||
) | ||
endif (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15") | ||
|
||
# Set the build directories | ||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows" | ||
OR CMAKE_SYSTEM_NAME STREQUAL "CYGWIN" | ||
OR CMAKE_SYSTEM_NAME MATCHES "MINGW.*") | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") | ||
else () | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") | ||
endif () | ||
|
||
#===========# | ||
# Configure # | ||
#===========# | ||
|
||
# configure a header file to pass the version number only | ||
configure_file( | ||
"${CMAKE_SOURCE_DIR}/contrib/cmake/config.h.in" | ||
"${PROJECT_NAME}Config.h" | ||
) | ||
|
||
#=============# | ||
# Sub-targets # | ||
#=============# | ||
|
||
include(CTest) | ||
if (BUILD_TESTING) | ||
add_subdirectory("${CMAKE_SOURCE_DIR}/contrib/cmake/example") | ||
add_subdirectory("${CMAKE_SOURCE_DIR}/contrib/cmake/example_cpp") | ||
endif (BUILD_TESTING) | ||
|
||
#=========# | ||
# Install # | ||
#=========# | ||
|
||
include(GNUInstallDirs) | ||
|
||
include(InstallRequiredSystemLibraries) | ||
set(CPACK_BUNDLE_NAME "${PROJECT_NAME}") | ||
set(CPACK_PACKAGE_VENDOR "SamuelMarks") | ||
set(CPACK_PACKAGE_DESCRIPTION "A C testing library in 1 file. No dependencies, no dynamic allocation. ISC licensed.") | ||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") | ||
if (APPLE) | ||
set(CPACK_BUNDLE_PLIST "contrib/cmake/Info.plist") | ||
set(CPACK_BUNDLE_ICON "contrib/cmake/Info.plist") | ||
set(CPACK_PACKAGE_ICON "contrib/cmake/CustomVolumeIcon.icns") | ||
endif (APPLE) | ||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE") | ||
set(CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}") | ||
set(CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}") | ||
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/contrib/cmake/README.txt") | ||
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/contrib/cmake/Welcome.txt") | ||
set(CPACK_PACKAGE_CONTACT "https://github.com/silentbicycle/${PROJECT_NAME}") | ||
|
||
include(CPack) | ||
include(CMakePackageConfigHelpers) | ||
|
||
# generate the config file that is includes the exports | ||
configure_package_config_file( | ||
"contrib/cmake/Config.cmake.in" | ||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" | ||
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}" | ||
NO_SET_AND_CHECK_MACRO | ||
NO_CHECK_REQUIRED_COMPONENTS_MACRO | ||
) | ||
|
||
# generate the version file for the config file | ||
write_basic_package_version_file( | ||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" | ||
VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}" | ||
COMPATIBILITY AnyNewerVersion | ||
) | ||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" | ||
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}") |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
set(CTEST_PROJECT_NAME "greatest") | ||
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST") | ||
|
||
set(CTEST_DROP_METHOD "http") | ||
set(CTEST_DROP_SITE "my.cdash.org") | ||
set(CTEST_DROP_LOCATION "/submit.php?project=greatest") | ||
set(CTEST_DROP_SITE_CDASH TRUE) |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
@PACKAGE_INIT@ | ||
|
||
include ( "${CMAKE_CURRENT_LIST_DIR}/greatestTargets.cmake" ) |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleExecutable</key> | ||
<string>BundleGeneratorTest</string> | ||
<key>CFBundleIconFile</key> | ||
<string>BundleGeneratorTest.icns</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
</dict> | ||
</plist> |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
include("release/CPackConfig.cmake") | ||
|
||
set(CPACK_INSTALL_CMAKE_PROJECTS | ||
"debug;greatest;ALL;/" | ||
"release;greatest;ALL;/" | ||
) |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
greatest | ||
|
||
A C testing library in 1 file. No dependencies, no dynamic allocation. ISC licensed. | ||
|
||
------------------------------------------------------------------------ | ||
|
||
Licensed under ISC |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
This installs greatest. |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef GREATEST_CONFIG_H | ||
#define GREATEST_CONFIG_H | ||
|
||
#define GREATEST_VERSION_MAJOR @greatest_VERSION_MAJOR@ | ||
#define GREATEST_VERSION_MINOR @greatest_VERSION_MINOR@ | ||
#define GREATEST_VERSION_PATCH @greatest_VERSION_PATCH@ | ||
#define GREATEST_VERSION "@greatest_VERSION@" | ||
|
||
#endif /* !GREATEST_CONFIG_H */ |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
set(Header_Files "${CMAKE_SOURCE_DIR}/greatest.h") | ||
source_group("Header Files" FILES "${Header_Files}") | ||
|
||
add_library("${PROJECT_NAME}" INTERFACE "${Header_Files}") | ||
|
||
target_link_libraries("${PROJECT_NAME}" INTERFACE "${PROJECT_NAME}_compiler_flags") | ||
|
||
include(GNUInstallDirs) | ||
|
||
#=========# | ||
# Install # | ||
#=========# | ||
|
||
# setup the version numbering | ||
set_property(TARGET "${PROJECT_NAME}" PROPERTY VERSION "${${PROJECT_NAME}_VERSION}") | ||
set_property(TARGET "${PROJECT_NAME}" PROPERTY SOVERSION "${${PROJECT_NAME}_VERSION_MAJOR}") | ||
|
||
install(FILES ${Header_Files} | ||
TYPE "INCLUDE") | ||
|
||
#====================# | ||
# Package to install # | ||
#====================# | ||
|
||
set(installable_libs "${PROJECT_NAME}" "${PROJECT_NAME}_compiler_flags") | ||
if (TARGET "${DEPENDANT_LIBRARY}") | ||
list(APPEND installable_libs "${DEPENDANT_LIBRARY}") | ||
endif () | ||
install(TARGETS ${installable_libs} | ||
EXPORT "${PROJECT_NAME}Targets" | ||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") | ||
install(EXPORT "${PROJECT_NAME}Targets" DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}") |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than adding a substitute implementation of
gettimeofday
here, it could just callGetSystemTime
andSystemTimeToFileTime
then use the milliseconds field. Actually replicating the overall behavior ofgettimeofday
isn't important -- it's just grabbing a timestamp to use as a seed for example code.