Skip to content

Commit 17b41da

Browse files
committed
add std::chrono test, if available use in thread test
1 parent 135adc7 commit 17b41da

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

cmake/SC_Config_Headers.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ cmake_push_check_state()
6464
CHECK_CXX_SOURCE_RUNS( "${TEST_STD_THREAD}" HAVE_STD_THREAD ) #quotes are *required*!
6565
cmake_pop_check_state()
6666

67+
set( TEST_STD_CHRONO "
68+
#include <iostream>
69+
#include <chrono>
70+
int main() {
71+
std::chrono::seconds sec(1);
72+
std::cout << \"1s is \"<< std::chrono::duration_cast<std::chrono::milliseconds>(sec).count() << \" ms\" << std::endl;
73+
}
74+
" )
75+
cmake_push_check_state()
76+
if( UNIX )
77+
set( CMAKE_REQUIRED_FLAGS "-std=c++0x" )
78+
else( UNIX )
79+
# vars probably need set for embarcadero, etc
80+
endif( UNIX )
81+
CHECK_CXX_SOURCE_RUNS( "${TEST_STD_CHRONO}" HAVE_STD_CHRONO ) #quotes are *required*!
82+
cmake_pop_check_state()
83+
6784
# Now that all the tests are done, configure the sc_cf.h file:
6885
get_property(CONFIG_H_FILE_CONTENTS GLOBAL PROPERTY SC_CONFIG_H_CONTENTS)
6986
file(WRITE ${CONFIG_H_FILE} "${CONFIG_H_FILE_CONTENTS}")

include/sc_cf_cmake.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
#cmakedefine HAVE_SSIZE_T 1
2525

2626
#cmakedefine HAVE_STD_THREAD 1
27+
#cmakedefine HAVE_STD_CHRONO 1
2728

2829
#endif /* SCL_CF_H */

test/cpp/schema_specific/stepfile_rw_progress.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@
1515
# error Need std::thread for this test!
1616
#endif
1717

18+
#ifdef HAVE_STD_CHRONO
19+
# include <chrono>
20+
#endif
21+
1822
#ifdef HAVE_UNISTD_H
1923
# include <unistd.h>
2024
#endif
2125

2226
#include "SdaiAUTOMOTIVE_DESIGN.h"
2327

2428
//macro for 50 ms sleep (could be more for a larger file, may need reduced for a fast processor)
25-
#ifndef __WIN32__
26-
# define DELAY(t) usleep( t * 100 );
29+
#ifdef HAVE_STD_CHRONO
30+
# define DELAY(t) std::this_thread::sleep_for(std::chrono::milliseconds(50));
2731
#else
28-
#define DELAY(t) Sleep( t );
32+
# ifndef __WIN32__
33+
# define DELAY(t) usleep( t * 100 )
34+
# else
35+
# include <WinBase.h>
36+
# define DELAY(t) Sleep( t )
37+
# endif
2938
#endif
3039

31-
3240
// NOTE this test requires std::thread, part of C++11. It will fail to compile otherwise.
3341

3442
void readProgressParallel( STEPfile & f, float & maxProgress ) {

0 commit comments

Comments
 (0)