@@ -17,100 +17,105 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
1717# - TE_FLOAT, TE_LONG_DOUBLE to use float or long double as the internal datatype
1818# - TE_POW_FROM_RIGHT to enable parsing exponents from the right
1919# - TE_BITWISE_OPERATORS to parse ^, &, and | as bitwise operators
20+ # - TE_BUILD_TEST_RUNNER to toggle running the tests
21+
22+ option (TE_BUILD_TEST_RUNNER "Build test runner" ON )
2023
2124project (TETestRunner)
2225
23- # https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
24- if (CMAKE_COMPILER_IS_GNUCXX)
25- list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake_modules" )
26- include (CodeCoverage)
27- append_coverage_compiler_flags()
28- setup_target_for_coverage_lcov(NAME ${CMAKE_PROJECT_NAME} _coverage
29- EXECUTABLE ${CMAKE_PROJECT_NAME}
30- DEPENDENCIES ${CMAKE_PROJECT_NAME} )
31- endif ()
32-
33- find_program (CLANG_TIDY_COMMAND
34- NAMES
35- clang-tidy
36- NO_CACHE)
37- if (CLANG_TIDY_COMMAND AND USE_CLANG_TIDY)
38- if (MSVC )
39- set (CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND} --extra-arg=/EHsc)
40- else ()
41- set (CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND} )
26+ if (TE_BUILD_TEST_RUNNER)
27+ # https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
28+ if (CMAKE_COMPILER_IS_GNUCXX)
29+ list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake_modules" )
30+ include (CodeCoverage)
31+ append_coverage_compiler_flags()
32+ setup_target_for_coverage_lcov(NAME ${CMAKE_PROJECT_NAME} _coverage
33+ EXECUTABLE ${CMAKE_PROJECT_NAME}
34+ DEPENDENCIES ${CMAKE_PROJECT_NAME} )
4235 endif ()
43- endif ()
44-
45- if (USE_ADDRESS_SANITIZE)
46- message (STATUS "Address Sanitizer enabled" )
47- endif ()
48-
49- if (USE_CLANG_TIDY)
50- message (STATUS "clang-tidy enabled" )
51- endif ()
52-
53- if (TE_FLOAT)
54- message (STATUS "Datatype: float" )
55- add_definitions (-DTE_FLOAT)
56- elseif (TE_LONG_DOUBLE)
57- message (STATUS "Datatype: long double" )
58- add_definitions (-DTE_LONG_DOUBLE)
59- else ()
60- message (STATUS "Datatype: double" )
61- endif (TE_FLOAT)
62-
63- if (TE_POW_FROM_RIGHT)
64- message (STATUS "Power from right: enabled" )
65- add_definitions (-DTE_POW_FROM_RIGHT)
66- else ()
67- message (STATUS "Power from right: disabled" )
68- endif (TE_POW_FROM_RIGHT)
69-
70- if (TE_BITWISE_OPERATORS)
71- message (STATUS "Extended bitwise operators: enabled" )
72- add_definitions (-DTE_BITWISE_OPERATORS)
73- else ()
74- message (STATUS "Extended bitwise operators: disabled" )
75- endif (TE_BITWISE_OPERATORS)
76-
77- if (TE_BRACKETS_AS_PARENS)
78- message (STATUS "[] being treats as (): enabled" )
79- add_definitions (-DTE_BRACKETS_AS_PARENS)
80- else ()
81- message (STATUS "[] being treats as (): disabled" )
82- endif (TE_BRACKETS_AS_PARENS)
83-
84- # place Catch2 at the same folder level as this repo if it isn't installed
85- # (you will need to do this on Windows or macOS or if version 3 of Catch2 isn't installed)
86- get_filename_component (_fullpath "${_dir} " REALPATH)
87- if (EXISTS "${_fullpath} " AND EXISTS "${_fullpath} /../../Catch2" )
88- add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /../../Catch2 ${CMAKE_CURRENT_BINARY_DIR} /Catch2)
89- else ()
90- # ...otherwise, see if it is installed
91- find_package (Catch2 3 REQUIRED)
92- endif ()
93-
94- set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR} /bin)
95-
96- add_executable (${CMAKE_PROJECT_NAME} ../tinyexpr.cpp tetests.cpp testingmain.cpp)
97- if (MSVC )
98- target_compile_definitions (${CMAKE_PROJECT_NAME} PUBLIC _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION
99- $<$<CONFIG:Release>:NDEBUG>)
100- # This warning:
101- # C4554: check operator precedence for possible error; use parentheses to clarify precedence
102- # is suppressed because of unit test, not the code itself.
36+
37+ find_program (CLANG_TIDY_COMMAND
38+ NAMES
39+ clang-tidy
40+ NO_CACHE)
41+ if (CLANG_TIDY_COMMAND AND USE_CLANG_TIDY)
42+ if (MSVC )
43+ set (CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND} --extra-arg=/EHsc)
44+ else ()
45+ set (CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND} )
46+ endif ()
47+ endif ()
48+
10349 if (USE_ADDRESS_SANITIZE)
104- target_compile_options (${CMAKE_PROJECT_NAME} PUBLIC /Zc:__cplusplus /MP /W3 /WX /wd4554
105- $<$<CONFIG:Debug>:/Od /fsanitize=address> $<$<CONFIG:Release>:/O2>)
50+ message (STATUS "Address Sanitizer enabled" )
51+ endif ()
52+
53+ if (USE_CLANG_TIDY)
54+ message (STATUS "clang-tidy enabled" )
55+ endif ()
56+
57+ if (TE_FLOAT)
58+ message (STATUS "Datatype: float" )
59+ add_definitions (-DTE_FLOAT)
60+ elseif (TE_LONG_DOUBLE)
61+ message (STATUS "Datatype: long double" )
62+ add_definitions (-DTE_LONG_DOUBLE)
63+ else ()
64+ message (STATUS "Datatype: double" )
65+ endif (TE_FLOAT)
66+
67+ if (TE_POW_FROM_RIGHT)
68+ message (STATUS "Power from right: enabled" )
69+ add_definitions (-DTE_POW_FROM_RIGHT)
70+ else ()
71+ message (STATUS "Power from right: disabled" )
72+ endif (TE_POW_FROM_RIGHT)
73+
74+ if (TE_BITWISE_OPERATORS)
75+ message (STATUS "Extended bitwise operators: enabled" )
76+ add_definitions (-DTE_BITWISE_OPERATORS)
10677 else ()
107- target_compile_options (${CMAKE_PROJECT_NAME} PUBLIC /Zc:__cplusplus /MP /W3 /WX /wd4554
108- $<$<CONFIG:Debug>:/Od> $<$<CONFIG:Release>:/O2>)
78+ message (STATUS "Extended bitwise operators: disabled" )
79+ endif (TE_BITWISE_OPERATORS)
80+
81+ if (TE_BRACKETS_AS_PARENS)
82+ message (STATUS "[] being treats as (): enabled" )
83+ add_definitions (-DTE_BRACKETS_AS_PARENS)
84+ else ()
85+ message (STATUS "[] being treats as (): disabled" )
86+ endif (TE_BRACKETS_AS_PARENS)
87+
88+ # place Catch2 at the same folder level as this repo if it isn't installed
89+ # (you will need to do this on Windows or macOS or if version 3 of Catch2 isn't installed)
90+ get_filename_component (_fullpath "${_dir} " REALPATH)
91+ if (EXISTS "${_fullpath} " AND EXISTS "${_fullpath} /../../Catch2" )
92+ add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /../../Catch2 ${CMAKE_CURRENT_BINARY_DIR} /Catch2)
93+ else ()
94+ # ...otherwise, see if it is installed
95+ find_package (Catch2 3 REQUIRED)
96+ endif ()
97+
98+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR} /bin)
99+
100+ add_executable (${CMAKE_PROJECT_NAME} ../tinyexpr.cpp tetests.cpp testingmain.cpp)
101+ if (MSVC )
102+ target_compile_definitions (${CMAKE_PROJECT_NAME} PUBLIC _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION
103+ $<$<CONFIG:Release>:NDEBUG>)
104+ # This warning:
105+ # C4554: check operator precedence for possible error; use parentheses to clarify precedence
106+ # is suppressed because of unit test, not the code itself.
107+ if (USE_ADDRESS_SANITIZE)
108+ target_compile_options (${CMAKE_PROJECT_NAME} PUBLIC /Zc:__cplusplus /MP /W3 /WX /wd4554
109+ $<$<CONFIG:Debug>:/Od /fsanitize=address> $<$<CONFIG:Release>:/O2>)
110+ else ()
111+ target_compile_options (${CMAKE_PROJECT_NAME} PUBLIC /Zc:__cplusplus /MP /W3 /WX /wd4554
112+ $<$<CONFIG:Debug>:/Od> $<$<CONFIG:Release>:/O2>)
113+ endif ()
109114 endif ()
110- endif ()
111- target_link_libraries (${CMAKE_PROJECT_NAME} PRIVATE Catch2::Catch2)
115+ target_link_libraries (${CMAKE_PROJECT_NAME} PRIVATE Catch2::Catch2)
112116
113- # load the test cases into the runner
114- include (CTest)
115- include (Catch)
116- catch_discover_tests(${CMAKE_PROJECT_NAME} )
117+ # load the test cases into the runner
118+ include (CTest)
119+ include (Catch)
120+ catch_discover_tests(${CMAKE_PROJECT_NAME} )
121+ endif ()
0 commit comments