cmake-basis / legacy

Legacy CMake BASIS project for versions 3.2 and older. For newer versions, go to
https://github.com/cmake-basis/BASIS
Other
13 stars 11 forks source link

basis_add_subdirectory sometimes skips existing subdirectory #498

Closed ahundt closed 8 years ago

ahundt commented 8 years ago

If you create an example directory, and in it call basis_add_subdirectory(dirname) it will have no effect. If you switch that line to standard add_subdirectory() and in the subdirectory call basis_include_directories(.) with a header in ., then do the normal cmake build with makefiles and run make VERBOSE=1 you will see no -I/path/to/folder/that/was/dot, that is the include never went through properly to cmake. I've seen this in other directories too, and verified that BUILD_EXAMPLE ON and that the cmake code where basis_add_subdirectory(dirname) is called is actually being executed.

I believe I've seen this on both OS X and Linux with the latest CMake and cmake-basis.

schuhschuh commented 8 years ago

When you use basis_add_subdirectory, are you sure that subdirectory exists? When you add the following before the call to add_subdirectory, what does it print?

set(SUBDIR "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}")
message("SUBDIR=${SUBDIR}")
if (IS_DIRECTORY "${SUBDIR}")
  message ("Subdirectory ${SUBDIR} exists")
else ()
  message ("Subdirectory ${SUBDIR} missing")
endif ()

Those are the only reasons why basis_add_subdirectory would not give you the same result as add_subdirectory.

ahundt commented 8 years ago

yes, if I delete basis_ then it works correctly using the standard cmake call.

schuhschuh commented 8 years ago

Regarding basis_include_directories, it calls right on the first line CMake's include_directories with the given arguments. Maybe there is a problem with the latest CMake...

function (basis_include_directories)
  # CMake's include_directories ()
  _include_directories (${ARGN})
  # ...
endfunction ()
schuhschuh commented 8 years ago

yes, if I delete basis_ then it works correctly using the standard cmake call.

Well, but can you please add those lines to provide some more debug output ?

schuhschuh commented 8 years ago

I just encountered the same issue with basis_add_subdirectory. As it turns out, the problem is that within a macro, a variable is used which has the same name as the input argument of the macro, i.e.,

set(SUBDIR "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR}")

For some reason, this may sometimes not change SUBDIR and hence the following IS_DIRECTORY check fails when the path is not absolute.

ahundt commented 8 years ago

good to see I'm not crazy :-)

schuhschuh commented 8 years ago

Fixed in CMake BASIS Modules develop branch (see this commit).