[Cmake] Including default rules in CMakeLists.txt

Andy Cedilnik andy . cedilnik at kitware . com
18 Aug 2003 07:49:33 -0400


Hi Alex,

There is no way of doing that. This is just the rule in CMake. All rules
are absolute, so you have to specify the source and action.

If you want to use .cc files, and you want to use Visual Studio 6, you
will also have to hack the registry.

Here is the code:

# Check if we are running Microsoft compilers, in that case we will need
# to force some files (.cc, .cpp) to be compiled as C++ files using the
-TP 
flag

MACRO (GET_SPECIAL_COMPILE_FLAGS_TO_FORCE_CPP VAR)
  GET_FILENAME_COMPONENT (
    CMAKE_PLATFORM_FILENAME_WE
    ${CMAKE_SYSTEM_AND_C_COMPILER_INFO_FILE}
    NAME_WE
  )
  IF (CMAKE_PLATFORM_FILENAME_WE MATCHES "Windows-cl")
    SET (${VAR} " -TP")
  ELSE (CMAKE_PLATFORM_FILENAME_WE MATCHES "Windows-cl")
    SET (${VAR} "")
  ENDIF (CMAKE_PLATFORM_FILENAME_WE MATCHES "Windows-cl")
ENDMACRO (GET_SPECIAL_COMPILE_FLAGS_TO_FORCE_CPP VAR)

# Fix the registery for MsDev6 so that .cc/.cpp files can be compiled
MACRO (FIX_MSDEV_EXTENSION_SUPPORT_IN_REGISTRY EXT)
  IF(CMAKE_GENERATOR MATCHES "Visual Studio 6")
    SET (REG_KEY 
"HKEY_CURRENT_USER\\Software\\Microsoft\\DevStudio\\6.0\\Build 
System\\Components\\Platforms\\Win32 (x86)\\Tools\\32-bit C/C++ Compiler
for 80x86;Input_Spec")
    GET_FILENAME_COMPONENT (INPUT_SPEC "[${REG_KEY}]" NAME)
    IF ("${INPUT_SPEC}" MATCHES "^registry$")
    ELSE ("${INPUT_SPEC}" MATCHES "^registry$")
      IF ("${INPUT_SPEC}" MATCHES ";\\*\\${EXT}")
      ELSE ("${INPUT_SPEC}" MATCHES ";\\*\\${EXT}")
        MESSAGE("The registry key ${REG_KEY}\nhas been fixed so that
Msdev 
can support the file extension ${EXT}")
        EXEC_PROGRAM(${CMAKE_COMMAND}
                    ARGS "-E write_regv \"${REG_KEY}\" 
\"${INPUT_SPEC};*${EXT}\""
        )
      ENDIF ("${INPUT_SPEC}" MATCHES ";\\*\\${EXT}")
    ENDIF ("${INPUT_SPEC}" MATCHES "^registry$")
  ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 6")
ENDMACRO (FIX_MSDEV_EXTENSION_SUPPORT_IN_REGISTRY)

FIX_MSDEV_EXTENSION_SUPPORT_IN_REGISTRY(".cc")
GET_SPECIAL_COMPILE_FLAGS_TO_FORCE_CPP (SPECIAL_COMPILE_FLAGS)

FOREACH (sfile
  dcmhmod.cc
  dcstrmpl.cc
  )
  SET (SRCS ${SRCS}  ${sfile})
  IF (SPECIAL_COMPILE_FLAGS)
    SET_SOURCE_FILES_PROPERTIES (${sfile}
                                 COMPILE_FLAGS ${SPECIAL_COMPILE_FLAGS})
  ENDIF (SPECIAL_COMPILE_FLAGS)
ENDFOREACH (sfile)

			Andy

On Mon, 2003-08-18 at 06:57, Alejandro Frangi wrote:
>  Is there any way to define in the CMakeLists.txt file default rules
> like those of Makefile?
> 
>  For instance, if I want that in a given directory, every .cc is turned
> into an executable, how should I state that?
> 
>  Thanks for a prompt reply,