[CMake] Force out of source build

Horacio Sanson hsanson at gmail.com
Fri Jun 6 10:18:21 EDT 2008


Thanks,

This is what I have now


MACRO(MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
    STRING(COMPARE EQUAL "${${PROJECT_NAME}_SOURCE_DIR}"
"${${PROJECT_NAME}_BINARY_DIR}" insource)
    GET_FILENAME_COMPONENT(PARENTDIR ${${PROJECT_NAME}_SOURCE_DIR} PATH)
    STRING(COMPARE EQUAL "${${PROJECT_NAME}_SOURCE_DIR}"
"${PARENTDIR}" insourcesubdir)
    IF(insource OR insourcesubdir)
        MESSAGE(FATAL_ERROR "${PROJECT_NAME} requires an out of source build.")
    ENDIF(insource OR insourcesubdir)
ENDMACRO(MACRO_ENSURE_OUT_OF_SOURCE_BUILD)


Then I simply call MACRO_ENSURE_OUT_OF_SOURCE_BUILD() just after I
define the project name with PROJECT().

I only have a minor problem that this macro still creates a
CMakeCache.txt file and a CMakeFiles directory. How would be the best
way to avoid these to be created or to delete them (in a portable way)
from the source directory??


thanks
Horacio

On Fri, Jun 6, 2008 at 10:36 PM, Mathieu Malaterre
<mathieu.malaterre at gmail.com> wrote:
> The macro is incomplete AFAIK. You might want to consider adding this too:
>
> http://www.cmake.org/pipermail/cmake/2008-March/020390.html
>
> On Fri, Jun 6, 2008 at 10:23 AM, hsanson <hsanson at gmail.com> wrote:
>> Andreas Schneider wrote:
>>>
>>> hsanson wrote:
>>>>
>>>> So how can I cause CMake to fail if I run it on the source directory??
>>>>
>>>
>>> Hi,
>>>
>>> try
>>>
>>>
>>> https://dev.csync.org/browser/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
>>
>> Thanks,
>>
>> The url above did not work for me but a Google search for
>> MacroEnsureOutOfSourceBuild gave me what I needed.
>>
>>>>
>>>> thanks
>>>> Horacio
>>>
>>>
>>>    -- andreas
>>>
>>
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
>>
>
>
>
> --
> Mathieu
>


More information about the CMake mailing list