I'm a newcomer to cmake so if I'm missing something obvious please point it 
out.  Having said that, despite reading the online documentation and doing a 
fair amount of googling I haven't found a solution. 


Specific Questions
====================
1) Is there a target/generator or some other configuration that will allow 
'automatic' building of CLR targets with the appropriate compiler flags?
2) Is there a recipe for removing flags from COMPILE_FLAGS so I can build my 
own options?
3) Is CMAKE_CXX_FLAGS the correct variable to tweak for Visual Studio 2010 
compilation flags ?  If so, can you suggest a reason why the recipe I'm using 
below isn't producing the desired results ?


Background to Problem
======================

We have some C code which can be either compiled into an embedded target or 
built into an emulation of that target running under .Net on windows.  Cmake 
seems like it would be a good solution to allow us to maintain a single set of 
project configurations and we've already successfully converted the embedded 
target configuration to cmake.

For windows 7, when running under .net, there are a number of specific compiler 
flags that need to be used to correctly build the project...

/CLR - used to indicate that this is a CLR target
/TP - used to indicate that '.c' files should be treated as c++
/FUpathToDll - used to indicate that namespaces and unresolved references may 
be found within the specified dll

I've generated a minimal test project using 
>cmake -G " Visual Studio 10 Win64" (Note cmake is 2.8.4)
and have created a CMakeList.text that includes

cmake_minimum_required (VERSION 2.6)
project (test)
add_subdirectory("src")
set_source_files_properties(src/main.c PROPERTIES COMPILE_FLAGS "/CLR /TP 
/FUotherstuff.dll")
add_executable(test src/main.c)

There is a also an empty cmakelists.txt in the src subdirectory to keep cmake 
happy.

The problem is that when trying to build ALL_BUILDS, cmake's idea of which 
compiler flags to use is not compatible with the additional flags I'd like to 
use.  Here's some sample output. 

Note the error "cl : Command line error D8016: '/RTC1' and '/clr' command-line 
options are incompatible"


-----------------------
C:\work\cmaketest>msbuild ALL_BUILD.vcxproj
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 07/04/2011 13:06:03.
Project "C:\work\cmaketest\ALL_BUILD.vcxproj" on node 1 (default targets).
Project "C:\work\cmaketest\ALL_BUILD.vcxproj" (1) is building 
"C:\work\cmaketest\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
InitializeBuildStatus:
  Creating "Win32\Debug\ZERO_CHECK\ZERO_CHECK.unsuccessfulbuild" because 
"AlwaysCreate" was specified.
CustomBuild:
  All outputs are up-to-date.
FinalizeBuildStatus:
  Deleting file "Win32\Debug\ZERO_CHECK\ZERO_CHECK.unsuccessfulbuild".
  Touching "Win32\Debug\ZERO_CHECK\ZERO_CHECK.lastbuildstate".
Done Building Project "C:\work\cmaketest\ZERO_CHECK.vcxproj" (default targets).

Project "C:\work\cmaketest\ALL_BUILD.vcxproj" (1) is building 
"C:\work\cmaketest\test.vcxproj" (3) on node 1 (default targets).
InitializeBuildStatus:
  Touching "test.dir\Debug\test.unsuccessfulbuild".
CustomBuild:
  All outputs are up-to-date.
ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /Zi 
/nologo /W3 /WX- /Od /Ob0 /Oy- /D WIN32 /D _WINDOWS /D _DEBUG /D 
"CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t 
/Zc:forScope /Fo"test.dir\Debug\\" /Fd"C:/work/cmaketest/Debug/test.pdb" /Gd 
/TP /FUotherstuff.dll /analyze- /errorReport:queue src\main.c  /CLR  /Zm1000
cl : Command line error D8016: '/RTC1' and '/clr' command-line options are 
incompatible [C:\work\cmaketest\test.vcxproj]
Done Building Project "C:\work\cmaketest\test.vcxproj" (default targets) -- 
FAILED.

Done Building Project "C:\work\cmaketest\ALL_BUILD.vcxproj" (default targets) 
-- FAILED.


Build FAILED.

"C:\work\cmaketest\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\work\cmaketest\test.vcxproj" (default target) (3) ->
(ClCompile target) ->
  cl : Command line error D8016: '/RTC1' and '/clr' command-line options are 
incompatible [C:\work\cmaketest\test.vcxproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.21
------------------------

This link: http://www.mail-archive.com/[email protected]/msg34975.html and this 
link http://www.cmake.org/pipermail/cmake/2010-June/037346.html suggest that 
modifying CMAKE_CXX_FLAGS will allow the removal of the conflicting flags.  
Unfortunately I can't get this to work at all.  The following cmakelist.txt...
----
cmake_minimum_required (VERSION 2.6)
project (test)

STRING(REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
STRING(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /clr")

add_subdirectory("src")
add_executable(test src/main.c)
---

Still results in this clcompile step (note incorrect flags)

ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\CL.exe 
/c /Zi /nologo /W3 /WX- /Od /Ob0 /D WIN32 /D _WINDOWS /D _DEBUG /D 
"CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS  /fp:precise /Zc:wchar_t 
/Zc:forScope /Fo"test.dir\Debug\\" /Fd"C:/work/cmaketest/Debug/test.pdb" /Gd 
/TC /errorReport:queue src\main.c  /Zm1000  main.c 

I've also tried likely permutations of the above, reordering of the step etc 
without any luck.

 Thanks in advance for any help you can offer,

  Neil




_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to