I have a working project with CMake and Boost.Test with a directory structure like this (pardon the ASCII art):
+-proj
|---CMakeLists.txt
|---build
|---test
A possible solution to disambiguate names in a directory structure like the one you have using a FOREACH() over ${test_cases} may be:
# Set Cmake version and policy
CMAKE_MINIMUM_REQUIRED( VERSION 2.8.7 )
CMAKE_POLICY( VERSION 2.8.7 )
PROJECT( DUMMY CXX )
FILE( GLOB_RECURSE test_cases FOLLOW_SYMLINKS "test/*.[h,c]pp" )
FOREACH( case ${test_cases} )
## Get filename without extension
GET_FILENAME_COMPONENT(case_name_we ${case} NAME_WE)
## Get innermost directory name
GET_FILENAME_COMPONENT(case_directory ${case} PATH)
GET_FILENAME_COMPONENT(case_innermost ${case_directory} NAME_WE)
## Construct executable name
SET( exe_name "${case_innermost}_${case_name_we}")
## Construct test name
SET( test_name "${exe_name}_test")
## Add executable and test
ADD_EXECUTABLE( ${exe_name} ${case} )
ADD_TEST( ${test_name} ${exe_name} )
ENDFOREACH()
As you can see this CMakeLists.txt creates 4 distinct test/executable couples.