[CMake] CMake and directory creation

Joshua Jensen jjensen at workspacewhiz.com
Tue May 29 16:07:05 EDT 2007


So, I have an interesting problem when using CMake (latest CVS).

I set the EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH to be the 
following:

    SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/image CACHE PATH 
"Output location for LuaPlus libraries")
    SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/image CACHE PATH 
"Output location for LuaPlus executables")

The intended disk hierarchy is:

    * image/
        * LuaPlus.exe
        * modules/
            * assorted.dll/.dylib
            * mime/
                core.dll/.dylib

To accomplish this, I have the following CMake script for my modules.

    IF (CMAKE_GENERATOR MATCHES "Visual Studio")
        SET_TARGET_PROPERTIES(${TargetName} PROPERTIES PREFIX "../modules/")
        SET_TARGET_PROPERTIES(${TargetName} PROPERTIES DEBUG_POSTFIX 
".debug")
    ENDIF (CMAKE_GENERATOR MATCHES "Visual Studio")
    IF (CMAKE_GENERATOR MATCHES "NMake" OR CMAKE_GENERATOR MATCHES "Make")
        SET_TARGET_PROPERTIES(${TargetName} PROPERTIES PREFIX "modules/")
        SET_TARGET_PROPERTIES(${TargetName} PROPERTIES DEBUG_POSTFIX 
".debug")
    ENDIF (CMAKE_GENERATOR MATCHES "NMake" OR CMAKE_GENERATOR MATCHES 
"Make")
    IF (CMAKE_GENERATOR MATCHES "Xcode")
        SET_TARGET_PROPERTIES(${TargetName} PROPERTIES PREFIX "modules/")
    ENDIF(CMAKE_GENERATOR MATCHES "Xcode")

For an Xcode or Visual Studio, the entire hierarchy is created without 
issue, and the build succeeds.

For NMake projects, the build stops at modules/assorted.dll, because the 
modules/ directory doesn't exist.

For Make projects, the build stops at modules/mime/core.dll, because the 
modules/mime/core.dll directory doesn't exist.  Somehow, the modules/ 
directory gets created, and the modules/ DLLs are created fine.  The 
interesting bits from my CMakeLists.txt for core.dll are:

    GET_TARGET_PROPERTY(MODULE_PREFIX mime PREFIX)    # MODULE_PREFIX 
ends up being modules/
    SET_TARGET_PROPERTIES(mime PROPERTIES PREFIX 
${MODULE_PREFIX}mime/)    # Put it in modules/mime/
    SET_TARGET_PROPERTIES(mime PROPERTIES OUTPUT_NAME core)

To get around the NMake and Make issue, I have the following hack.  I 
don't like this hack, because those directories should be created at 
build time.  If the user destroys the image/ folder, the build will fail.

# Hacks for makefile projects.
FILE(MAKE_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}/modules")
FILE(MAKE_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}/modules/mime")

Is this a bug?  What are the workarounds?

If anyone wants to see this on their own, the Subversion repository is 
at svn://svn.luaplus.org/LuaPlus/work51.  My CMakeLists.txt conversion 
isn't complete yet, so bear with me.  If anyone has suggestions on the 
way I set things up, just say so.  I'm still very much a CMake newbie.

Thanks for your help.

Josh



More information about the CMake mailing list