Please allow specifying Visual C++ compiler flags in CMake

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Niels Dekker
Posts: 40
Joined: Thu, 2005-05-26, 17:11
Location: Leiden (work), Amsterdam (home)
Contact:

Please allow specifying Visual C++ compiler flags in CMake

#1 Post by Niels Dekker »

We are very pleased about the snapshots being regularly updated. However, it also causes some overhead on our side, having to locally patch each snapshot before we can use it. For example, we use different Visual C++ 2008 compiler flags as we statically link to the Microsoft Runtime Library (/MD, /MDd), while dcmtk-3.5.5_20100326/CMakeLists.txt specifies otherwise:

Code: Select all

      SET(CMAKE_CXX_FLAGS "/nologo /W3 /Gy /EHsc")
      SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
      SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
      SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2")
      SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
So we need to manually edit your CMakeLists.txt whenever we upgrade to a new snapshot. It would be very helpful to us if you could allow the users to specify their own compiler flags, within the cmake-gui. For example by placing your SET commands inside an IF...ENDIF as follows:

Code: Select all

SET(DCMTK_ALLOW_RESETTING_COMPILER_FLAGS ON CACHE BOOL
  "Allow DCMTK to overrule the CMake cache and reset the compiler flags")

IF(DCMTK_ALLOW_RESETTING_COMPILER_FLAGS)

# settings for Microsoft Visual C
   (Setting C flags according to DCMTK preferences...)
# settings for Microsoft Visual C++
   (Setting C++ flags according to DCMTK preferences...)

ENDIF(DCMTK_ALLOW_RESETTING_COMPILER_FLAGS)
In the code above, DCMTK_ALLOW_RESETTING_COMPILER_FLAGS is ON by default, enabling the DCMTK preferences as before. But it allows users to switch off DCMTK_ALLOW_RESETTING_COMPILER_FLAGS, and specify their own compiler flags instead.

I think it's a very small change (4 lines of code), but it would be very helpful. Do you think it would be feasible for you to modify DCMTK in such a way?
Niels Dekker
Scientific programmer at LKEB, Leiden University Medical Center, The Netherlands

Michael Onken
DCMTK Developer
Posts: 2072
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

#2 Post by Michael Onken »

Hi Niels,

we will discuss that with the team after the easter days.

In my opinion, there is no reason why we should forbid people to change any CMake flags if they explicitly want to. If I remember correctly, there was some reason why the reset was integrated (bug in CMake?!), but that was just before my time at OFFIS and I don't remember the explanation ;)

Best regards,
Michael

Niels Dekker
Posts: 40
Joined: Thu, 2005-05-26, 17:11
Location: Leiden (work), Amsterdam (home)
Contact:

#3 Post by Niels Dekker »

Thank you, Michael. Of course, we wouldn't mind if you would just remove all those SET commands:

Code: Select all

# settings for Microsoft Visual C
IF(CMAKE_C_COMPILER MATCHES "CL|cl")
  IF(NOT WITH_SHARED_LIBS)
    IF(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
      SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX")
      SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
      SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
      SET(CMAKE_C_FLAGS_MINSIZEREL "/MT /O2")
      SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
    ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
    IF(CMAKE_GENERATOR STREQUAL "Visual Studio 7" OR CMAKE_GENERATOR STREQUAL "Visual Studio 7 .NET 2003")
      SET(CMAKE_C_FLAGS "/nologo /W3 /Gy")
      SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
      SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
      SET(CMAKE_C_FLAGS_MINSIZEREL "/MT /O2")
      SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
    ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 7" OR CMAKE_GENERATOR STREQUAL "Visual Studio 7 .NET 2003")
    IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
      SET(CMAKE_C_FLAGS "/nologo /W3 /Gy /EHsc")
      SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
      SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
      SET(CMAKE_C_FLAGS_MINSIZEREL "/MT /O2")
      SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
    ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
  ENDIF(NOT WITH_SHARED_LIBS)
ENDIF(CMAKE_C_COMPILER MATCHES "CL|cl")

# settings for Microsoft Visual C++
IF(CMAKE_CXX_COMPILER MATCHES "CL|cl")
  IF(NOT WITH_SHARED_LIBS)
    IF(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
      SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX")
      SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
      SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
      SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2")
      SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
    ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
    IF(CMAKE_GENERATOR STREQUAL "Visual Studio 7" OR CMAKE_GENERATOR STREQUAL "Visual Studio 7 .NET 2003")
      SET(CMAKE_CXX_FLAGS "/nologo /W3 /Gy")
      SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
      SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
      SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2")
      SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
    ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 7" OR CMAKE_GENERATOR STREQUAL "Visual Studio 7 .NET 2003")
    IF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
      SET(CMAKE_CXX_FLAGS "/nologo /W3 /Gy /EHsc")
      SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
      SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
      SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2")
      SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
    ENDIF(CMAKE_GENERATOR STREQUAL "Visual Studio 8 2005" OR CMAKE_GENERATOR STREQUAL "Visual Studio 9 2008")
  ENDIF(NOT WITH_SHARED_LIBS)
ENDIF(CMAKE_CXX_COMPILER MATCHES "CL|cl")
But we weren't sure if you would still need to have them in there. That's why we proposed to at least allow users to switch them off.

Happy Easter days!
Niels
Niels Dekker
Scientific programmer at LKEB, Leiden University Medical Center, The Netherlands

Niels Dekker
Posts: 40
Joined: Thu, 2005-05-26, 17:11
Location: Leiden (work), Amsterdam (home)
Contact:

#4 Post by Niels Dekker »

Hi Michael,

The latest snapshot (dcmtk-3.5.5_20100504) still resets the Microsoft Visual C++ compiler flags, even when we specify different compiler flags within cmake-gui.

Did you still have time to discuss the CMakeLists, as you planned to do after the easter days?
Niels Dekker
Scientific programmer at LKEB, Leiden University Medical Center, The Netherlands

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#5 Post by Jörg Riesmeier »

Just done. Thanks again for the suggestion.

Niels Dekker
Posts: 40
Joined: Thu, 2005-05-26, 17:11
Location: Leiden (work), Amsterdam (home)
Contact:

#6 Post by Niels Dekker »

Hi Jörg,

Thanks for adding the OVERWRITE_COMPILER_FLAGS option (and allowing us to switch it off :D ). I just downloaded DCMTK from http://git.dcmtk.org and gave it a try. The option works well.

For what it's worth, personally I would add a DCMTK specific prefix, and name it e.g., "DCMTK_OVERWRITE_COMPILER_FLAGS". cmake-gui.exe groups all options that have the same prefix, so by doing so, all DCMTK options could be nicely grouped together. But that's just a minor issue, of course. Thanks again!
Niels Dekker
Scientific programmer at LKEB, Leiden University Medical Center, The Netherlands

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#7 Post by Jörg Riesmeier »

Thank you for the feedback. I understand why the "DCMTK_" prefix would be desirable, but we still prefer to have the names of flags and options close to the ones used for GNU autoconf on Unix systems. Furthermore, the CMake project files will probably be reworked completely sometimes in the near future in order to also support non-Windows systems. This does not mean that we will drop the well-establised GNU autoconf mechanism soon.

Btw, we use the admittedly ugly overwriting of compiler flags for various Windows compilers in order to make sure that the command line tools are always linked statically. This way, the binaries should work on more Windows platforms because of less dependencies ...

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest