[CMake] Generate *.cpp/*.hpp with add_custom_command, reference these in add_library in another subdirectory/CMakeLists?
Hi, I'm generating a *.cpp/*.hpp pair of files using add_custom_command() + add_custom_target(). These are then referenced in add_library() to be compiled and linked into a library, together with some "static" source-files. This works well as long as both parts (generating and creating the library) are in the same CMakeLists. This is also stated in the documentation [1]: {{{ A target created in the same directory (CMakeLists.txt file) that specifies any output of the custom command as a source file is given a rule to generate the file using the command at build time. }}} My question: Is there a way to split the generating and compiling into different subdirectories/CMakeLists, and specify the "rule to generate the file" manually for the add_library() target? The problem: At the time the add_library() is processed by cmake, the referenced *.cpp/*.hpp files are not yet created, hence they are not found ("Cannot find source file"). Adding the generate-target to ALL does not help, as at the target is executed to create the file _after_ the add_library() call is processed. Any hints? Greetings and thanks for your efforts. [1] http://cmake.org/cmake/help/v2.8.7/cmake.html#command:add_custom_command -- 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: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Generate *.cpp/*.hpp with add_custom_command, reference these in add_library in another subdirectory/CMakeLists?
On 01/10/2014 11:21 AM, Martin Zenzes wrote: The problem: At the time the add_library() is processed by cmake, the referenced *.cpp/*.hpp files are not yet created, hence they are not found ("Cannot find source file"). Adding the generate-target to ALL does not help, as at the target is executed to create the file _after_ the add_library() call is processed. Any hints? I think against the "Cannot find source file" problem it would help to set the "GENERATED" source file property. add_dependencies(mylibrary mycustomtarget) should make sure they are build in the right order. Nils -- 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: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] "find_package(MPI)" overriding "set(MPIEXEC)" in CmakeList.txt
Hi, Did Den 09. jan. 2014 22:49, skrev Pettey . Lucas: > Hello, > > On a Cray XE6, I am using find_package(MPI REQUIRED) in my CMakeLists.txt. It > correctly finds all of the MPI stuff, except that it sets the MPIEXEC to the > login node mpiexec command. I would like to override this behavior and set > the MPIEXEC command to the "aprun" wrapper, but it is not working. I have > tried using set(MPIEXEC "aprun") both before and after the find_package(MPI > REQUIRED) in my CMakeLists.txt. > > Thanks > Lucas Hi, Did you try to use find_program? I think this will "override" the find_program inside FindMPI.cmake: find_program(MPIEXEC aprun) find_package(MPI REQUIRED) message("MPI exec: ${MPIEXEC}") Cheers, Yngve -- 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: http://www.cmake.org/mailman/listinfo/cmake
[CMake] boostrap error - borked cmConfigure.h [v2.8.12.1]
Hi, I'm trying to compile 2.8.12.1, but I keep bumping into an error: [...] /tmp/cmake-2.8.12.1/Bootstrap.cmk/cmConfigure.h:27:24: warning: missing terminating " character [enabled by default] "8define CMAKE_DATA_DIR "/share/cmake-2 [...] This seems to be caused by a rather messed up-looking cmConfigure.h: [...] /* #undef CMAKE_NO_ANSI_STRING_STREAM */ /* #undef CMAKE_NO_ANSI_FOR_SCOPE */ #define CMAKE_ROOT_DIR "/home/pszilard/tmp/cmake-2.8.12.1" #define CMAKE_DATA_DIR "/share/cmake-2^M.8^M" #define CMAKE_BOOTSTRAP Note that I've manually added the "^M" control characters which would show up as newlines when pasted into the mail client. I've tried running on both an Ubuntu 10.04 and 12.04 machine with different compiler versions, but of course, no compiler swallowed this broken include file. Any ideas what's going on? Cheers, -- Szilárd -- 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: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] boostrap error - borked cmConfigure.h [v2.8.12.1]
Found a workaround: $ find /tmp/cmake-2.8.12.1 -type f | xargs dos2unix This must be a bug, should I file a report? -- Szilárd On Fri, Jan 10, 2014 at 1:21 PM, Szilárd Páll wrote: > Hi, > > I'm trying to compile 2.8.12.1, but I keep bumping into an error: > [...] > /tmp/cmake-2.8.12.1/Bootstrap.cmk/cmConfigure.h:27:24: warning: > missing terminating " character [enabled by default] > "8define CMAKE_DATA_DIR "/share/cmake-2 > [...] > > This seems to be caused by a rather messed up-looking cmConfigure.h: > [...] > /* #undef CMAKE_NO_ANSI_STRING_STREAM */ > /* #undef CMAKE_NO_ANSI_FOR_SCOPE */ > #define CMAKE_ROOT_DIR "/home/pszilard/tmp/cmake-2.8.12.1" > #define CMAKE_DATA_DIR "/share/cmake-2^M.8^M" > #define CMAKE_BOOTSTRAP > > Note that I've manually added the "^M" control characters which would > show up as newlines when pasted into the mail client. > > I've tried running on both an Ubuntu 10.04 and 12.04 machine with > different compiler versions, but of course, no compiler swallowed this > broken include file. > > Any ideas what's going on? > > Cheers, > -- > Szilárd -- 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: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] boostrap error - borked cmConfigure.h [v2.8.12.1]
On 01/10/2014 02:16 PM, Szilárd Páll wrote: Found a workaround: $ find /tmp/cmake-2.8.12.1 -type f | xargs dos2unix This must be a bug, should I file a report? Did you use the "Windows Source" zip file instead of the "Unix/Linux Source" tar.gz/tar.Z? Nils -- 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: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Fwd: Visual Studio command line from CMake
This approach should work... *but* you should always use the full path name to any custom commands. So the "runthis.bat" should be: "${CMAKE_CURRENT_BINARY_DIR}/runthis.bat" or "/runthis.bat" Glad you got it working with CMake, though. -Original Message- From: Rob McDonald To: CMake ML Sent: Thu, Jan 9, 2014 6:48 pm Subject: Re: [CMake] Fwd: Visual Studio command line from CMake All, Thanks for all the help, I'm getting closer. My current approach does this CMAKE_MINIMUM_REQUIRED( VERSION 2.8 ) INCLUDE( ExternalProject ) SET( VS_MAKEFILE_ZIP vsnet-makefiles.0.85.zip ) IF( MSVC ) IF( MSVC_VERSION EQUAL 1200 ) SET( VS_TOOLS_PATH $ENV{VS60COMNTOOLS} ) SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat ) ELSEIF( MSVC_VERSION EQUAL 1300 ) SET( VS_TOOLS_PATH $ENV{VS70COMNTOOLS} ) SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat ) ELSEIF( MSVC_VERSION EQUAL 1310 ) SET( VS_TOOLS_PATH $ENV{VS71COMNTOOLS} ) SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat ) ELSEIF( MSVC_VERSION EQUAL 1400 ) SET( VS_TOOLS_PATH $ENV{VS80COMNTOOLS} ) SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat ) ELSEIF( MSVC_VERSION EQUAL 1500 ) SET( VS_TOOLS_PATH $ENV{VS90COMNTOOLS} ) SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat ) ELSEIF( MSVC_VERSION EQUAL 1600 ) SET( VS_TOOLS_PATH $ENV{VS100COMNTOOLS} ) SET( VS_ENV_BAT ${VS_TOOLS_PATH}vsvars32.bat ) ELSEIF( MSVC_VERSION EQUAL 1700 ) SET( VS_TOOLS_PATH $ENV{VS110COMNTOOLS} ) SET( VS_ENV_BAT ${VS_TOOLS_PATH}VsDevCmd.bat ) ELSEIF( MSVC_VERSION EQUAL 1800 ) SET( VS_TOOLS_PATH $ENV{VS120COMNTOOLS} ) SET( VS_ENV_BAT ${VS_TOOLS_PATH}VsDevCmd.bat ) ENDIF( MSVC_VERSION EQUAL 1200 ) ENDIF ( MSVC ) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/opts.txt "R V") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/runthis.bat "call \"${VS_ENV_BAT}\" gmake < opts.txt") ExternalProject_Add( FLTK URL ${CMAKE_SOURCE_DIR}/fltk-1.3.2-source.tar UPDATE_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/${VS_MAKEFILE_ZIP} /${VS_MAKEFILE_ZIP} COMMAND ${CMAKE_COMMAND} -E tar -xzf /${VS_MAKEFILE_ZIP} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/opts.txt /opts.txt COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/runthis.bat /runthis.bat PATCH_COMMAND "" CONFIGURE_COMMAND runthis.bat BUILD_COMMAND "" INSTALL_COMMAND "" BUILD_IN_SOURCE 1 ) It doesn't fully work. -- I create the opts.txt and runthis.bat files in CMAKE_CURRENT_BINARY_DIR and then copy them to . I couldn't figure out how to write them within ExternalProject_Add and doesn't exist before unless I want to reset its value. Suggestions Welcome. -- opts.txt and runthis.bat end up where I want them and contain what I want. -- If you double-click runthis.bat, it successfully builds FLTK. -- However, running 'runthis.bat' from inside ExternalProject fails. I've tried 'cmd runthis.bat' '/runthis.bat' and a few other things, none work. I think it may be a problem with the command to run the batch program doesn't create a new environment, or doesn't keep the environment variables set by vsvars32.bat. Suggestions Welcome. Rob P.S. The mess of IF code to detect the MSVC version and use the environment variable has not been vetted and is mostly a guess at this point. From all the googling I could do, it is probably closeish to right. P.P.S. vsvarsall.bat Is special because it lets you set 32/64/arm target and also 32/64 host environments. I would like to support 32/64 target, but you can't set target without knowing the host environment. Is there a CMake way to detect whether the Visual Studio host environment is 32/64 bit? On Thu, Jan 9, 2014 at 10:48 AM, Rob McDonald wrote: Correct, this is one of the concerns that makes it more complex than just searching for the first vcvarsall.bat you come to. I'd like to match up the vcvarsall to the version of visual studio currently in use by CMake. I think there are now enough pieces that I can write a CMake 'FindVSEnvironment.cmake'. While I can't test it for a large number of MSVC versions, I'll post it and hopefully others can help out. Rob On Thu, Jan 9, 2014 at 6:44 AM, John Drescher wrote: > Why not just write your own batch ('buildit.bat') file that does: > > call vcvarsall.bat > nmake > > (or whatever the command to build in the VS command prompt is...) > > And then your command to build is: > > C:/full/path/to/buildit.bat > > It's presumably in a Windows-specific chunk of your CMakeLists anyway, so > that should work fairly simply. I think the part of problem would be figuring out what vcvarsall.bat to run especially if you have more than 1 version of Visual Studio. John -- 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
Re: [CMake] boostrap error - borked cmConfigure.h [v2.8.12.1]
Hi, On Fri, Jan 10, 2014 at 2:16 PM, Szilárd Páll wrote: > Found a workaround: > $ find /tmp/cmake-2.8.12.1 -type f | xargs dos2unix > > This must be a bug, should I file a report? > Did you use the .zip file of the CMake sources? That one is intended to be used for Windows and hence contains Windows lineendings. Thus its not surprising that you have to convert that to unix first, not all *nix tools can handle windows lineendings. Alternatively you can use the *.tar.* download of the CMake sources. Andreas -- 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: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] "find_package(MPI)" overriding "set(MPIEXEC)" in CmakeList.txt
That did not work. It still brings up the "mpiexec" from the operating system rather than the "aprun" job script submission command. Curiously, manually changing MPIEXEC in the CCMake Advanced screen works and is preserved throughout the configuration and Makefile generation process. I would really like to set up Cmake so that users don't have to change anything in the Advanced menu. Any other ideas are appreciated. Thanks Lucas From: cmake-boun...@cmake.org [cmake-boun...@cmake.org] on behalf of Yngve Inntjore Levinsen [yngve.levin...@gmail.com] Sent: Friday, January 10, 2014 5:33 AM To: Pettey . Lucas; cmake@cmake.org Subject: Re: [CMake] "find_package(MPI)" overriding "set(MPIEXEC)" in CmakeList.txt Hi, Did Den 09. jan. 2014 22:49, skrev Pettey . Lucas: > Hello, > > On a Cray XE6, I am using find_package(MPI REQUIRED) in my CMakeLists.txt. It > correctly finds all of the MPI stuff, except that it sets the MPIEXEC to the > login node mpiexec command. I would like to override this behavior and set > the MPIEXEC command to the "aprun" wrapper, but it is not working. I have > tried using set(MPIEXEC "aprun") both before and after the find_package(MPI > REQUIRED) in my CMakeLists.txt. > > Thanks > Lucas Hi, Did you try to use find_program? I think this will "override" the find_program inside FindMPI.cmake: find_program(MPIEXEC aprun) find_package(MPI REQUIRED) message("MPI exec: ${MPIEXEC}") Cheers, Yngve -- 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: http://www.cmake.org/mailman/listinfo/cmake This electronic message transmission and any attachments that accompany it contain information from DRC® (Dynamics Research Corporation) or its subsidiaries, or the intended recipient, which is privileged, proprietary, business confidential, or otherwise protected from disclosure and is the exclusive property of DRC and/or the intended recipient. The information in this email is solely intended for the use of the individual or entity that is the intended recipient. If you are not the intended recipient, any use, dissemination, distribution, retention, or copying of this communication, attachments, or substance is prohibited. If you have received this electronic transmission in error, please immediately reply to the author via email that you received the message by mistake and also promptly and permanently delete this message and all copies of this email and any attachments. We thank you for your assistance and apologize for any inconvenience. -- 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: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] boostrap error - borked cmConfigure.h [v2.8.12.1]
Indeed, I did (accidentally) download the .zip package. I was rather annoyed that the bootstrap script did not have executable permission set, but it did not ring a bell... Thanks guys! Just for curiosity: - what *nix tool does not support CR+LF? - the cross-platform codes I work on use LF newlines but build without problem on Windows (msvc, intel, gcc). Why does CMake need two separate packages with different newlines? Cheers, -- Szilárd On Fri, Jan 10, 2014 at 2:56 PM, Andreas Pakulat wrote: > Hi, > > On Fri, Jan 10, 2014 at 2:16 PM, Szilárd Páll wrote: >> >> Found a workaround: >> $ find /tmp/cmake-2.8.12.1 -type f | xargs dos2unix >> >> This must be a bug, should I file a report? > > > Did you use the .zip file of the CMake sources? That one is intended to be > used for Windows and hence contains Windows lineendings. Thus its not > surprising that you have to convert that to unix first, not all *nix tools > can handle windows lineendings. > > Alternatively you can use the *.tar.* download of the CMake sources. > > Andreas > -- 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: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] boostrap error - borked cmConfigure.h [v2.8.12.1]
Hi, On Fri, Jan 10, 2014 at 9:42 PM, Szilárd Páll wrote: > Indeed, I did (accidentally) download the .zip package. I was rather > annoyed that the bootstrap script did not have executable permission > set, but it did not ring a bell... Thanks guys! > > Just for curiosity: > - what *nix tool does not support CR+LF? > As your error shows they got transported literally from an end of line into a c++ header. Which part in the build process would need to be fixed I don't know, I'd start searching where the cmake-2.8 value is supposed to come from and who generates the numbers. > - the cross-platform codes I work on use LF newlines but build without > problem on Windows (msvc, intel, gcc). Why does CMake need two > separate packages with different newlines? The problem is not so much the compilers (though there could be older versions which choke on just lf), but some editors still require crlf for line breaks (try opening a unix-file with Windows' notepad). Andreas -- 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: http://www.cmake.org/mailman/listinfo/cmake