summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaus Klein <claus.klein.sha@googlemail.com>2019-08-11 15:35:44 +0200
committerViktor Kirilov <vik.kirilov@gmail.com>2019-08-11 16:35:44 +0300
commit6f1241c29dd5fa5921f058abbd91997a3c8e9b2a (patch)
tree003a0952d95114a5a1e02b4e908a1ad5743e9868
parentebc76d5e79445f1be5771c18e017db999c2baf35 (diff)
Fixes to the documentation + forcing C++11 for AppleClang - to rework later.
-rw-r--r--CMakeLists.txt2
-rw-r--r--doc/markdown/build-systems.md8
-rw-r--r--examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake22
-rw-r--r--examples/installed_doctest_cmake/executable/CMakeLists.txt2
-rw-r--r--examples/installed_doctest_cmake/executable/main.cpp10
-rw-r--r--scripts/cmake/common.cmake43
-rw-r--r--scripts/cmake/doctest.cmake4
-rw-r--r--scripts/cmake/exec_test.cmake14
-rw-r--r--scripts/how_stuff_works/CMakeLists.txt2
9 files changed, 58 insertions, 49 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b305851..89d4b58 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -60,7 +60,7 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR AND DOCTEST_WITH_TESTS)
include(scripts/cmake/common.cmake)
add_subdirectory(examples/all_features)
-
+
# for code coverage we want exactly one binary to be produced and exercised
if(NOT DEFINED ENV{CODE_COVERAGE})
add_subdirectory(examples/exe_with_static_libs)
diff --git a/doc/markdown/build-systems.md b/doc/markdown/build-systems.md
index dfebf52..7eb8223 100644
--- a/doc/markdown/build-systems.md
+++ b/doc/markdown/build-systems.md
@@ -10,15 +10,15 @@ You can substitute ```master``` with ```dev``` or a tag like ```1.2.9``` for a s
```cmake
cmake_minimum_required(VERSION 3.0)
-project(cmake_test)
+project(cmake_test VERSION 0.0.1 LANGUAGES CXX)
# Prepare doctest for other targets to use
-add_library(doctest INTERFACE)
-target_include_directories(doctest INTERFACE path/to/doctest)
+find_package(doctest REQUIRED)
# Make test executable
add_executable(tests main.cpp)
-target_link_libraries(tests doctest)
+target_compile_features(test PRIVATE cxx_std_17)
+target_link_libraries(test PRIVATE doctest::doctest)
```
- You can also use the following CMake snippet to automatically fetch the entire **doctest** repository from github and configure it as an external project:
diff --git a/examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake b/examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake
index 1192551..ecabc41 100644
--- a/examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake
+++ b/examples/exe_with_static_libs/doctest_force_link_static_lib_in_target.cmake
@@ -14,7 +14,7 @@ function(doctest_include_file_in_sources header sources)
if(old_compile_flags STREQUAL "NOTFOUND")
set(old_compile_flags "")
endif()
-
+
# update flags
if(MSVC)
set_source_files_properties(${src} PROPERTIES COMPILE_FLAGS
@@ -49,7 +49,7 @@ function(doctest_force_link_static_lib_in_target target lib)
set(dummy_dir ${BD}/${LIB_NAME}_DOCTEST_STATIC_LIB_FORCE_LINK_DUMMIES/)
set(dummy_header ${dummy_dir}/all_dummies.h)
file(MAKE_DIRECTORY ${dummy_dir})
-
+
# create a dummy header for each source file, include a dummy function in it and include it in the source file
set(curr_dummy "0")
set(DLL_PRIVATE "#ifndef _WIN32\n#define DLL_PRIVATE __attribute__ ((visibility (\"hidden\")))\n#else\n#define DLL_PRIVATE\n#endif\n\n")
@@ -57,37 +57,37 @@ function(doctest_force_link_static_lib_in_target target lib)
foreach(src ${lib_sources})
if(${src} MATCHES \\.\(cc|cp|cpp|CPP|c\\+\\+|cxx\)$)
math(EXPR curr_dummy "${curr_dummy} + 1")
-
+
set(curr_dummy_header ${dummy_dir}/dummy_${curr_dummy}.h)
file(WRITE ${curr_dummy_header} "${DLL_PRIVATE}namespace doctest { namespace detail { DLL_PRIVATE int dummy_for_${LIB_NAME}_${curr_dummy}(); DLL_PRIVATE int dummy_for_${LIB_NAME}_${curr_dummy}() { return ${curr_dummy}; } } }\n")
doctest_include_file_in_sources(${curr_dummy_header} ${src})
endif()
endforeach()
set(total_dummies ${curr_dummy})
-
+
# create the master dummy header
file(WRITE ${dummy_header} "${DLL_PRIVATE}namespace doctest { namespace detail {\n\n")
-
+
# forward declare the dummy functions in the master dummy header
foreach(curr_dummy RANGE 1 ${total_dummies})
file(APPEND ${dummy_header} "DLL_PRIVATE int dummy_for_${LIB_NAME}_${curr_dummy}();\n")
endforeach()
-
+
# call the dummy functions in the master dummy header
file(APPEND ${dummy_header} "\nDLL_PRIVATE int dummies_for_${LIB_NAME}();\nDLL_PRIVATE int dummies_for_${LIB_NAME}() {\n int res = 0;\n")
foreach(curr_dummy RANGE 1 ${total_dummies})
file(APPEND ${dummy_header} " res += dummy_for_${LIB_NAME}_${curr_dummy}();\n")
endforeach()
file(APPEND ${dummy_header} " return res;\n}\n\n} } // namespaces\n")
-
+
# set the dummy header property so we don't recreate the dummy headers the next time this macro is called for this library
set_target_properties(${lib} PROPERTIES DOCTEST_DUMMY_HEADER ${dummy_header})
set(DDH ${dummy_header})
endif()
-
+
get_target_property(DFLLTD ${target} DOCTEST_FORCE_LINKED_LIBRARIES_THROUGH_DUMMIES)
get_target_property(target_sources ${target} SOURCES)
-
+
if("${DFLLTD}" STREQUAL "DFLLTD-NOTFOUND")
# if no library has been force linked to this target
foreach(src ${target_sources})
@@ -96,7 +96,7 @@ function(doctest_force_link_static_lib_in_target target lib)
break()
endif()
endforeach()
-
+
# add the library as force linked to this target
set_target_properties(${target} PROPERTIES DOCTEST_FORCE_LINKED_LIBRARIES_THROUGH_DUMMIES ${LIB_NAME})
else()
@@ -109,7 +109,7 @@ function(doctest_force_link_static_lib_in_target target lib)
break()
endif()
endforeach()
-
+
# add this library to the list of force linked libraries for this target
list(APPEND DFLLTD ${LIB_NAME})
set_target_properties(${target} PROPERTIES DOCTEST_FORCE_LINKED_LIBRARIES_THROUGH_DUMMIES "${DFLLTD}")
diff --git a/examples/installed_doctest_cmake/executable/CMakeLists.txt b/examples/installed_doctest_cmake/executable/CMakeLists.txt
index 6182a8a..a3c6d8d 100644
--- a/examples/installed_doctest_cmake/executable/CMakeLists.txt
+++ b/examples/installed_doctest_cmake/executable/CMakeLists.txt
@@ -6,4 +6,4 @@ find_package(doctest REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
-target_link_libraries(${PROJECT_NAME} doctest::doctest) \ No newline at end of file
+target_link_libraries(${PROJECT_NAME} PRIVATE doctest::doctest)
diff --git a/examples/installed_doctest_cmake/executable/main.cpp b/examples/installed_doctest_cmake/executable/main.cpp
index 88f57b0..2c9e856 100644
--- a/examples/installed_doctest_cmake/executable/main.cpp
+++ b/examples/installed_doctest_cmake/executable/main.cpp
@@ -4,16 +4,16 @@
int main(int argc, char **argv) {
doctest::Context context;
context.applyCommandLine(argc, argv);
-
+
int res = context.run(); // run doctest
-
+
// important - query flags (and --exit) rely on the user doing this
if (context.shouldExit()) {
// propagate the result of the tests
return res;
}
-
- printf("%s", "Hello, World!");
+
+ printf("%s\n", "Hello, World!");
}
int factorial(const int number) {
@@ -32,4 +32,4 @@ TEST_CASE("testing the factorial function") {
// ./example_exe --no-run (run normal program)
// ./example_exe --exit (run tests then exit)
// ./example_exe (run tests then run program)
-// ./example_exe --success (print successful test casts) \ No newline at end of file
+// ./example_exe --success (print successful test casts)
diff --git a/scripts/cmake/common.cmake b/scripts/cmake/common.cmake
index cd0404d..6f2bb39 100644
--- a/scripts/cmake/common.cmake
+++ b/scripts/cmake/common.cmake
@@ -17,9 +17,9 @@ function(doctest_add_test_impl)
if(NOT "${ARG_UNPARSED_ARGUMENTS}" STREQUAL "" OR "${ARG_NAME}" STREQUAL "" OR "${ARG_COMMAND}" STREQUAL "")
message(FATAL_ERROR "doctest_add_test() called with wrong options!")
endif()
-
+
set(the_test_mode NORMAL)
-
+
# construct the command that will be called by the exec_test.cmake script
set(the_command "")
if(${DOCTEST_TEST_MODE} STREQUAL "VALGRIND" AND NOT ARG_NO_VALGRIND)
@@ -41,9 +41,9 @@ function(doctest_add_test_impl)
set(the_command "${the_command} --dt-no-exitcode=1")
# append the argument for using the same line format in the output - so gcc/non-gcc builds have the same output
set(the_command "${the_command} --dt-gnu-file-line=0")
-
+
string(STRIP ${the_command} the_command)
-
+
if(${DOCTEST_TEST_MODE} STREQUAL "COLLECT" OR ${DOCTEST_TEST_MODE} STREQUAL "COMPARE")
if(NOT ARG_NO_OUTPUT)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test_output/)
@@ -52,9 +52,9 @@ function(doctest_add_test_impl)
list(APPEND ADDITIONAL_FLAGS -DTEST_TEMP_FILE=${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/temp_test_output_${ARG_NAME}.txt)
endif()
endif()
-
+
list(APPEND ADDITIONAL_FLAGS -DTEST_MODE=${the_test_mode})
-
+
add_test(NAME ${ARG_NAME} COMMAND ${CMAKE_COMMAND} -DCOMMAND=${the_command} ${ADDITIONAL_FLAGS} -P ${CURRENT_LIST_DIR_CACHED}/exec_test.cmake)
endfunction()
@@ -110,11 +110,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compiler_flags(-Woverloaded-virtual)
add_compiler_flags(-Wunused-but-set-variable)
add_compiler_flags(-Wunused-result)
-
+
# add_compiler_flags(-Wsuggest-override)
# add_compiler_flags(-Wmultiple-inheritance)
# add_compiler_flags(-Wcatch-value)
- # add_compiler_flags(-Wsuggest-attribute=cold)
+ # add_compiler_flags(-Wsuggest-attribute=cold)
# add_compiler_flags(-Wsuggest-attribute=const)
# add_compiler_flags(-Wsuggest-attribute=format)
# add_compiler_flags(-Wsuggest-attribute=malloc)
@@ -122,17 +122,17 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# add_compiler_flags(-Wsuggest-attribute=pure)
# add_compiler_flags(-Wsuggest-final-methods)
# add_compiler_flags(-Wsuggest-final-types)
-
+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
add_compiler_flags(-Wnoexcept)
endif()
-
+
# no way to silence it in the expression decomposition macros: _Pragma() in macros doesn't work for the c++ front-end of g++
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69543
# Also the warning is completely worthless nowadays - http://stackoverflow.com/questions/14016993
#add_compiler_flags(-Waggregate-return)
-
+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
add_compiler_flags(-Wdouble-promotion)
add_compiler_flags(-Wtrampolines)
@@ -140,24 +140,33 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compiler_flags(-Wuseless-cast)
add_compiler_flags(-Wvector-operation-performance)
endif()
-
+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
add_compiler_flags(-Wshift-overflow=2)
add_compiler_flags(-Wnull-dereference)
add_compiler_flags(-Wduplicated-cond)
endif()
-
+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
add_compiler_flags(-Walloc-zero)
add_compiler_flags(-Walloca)
add_compiler_flags(-Wduplicated-branches)
endif()
-
+
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
add_compiler_flags(-Wcast-align=strict)
endif()
endif()
+if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
+ add_compiler_flags(-std=c++11)
+ # add_compiler_flags(-Wno-c++11-inline-namespace)
+ # add_compiler_flags(-Wno-c++11-extensions)
+ # add_compiler_flags(-Wno-variadic-macros)
+ # add_compiler_flags(-Wno-c++11-compat)
+ # add_compiler_flags(-Wno-c++11-long-long)
+endif()
+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compiler_flags(-Weverything)
add_compiler_flags(-Wno-c++98-compat)
@@ -172,16 +181,16 @@ if(MSVC)
add_compiler_flags(/permissive-) # force standard conformance - this is the better flag than /Za
add_compiler_flags(/WX)
add_compiler_flags(/Wall) # turns on warnings from levels 1 through 4 which are off by default - https://msdn.microsoft.com/en-us/library/23k5d385.aspx
-
+
add_compiler_flags(
/wd4514 # unreferenced inline function has been removed
/wd4571 # SEH related
/wd4710 # function not inlined
/wd4711 # function 'x' selected for automatic inline expansion
-
+
/wd4616 # invalid compiler warnings - https://msdn.microsoft.com/en-us/library/t7ab6xtd.aspx
/wd4619 # invalid compiler warnings - https://msdn.microsoft.com/en-us/library/tacee08d.aspx
-
+
#/wd4820 # padding in structs
#/wd4625 # copy constructor was implicitly defined as deleted
#/wd4626 # assignment operator was implicitly defined as deleted
diff --git a/scripts/cmake/doctest.cmake b/scripts/cmake/doctest.cmake
index c5670be..c7bfe5c 100644
--- a/scripts/cmake/doctest.cmake
+++ b/scripts/cmake/doctest.cmake
@@ -147,7 +147,7 @@ function(doctest_discover_tests TARGET)
"endif()\n"
)
- if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
+ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
# Add discovered tests to directory TEST_INCLUDE_FILES
set_property(DIRECTORY
APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
@@ -155,7 +155,7 @@ function(doctest_discover_tests TARGET)
else()
# Add discovered tests as directory TEST_INCLUDE_FILE if possible
get_property(test_include_file_set DIRECTORY PROPERTY TEST_INCLUDE_FILE SET)
- if (NOT ${test_include_file_set})
+ if(NOT ${test_include_file_set})
set_property(DIRECTORY
PROPERTY TEST_INCLUDE_FILE "${ctest_include_file}"
)
diff --git a/scripts/cmake/exec_test.cmake b/scripts/cmake/exec_test.cmake
index 5dce94b..3ea352f 100644
--- a/scripts/cmake/exec_test.cmake
+++ b/scripts/cmake/exec_test.cmake
@@ -2,7 +2,7 @@
# - COMMAND: the command to run with all it's arguments
# - TEST_MODE: NORMAL/VALGRIND/COLLECT/COMPARE
# - TEST_OUTPUT_FILE: the file to/from which to write/read the output of the test
-# - TEST_TEMP_FILE: the temp file for the current test output used in COMPARE mode
+# - TEST_TEMP_FILE: the temp file for the current test output used in COMPARE mode
# To run something through this script use cmake like this:
# cmake -DCOMMAND=path/to/my.exe -arg1 -arg2 -DTEST_MODE=VALGRIND -P path/to/exec_test.cmake
@@ -31,20 +31,20 @@ if("${TEST_MODE}" STREQUAL "COMPARE")
if(NOT CMAKE_HOST_UNIX)
execute_process(COMMAND dos2unix ${TEST_TEMP_FILE})
endif()
-
+
execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files ${TEST_OUTPUT_FILE} ${TEST_TEMP_FILE} RESULT_VARIABLE cmp_result)
-
+
if(cmp_result)
find_package(Git)
if(GIT_FOUND)
set(cmd ${GIT_EXECUTABLE} diff --no-index ${TEST_OUTPUT_FILE} ${TEST_TEMP_FILE})
execute_process(COMMAND ${GIT_EXECUTABLE} diff --no-index ${TEST_OUTPUT_FILE} ${TEST_TEMP_FILE} OUTPUT_VARIABLE DIFF)
- MESSAGE("${DIFF}")
+ message("${DIFF}")
endif()
-
+
# file(READ ${TEST_OUTPUT_FILE} orig)
# file(READ ${TEST_TEMP_FILE} temp)
-
+
# message("==========================================================================")
# message("== CONTENTS OF ${TEST_OUTPUT_FILE}")
# message("==========================================================================")
@@ -56,7 +56,7 @@ if("${TEST_MODE}" STREQUAL "COMPARE")
# message("==========================================================================")
# message("== CONTENTS END")
# message("==========================================================================")
-
+
set(CMD_RESULT "Output is different from reference file!")
endif()
endif()
diff --git a/scripts/how_stuff_works/CMakeLists.txt b/scripts/how_stuff_works/CMakeLists.txt
index 308b212..6f59cb3 100644
--- a/scripts/how_stuff_works/CMakeLists.txt
+++ b/scripts/how_stuff_works/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.0)
project(how_stuff_works)