Skip to content

Commit 017faa9

Browse files
committed
make schema-specific tests work on cmake 3.x
1 parent 46c3720 commit 017faa9

2 files changed

Lines changed: 51 additions & 23 deletions

File tree

cmake/SC_Config_Headers.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ cmake_push_check_state()
5959
if( UNIX )
6060
set( CMAKE_REQUIRED_FLAGS "-pthread -std=c++0x" )
6161
else( UNIX )
62-
# vars probably need set for MSVC11, embarcadero, etc
62+
# vars probably need set for embarcadero, etc
6363
endif( UNIX )
6464
CHECK_CXX_SOURCE_RUNS( "${TEST_STD_THREAD}" HAVE_STD_THREAD ) #quotes are *required*!
6565
cmake_pop_check_state()

test/cpp/schema_specific/CMakeLists.txt

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,51 @@ cmake_minimum_required(VERSION 2.8)
44
include_directories( ${SC_SOURCE_DIR}/src/cldai ${SC_SOURCE_DIR}/src/cleditor ${SC_SOURCE_DIR}/src/clutils
55
${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/base )
66

7+
# helper function for add_schema_dependent_test
8+
# given an sdai target, set out_path_var to the include dir
9+
# added as a workaround for changed behavior in newer cmake
10+
# versions (changes somewhere between 2.8 and 3.1)
11+
function(get_sdai_incl_dir out_path_var sdai_lib)
12+
if(DEFINED sdai_${sdai_lib}_SOURCE_DIR)
13+
set(${out_path_var} ${sdai_${sdai_lib}_SOURCE_DIR} PARENT_SCOPE)
14+
return()
15+
endif(DEFINED sdai_${sdai_lib}_SOURCE_DIR)
16+
get_target_property(sdai_srcs sdai_${sdai_lib} SOURCES)
17+
foreach(src ${sdai_srcs})
18+
if(${src} MATCHES "schema.cc$")
19+
get_filename_component(incl_path ${src} PATH)
20+
break()
21+
endif(${src} MATCHES "schema.cc$")
22+
get_filename_component(src_dir ${src} PATH)
23+
if(${src_dir} MATCHES "(type|entity)$")
24+
get_filename_component(incl_path ${src_dir} PATH)
25+
break()
26+
endif(${src_dir} MATCHES "(type|entity)$")
27+
endforeach(src ${sdai_srcs})
28+
if(NOT ${incl_path} EQUAL "")
29+
set(${out_path_var} ${incl_path} PARENT_SCOPE)
30+
else()
31+
message(WARNING "failed to locate incl dir for ${sdai_lib}, given ${sdai_srcs}")
32+
endif(NOT ${incl_path} EQUAL "")
33+
endfunction(get_sdai_incl_dir out_path_var sdai_target)
34+
735
# ${name} is used for the C++ file name (${name}.cc), and as the suffix for the target and test names
836
# ${sdai_lib} is the name of the schema lib that is used
937
# ${exe_args} are additional args for the test executable
10-
# two optional args: ARGV3, ARGV4 are compile flags and libs, respectively.
11-
function( add_schema_dependent_test name sdai_lib exe_args )
12-
# need the path to the lib sources for -I
13-
get_target_property( sdai_srcs sdai_${sdai_lib} SOURCES )
14-
15-
# -1 --> last item in list, which will be a file that isn't in a subdir
16-
list(GET sdai_srcs -1 fullpath )
17-
get_filename_component(sdai_src_path ${fullpath} PATH )
18-
19-
add_executable( tst_${name} "${name}.cc" )
20-
set_target_properties( tst_${name} PROPERTIES COMPILE_FLAGS "-I${sdai_src_path} ${ARGV3}" EXCLUDE_FROM_ALL ON )
21-
message(INFO "schema test ${name}: include '${sdai_src_path}'")
22-
if(NOT "${ARGV4}" MATCHES "NONE")
23-
DEFINE_DLL_IMPORTS( "tst_${name}" "${ARGV4}" )
24-
endif(NOT "${ARGV4}" MATCHES "NONE")
25-
target_link_libraries( tst_${name} sdai_${sdai_lib} ${ARGV4} )
26-
add_test( NAME build_cpp_${name}
38+
# three optional args: ARGV3, ARGV4, ARGV5 are include paths, compile flags, and libs, respectively.
39+
function(add_schema_dependent_test name sdai_lib exe_args )
40+
get_sdai_incl_dir(sdai_src_path ${sdai_lib})
41+
add_executable(tst_${name} "${name}.cc")
42+
set_target_properties(tst_${name} PROPERTIES EXCLUDE_FROM_ALL ON)
43+
set_property(TARGET tst_${name} APPEND PROPERTY INCLUDE_DIRECTORIES ${sdai_src_path} ${ARGV3} )
44+
if(NOT ${ARGV4} STREQUAL "")
45+
set_property(TARGET tst_${name} APPEND PROPERTY COMPILE_FLAGS ${ARGV4} )
46+
endif(NOT ${ARGV4} STREQUAL "")
47+
if(NOT "${ARGV5}" MATCHES "NONE")
48+
DEFINE_DLL_IMPORTS("tst_${name}" "${ARGV5}")
49+
endif(NOT "${ARGV5}" MATCHES "NONE")
50+
target_link_libraries(tst_${name} sdai_${sdai_lib} ${ARGV5})
51+
add_test(NAME build_cpp_${name}
2752
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
2853
COMMAND ${CMAKE_COMMAND} --build .
2954
--target tst_${name}
@@ -45,8 +70,7 @@ SCHEMA_CMLIST(${SC_SOURCE_DIR}/test/unitary_schemas/inverse_attr.exp)
4570
set(SC_ENABLE_TESTING ON)
4671

4772
add_schema_dependent_test( "aggregate_bound_runtime" "array_bounds_expr"
48-
"${SC_SOURCE_DIR}/test/p21/test_array_bounds.p21"
49-
"" "stepcore")
73+
"${SC_SOURCE_DIR}/test/p21/test_array_bounds.p21" "" "" "stepcore")
5074

5175
#can't use the macro for this one because it depends on the test above and needs WILL_FAIL
5276
add_test( NAME test_aggregate_bound_runtime_FAIL1
@@ -59,13 +83,17 @@ set_tests_properties( test_aggregate_bound_runtime_FAIL1 PROPERTIES
5983
add_schema_dependent_test( "inverse_attr1" "inverse_attr" "${SC_SOURCE_DIR}/test/p21/test_inverse_attr.p21" )
6084
add_schema_dependent_test( "inverse_attr2" "inverse_attr" "${SC_SOURCE_DIR}/test/p21/test_inverse_attr.p21" )
6185
add_schema_dependent_test( "inverse_attr3" "inverse_attr" "${SC_SOURCE_DIR}/test/p21/test_inverse_attr.p21"
62-
"-I${SC_SOURCE_DIR}/src/cllazyfile -I${SC_SOURCE_DIR}/src/base/judy/src" "steplazyfile" )
86+
"${SC_SOURCE_DIR}/src/cllazyfile;${SC_SOURCE_DIR}/src/base/judy/src" "" "steplazyfile" )
6387
add_schema_dependent_test( "attribute" "inverse_attr" "${SC_SOURCE_DIR}/test/p21/test_inverse_attr.p21" )
6488

6589
if(HAVE_STD_THREAD)
90+
if(UNIX)
91+
set(thread_flags "-pthread -std=c++0x" )
92+
set(thread_libs "pthread")
93+
endif(UNIX)
6694
# for best results, use a large file. as1-oc-214.stp is currently the largest file in the repo that sc works with.
67-
add_schema_dependent_test( "stepfile_rw_progress" "ap214e3"
68-
"${SC_SOURCE_DIR}/data/ap214e3/as1-oc-214.stp" "-pthread -std=c++0x" "pthread" )
95+
add_schema_dependent_test( "stepfile_rw_progress" "ap214e3" "${SC_SOURCE_DIR}/data/ap214e3/as1-oc-214.stp"
96+
"" "${thread_flags}" "${thread_libs}")
6997
endif(HAVE_STD_THREAD)
7098

7199
# Local Variables:

0 commit comments

Comments
 (0)