[CMake] Visual Studio generator running custom_command twice

2019-03-13 Thread Paul Smith
I have a situation where I've created a custom command to generate .cpp
files to be compiled (in my case running bison/flex).

I'm using CMake 3.13.4

However, I have to compile this code in two different ways for two
different targets.  I am seeing the Visual Studio generator re-running
bison/flex once for each of these targets, which is (a) not necessary
and (b) causes my builds to fail since it often happens that the second
run can't replace the output files (due to Windows' annoying habit of
locking files that are open).

I have a custom command like this:

 add_custom_command(OUTPUT
  ${OUT_DIR}/MyParser.tab.cpp
  ${OUT_DIR}/MyParser.tab.hpp
  COMMAND ${CMAKE_COMMAND} -E make_directory ${OUT_DIR}
  COMMAND ${BISON} -d -o ${OUT_DIR}/MyParser.tab.cpp MyParser.y
  DEPENDS MyParser.y
  COMMENT "Building MyParser parser")

  set(MyParserOutput
  ${OUT_DIR}/MyParser.tab.cpp
  ${OUT_DIR}/MyParser.tab.hpp)

  add_custom_target(MyGenParser DEPENDS ${MyParserOutput})

Then I have two different libraries, both depending on this:

  add_library(OneLib STATIC ${MyParserOutput} ...)

  target_compile_definitions(OneLib PRIVATE -DONELIB)

  target_include_directories(OneLib PRIVATE ${OUT_DIR})

  add_dependencies(OneLib MyGenparser)


  add_library(TwoLib STATIC ${MyParserOutput} ...)

  target_compile_definitions(TwoLib PRIVATE -DTWOLIB)

  target_include_directories(TwoLib PRIVATE ${OUT_DIR})

  add_dependencies(TwoLib MyGenparser)


On Linux and MacOS, this works fine.  However on Windows with Visual
Studio I see the custom target being run twice, once for each library:

  18:27:10 21>PrepareForBuild:
  18:27:10  Creating directory "OneLib.dir\RelWithDebInfo\".
  18:27:10  Creating directory "OneLib.dir\RelWithDebInfo\OneLib.tlog\".
  18:27:10InitializeBuildStatus:
  18:27:10  Creating 
"OneLib.dir\RelWithDebInfo\OneLib.tlog\unsuccessfulbuild" because 
"AlwaysCreate" was specified.
  18:27:10ComputeCustomBuildOutput:
  18:27:10  Creating directory "D:\builds\src\".
  18:27:10CustomBuild:
  18:27:10  Building MyParser parser

Then again later:

  18:27:20 69>PrepareForBuild:
  18:27:20  Creating directory "TwoLib.dir\RelWithDebInfo\".
  18:27:20  Creating directory "TwoLib.dir\RelWithDebInfo\TwoLib.tlog\".
  18:27:20InitializeBuildStatus:
  18:27:20  Creating 
"TwoLib.dir\RelWithDebInfo\TwoLib.tlog\unsuccessfulbuild" because 
"AlwaysCreate" was specified.
  18:27:20CustomBuild:
  18:27:20  Building MyParser parser

See how this second one is re-building the parser; then this fails
because the output file is locked by Windows (in use by the compiler):

  18:27:21 69>CustomBuild:
  18:27:21  bison.exe: could not create D:/builds/src/MyParser.tab.cpp
  18:27:25 69>C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(209,5):
 error MSB6006: "cmd.exe" exited with code 1. [D:\builds\TwoLib.vcxproj]

How can I get CMake to only run the bison command one time, then use
the output for two different libraries?

-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

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


Re: [CMake] further configuration of generated projects outside of CMake?

2019-03-13 Thread hex

I see now the generators are part of CMake sources on gitlab...

that answers my questions.

thank you, Zan Lynx.




On March 11, 2019 6:03:24 PM MDT, hex  wrote:



Another question, I didn't know there is a generator for sublime text 2:

https://cmake.org/cmake/help/latest/generator/Sublime%20Text%202.html

Is the source code for generators available? I think it would be fun 
adding some improvements.


best regards! 

--

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

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


[CMake] cmake and high-dpi support on Mac

2019-03-13 Thread René J . V . Bertin
Hi,

CMake had hardcoded default support for high-dpi screens in the applications it 
generated for Apple's desktop OS at some point, but that was removed very 
quickly in 286c75f7f034c5fdcd43bcb755da74d09c809642.

It is my understanding that you don't actually need to set the high-dpi key 
explicitly, but that it defaults to on for the desktop OS. IOW, it's enough to 
set the NSPrincipalClass property to NSApplication.

I cannot check this myself, and I have no idea if and how NSPrincipalClass can 
be set for Apple's other OS variants.
But maybe one could use this property in a minimal-change change to enable 
high-dpi support automatically in applications that do not provide their own 
Info.plist: add this to the bundle plist template:

+   NSPrincipalClass
+   <${MACOSX_BUNDLE_PRINCIPALCLASS}/>

If the target OS is known when the MACOSX_BUNDLE_* variables get their default, 
MACOSX_BUNDLE_PRINCIPALCLASS could default to whatever class is appropriate for 
the target OS, otherwise it would just be set to NSApplication (and users 
targetting other OS variants would have to set the property explicitly, which 
is still less cumbersome than providing a custom template).

Thoughts please?
Thanks,
R.


-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

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