A might-be-sloppy resolution I came out is to use boost to transform 
SOURCE_DIR macro to string, which is
#include <boost/preprocessor/stringize.hpp>
...
void test ()
{
  ...
  std::string string_from_macro = BOOST_PP_STRINGIZE(SOURCE_DIR);
  ...
}

It worked, but as what I said, in a sloppy way. I'd be happy to see what 
you guys have in mind.

在 2018年2月5日星期一 UTC-8下午10:37:38,Weixiong Zheng写道:
>
> Thanks Matthias,
>
> What I've tried is to 
> ADD_DEFINITION(-DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}) in the 
> CMakeLists.txt in the test directory. I tried tesing SOURCE_DIR in *.cc 
> file like: std::cout << SOURCE_DIR << std::endl;
>
> When I did "make", screen printout shows: 
> "<command line>:2:20: note: expanded from here
>
> #define SOURCE_DIR /Users/GrillCheese/UCB/Research/xtrans/tests/mesh
>
> Following that it has errors like:
>
> */Users/GrillCheese/UCB/Research/xtrans/tests/mesh/mesh_generator_01.cc:57:17:
>  
> **error: **expected expression*
>
>  std::cout << (SOURCE_DIR) << std::endl;
> and
>
> */Users/GrillCheese/UCB/Research/xtrans/tests/mesh/mesh_generator_01.cc:57:17:
>  
> **error: **use of undeclared identifier 'Users'*
>
> *<command line>:2:21: **note: *expanded from here
>
> #define SOURCE_DIR /Users/GrillCheese/UCB/Research/xtrans/tests/mesh
> and other same type of error saying "use of undeclared identifier 'xxx'" 
> where xxx can be GrillCheese, UCB, Research etc.
>
> Anything obviously wrong to you?
>
> Thanks,
> Weixiong
>
>
>
> 在 2018年2月5日星期一 UTC-8下午9:25:22,Matthias Maier写道:
>>
>>
>> On Mon, Feb  5, 2018, at 22:15 CST, Weixiong Zheng <[email protected]> 
>> wrote: 
>>
>> > Hello All, 
>> > 
>> > I am trying to get unit test work for my project. It works until 
>> reaching 
>> > the point of reading input data. I tried to specify the directory using 
>> > getcwd() though it didn't work with ctest. I noticed there was another 
>> user 
>> > having the same issue and the resolution was to use SOURCE_DIR directly 
>> in 
>> > *.cc file. It turns out it was not recognized. Any quick idea how to 
>> fix it 
>> > would be appreciated. Thanks! 
>>
>> SOURCE_DIR is defined when compiling the *.cc file of a test [1]. For 
>> example, if you have the test layout 
>>
>>   my_test.cc 
>>   my_test.output 
>>
>> and you call DEAL_II_PICKUP_TESTS() in that subdirectory. In that case 
>> the my_test.cc file will be compiled with a compiler flag similar to 
>>
>>  -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} 
>>
>> It is not available in any other compilation unit (i.e. *.cc file). Or 
>> for the second class of tests where you specify a *.prm file [2]. 
>>
>> Best, 
>> Matthias 
>>
>> [1] The SOURCE_DIR preprocessor definition is set up in line 266 of the 
>> macro cmake/macros/macro_deal_ii_add_test.cmake. 
>>
>> [2] In this case a test gets the full path to the parameter file as 
>> first argument. So simply stripping of the filename should be enough to 
>> get the source directory of the tests. 
>>
>

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to