Re: [CMake] Return an Error Code (or something) from a CMake Script.
Hi Michael, you probably figured this out by now, but for future reference: You have to log to stderr to make the script fail. This example works (as in /does not build/ ;) ): file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/skript.cmake" CONTENT "message(FATAL_ERROR \"Script failed!!\")" ) add_custom_target(runSkript COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/skript.cmake ) btw: Using CMake 3.10 Greetings, Felix -- Sent from: http://cmake.3232098.n2.nabble.com/ -- 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] Return an Error Code (or something) from a CMake Script.
-Original Message- From: "Alan W. Irwin" Date: Monday, February 26, 2018 at 6:02 PM To: Michael Jackson Cc: CMake Mail List Subject: Re: [CMake] Return an Error Code (or something) from a CMake Script. On 2018-02-26 14:19-0500 Michael Jackson wrote: > In our CMake based project I generate a *.cmake file which I call with the following bit of code: > > add_custom_target(DREAM3D_MKDOCS_GENERATION ALL >COMMAND "${CMAKE_COMMAND}" -P "${docsCmakeFile}" >COMMENT "using mkdocs to generate the documentation" > ) > > Inside the generated file is the following cmake command: > > message(STATUS "Starting mkdocs execution. This can take a while.") > execute_process(COMMAND "/path/to/mkdocs" build >OUTPUT_VARIABLE mkdocs_gen_output >RESULT_VARIABLE mkdocs_gen_result >ERROR_VARIABLE mkdocs_gen_error >WORKING_DIRECTORY "/Users/mjackson/DREAM3D-Dev/DREAM3D-Build/Debug/Documentation/mkdocs" >) > message(STATUS "mkdocs_gen_result: ${mkdocs_gen_result}") > message(STATUS "mkdocs_gen_error: ${mkdocs_gen_error}") > message(STATUS "**") > message(STATUS "mkdocs_gen_output: ${mkdocs_gen_output}") > message(STATUS "**") > > > The issue that I am having is that if the mkdocs command fails, the build does NOT show the failure. Is there a way to have the "cmake -P" command pick up the fact that the cmake script failed so that the build fails or throws a warning/error? Hi Mike: I think you already have a good specific answer to your question, but just out of curiosity could this CMake script approach be replaced by executing "/path/to/mkdocs" as the COMMAND in a custom command where your DREAM3D_MKDOCS_GENERATION custom target DEPENDS on the OUTPUT of that custom command? Or are there reasons not to implement this more usual custom command/custom target approach in this case? Alan __ Alan W. Irwin Alan, There was a lot in that .cmake file that I left out. In order for the mkdocs to work all of our documentation has to be in the same folder (At least it makes it much easier) so during cmake time we generate the file with about 30~40 directory copy commands in it. We could do all of that in the mail cmake files but our project is starting to get overwhelmed with targets which makes opening it up on IDE's like Visual Studio and Xcode take a long time and the organization within those IDEs is frightful sometimes. So we factored out "copy" commands into a single file. Mike Jackson -- 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] Return an Error Code (or something) from a CMake Script.
On 2018-02-26 14:19-0500 Michael Jackson wrote: In our CMake based project I generate a *.cmake file which I call with the following bit of code: add_custom_target(DREAM3D_MKDOCS_GENERATION ALL COMMAND "${CMAKE_COMMAND}" -P "${docsCmakeFile}" COMMENT "using mkdocs to generate the documentation" ) Inside the generated file is the following cmake command: message(STATUS "Starting mkdocs execution. This can take a while.") execute_process(COMMAND "/path/to/mkdocs" build OUTPUT_VARIABLE mkdocs_gen_output RESULT_VARIABLE mkdocs_gen_result ERROR_VARIABLE mkdocs_gen_error WORKING_DIRECTORY "/Users/mjackson/DREAM3D-Dev/DREAM3D-Build/Debug/Documentation/mkdocs" ) message(STATUS "mkdocs_gen_result: ${mkdocs_gen_result}") message(STATUS "mkdocs_gen_error: ${mkdocs_gen_error}") message(STATUS "**") message(STATUS "mkdocs_gen_output: ${mkdocs_gen_output}") message(STATUS "**") The issue that I am having is that if the mkdocs command fails, the build does NOT show the failure. Is there a way to have the "cmake -P" command pick up the fact that the cmake script failed so that the build fails or throws a warning/error? Hi Mike: I think you already have a good specific answer to your question, but just out of curiosity could this CMake script approach be replaced by executing "/path/to/mkdocs" as the COMMAND in a custom command where your DREAM3D_MKDOCS_GENERATION custom target DEPENDS on the OUTPUT of that custom command? Or are there reasons not to implement this more usual custom command/custom target approach in this case? Alan __ Alan W. Irwin Astronomical research affiliation with Department of Physics and Astronomy, University of Victoria (astrowww.phys.uvic.ca). Programming affiliations with the FreeEOS equation-of-state implementation for stellar interiors (freeeos.sf.net); the Time Ephemerides project (timeephem.sf.net); PLplot scientific plotting software package (plplot.sf.net); the libLASi project (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project (lbproject.sf.net). __ Linux-powered Science __ -- 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] Return an Error Code (or something) from a CMake Script.
cmake -P usually do the right thing. Here you ignore the error because you only message (STATUS ...) Try adding message (ERROR ...) or message (FATAL_ERROR ...) when execute_process producer error and tout custom command should faim. Le 26 févr. 2018 20:19, "Michael Jackson" a écrit : > In our CMake based project I generate a *.cmake file which I call with the > following bit of code: > > add_custom_target(DREAM3D_MKDOCS_GENERATION ALL > COMMAND "${CMAKE_COMMAND}" -P "${docsCmakeFile}" > COMMENT "using mkdocs to generate the documentation" > ) > > Inside the generated file is the following cmake command: > > message(STATUS "Starting mkdocs execution. This can take a while.") > execute_process(COMMAND "/path/to/mkdocs" build > OUTPUT_VARIABLE mkdocs_gen_output > RESULT_VARIABLE mkdocs_gen_result > ERROR_VARIABLE mkdocs_gen_error > WORKING_DIRECTORY "/Users/mjackson/DREAM3D-Dev/D > REAM3D-Build/Debug/Documentation/mkdocs" > ) > message(STATUS "mkdocs_gen_result: ${mkdocs_gen_result}") > message(STATUS "mkdocs_gen_error: ${mkdocs_gen_error}") > message(STATUS "* > *") > message(STATUS "mkdocs_gen_output: ${mkdocs_gen_output}") > message(STATUS "* > *") > > > The issue that I am having is that if the mkdocs command fails, the build > does NOT show the failure. Is there a way to have the "cmake -P" command > pick up the fact that the cmake script failed so that the build fails or > throws a warning/error? > > Thanks > Mike Jackson > > > -- > > 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/opensou > rce/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake > -- 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] Return an Error Code (or something) from a CMake Script.
In our CMake based project I generate a *.cmake file which I call with the following bit of code: add_custom_target(DREAM3D_MKDOCS_GENERATION ALL COMMAND "${CMAKE_COMMAND}" -P "${docsCmakeFile}" COMMENT "using mkdocs to generate the documentation" ) Inside the generated file is the following cmake command: message(STATUS "Starting mkdocs execution. This can take a while.") execute_process(COMMAND "/path/to/mkdocs" build OUTPUT_VARIABLE mkdocs_gen_output RESULT_VARIABLE mkdocs_gen_result ERROR_VARIABLE mkdocs_gen_error WORKING_DIRECTORY "/Users/mjackson/DREAM3D-Dev/DREAM3D-Build/Debug/Documentation/mkdocs" ) message(STATUS "mkdocs_gen_result: ${mkdocs_gen_result}") message(STATUS "mkdocs_gen_error: ${mkdocs_gen_error}") message(STATUS "**") message(STATUS "mkdocs_gen_output: ${mkdocs_gen_output}") message(STATUS "**") The issue that I am having is that if the mkdocs command fails, the build does NOT show the failure. Is there a way to have the "cmake -P" command pick up the fact that the cmake script failed so that the build fails or throws a warning/error? Thanks Mike Jackson -- 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