[CMake] Ctest applied in a sub dir
Michael Hertling
mhertling at online.de
Sun Oct 24 12:16:49 EDT 2010
On 10/24/2010 12:18 PM, Yann COLLETTE wrote:
> Hello,
>
> I have used cmake to build an executable (which is
> ${CMAKE_EXECUTABLE_DIR}/myprog.exe).
> I wanted to use ctest to test my executable. But I need to execute this
> program in specific directories with various data set (in
> ${CMAKE_SOURCE_DIR}/tests/first_test for example).
>
> Is it possible to do this with ctest ?
You might use "cmake -E chdir" as a simple test driver:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(CWD C)
ENABLE_TESTING()
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "
#include<unistd.h>
#include<stdio.h>
int main(void)
{
char cwd[1000];
getcwd(cwd,sizeof cwd);
printf(\"CWD: %s\\n\",cwd);
return 0;
}
")
ADD_EXECUTABLE(main main.c)
ADD_TEST(NAME maintest
COMMAND ${CMAKE_COMMAND} -E chdir /var/tmp $<TARGET_FILE:main>)
So, "ctest -V" issues "1: CWD: /var/tmp"; adapt for non-*nices.
Regards,
Michael
More information about the CMake
mailing list