LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-14-2011, 08:28 PM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
CMake custom command issue


I was having an issue with namespaces and compiling a Lex-generated lexer, so I though that the simplest solution would simply be to wrap namespace constructs around Lex's output before compiling (I know, it's not really an elegant solution, but I couldn't think of anything much better).

Here is a snippet from my CMakeLists.txt:

Code:
find_program (LEX_TOOL NAMES lex flex)
if (NOT LEX_TOOL)
	message (FATAL_ERROR "Unable to find Lex")
endif (NOT LEX_TOOL)

find_program (YACC_TOOL NAMES yacc bison)
if (NOT YACC_TOOL)
	message (FATAL_ERROR "Unable to find YACC")
endif (NOT YACC_TOOL)

find_program (SED_TOOL NAMES sed)
if (NOT SED_TOOL)
	message (FATAL_ERROR "Unable to find sed")
endif (NOT SED_TOOL)

add_custom_command (
	COMMENT "Editing Lex Output"
	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp
	DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp.temp
	COMMAND ${SED_TOOL} -e "1 s@.*@#include \"config.hpp\"\\nnamespace LANG_NAMESPACE {\\nnamespace lexyacc {\\n\\n&@" -e "$ s@.*@&\\n}}\\n@" ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp.temp > ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp
)

add_custom_command (
	COMMENT "Building Lexer"
	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp.temp
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lex_lexer.l ${CMAKE_CURRENT_BINARY_DIR}/y.tab.hpp
	COMMAND ${LEX_TOOL} -o ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp.temp ${CMAKE_CURRENT_SOURCE_DIR}/lex_lexer.l
)

add_custom_command (
	COMMENT "Building Parser"
	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/y.tab.hpp ${CMAKE_CURRENT_BINARY_DIR}/y.tab.cpp
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/yacc_parser.y
	COMMAND ${YACC_TOOL} -d -o ${CMAKE_CURRENT_BINARY_DIR}/y.tab.cpp ${CMAKE_CURRENT_SOURCE_DIR}/yacc_parser.y
)
The problem is that it spits out this error when I try to make:

Code:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/michael/Projects/lang/build
[  6%] Editing Lex Output
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
make[2]: *** [lib/lex_lexer.cpp] Error 1
make[1]: *** [lib/CMakeFiles/lang.dir/all] Error 2
make: *** [all] Error 2
What's wrong?
 
Old 04-15-2011, 09:40 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Without having analyzed the Makefile in-depth, it looks like there are unbalanced quotes in the line
Code:
	COMMAND ${SED_TOOL} -e "1 s@.*@#include \"config.hpp\"\\nnamespace LANG_NAMESPACE {\\nnamespace lexyacc {\\n\\n&@" -e "$ s@.*@&\\n}}\\n@" ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp.temp > ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp
--- rod.
 
Old 04-15-2011, 09:50 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by theNbomr View Post
Without having analyzed the Makefile in-depth, it looks like there are unbalanced quotes in the line
Code:
	COMMAND ${SED_TOOL} -e "1 s@.*@#include \"config.hpp\"\\nnamespace LANG_NAMESPACE {\\nnamespace lexyacc {\\n\\n&@" -e "$ s@.*@&\\n}}\\n@" ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp.temp > ${CMAKE_CURRENT_BINARY_DIR}/lex_lexer.cpp
--- rod.
I don't see them!
 
Old 04-15-2011, 10:26 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Oops, my bad. I guess I miscounted them when I first looked.
Does your sed command work as specified, but independently of make? Does the input file exist? Non-empty? Where its supposed to be when make runs?

--- rod.
 
Old 04-15-2011, 11:31 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by theNbomr View Post
Oops, my bad. I guess I miscounted them when I first looked.
Does your sed command work as specified, but independently of make? Does the input file exist? Non-empty? Where its supposed to be when make runs?

--- rod.
That's kind of irrelavent becasue when you look at the error messages, it's /bin/sh, not sed, throwing the error.

I think that the biggest problem is that I don't understand how the command is executed by CMake. Is it passed unmodified to bash? Does CMake interpret certain quotes and escape characters?

I thought that CMake interprets them becasue Kate doesn't highlight single quotes, and even if I do try them, CMake interprets the '#' characters as the start of a comment. And then bash says that there's an unmatched single quote.

Last edited by MTK358; 04-15-2011 at 11:35 AM.
 
Old 04-16-2011, 11:29 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I found that CMake inserts a backslash before every space in the Makefile. Why is that, and how to fix it?

CMakeLists.txt:

Code:
${SED_TOOL} -e "'1 s@.*@\#include \"config.hpp\"\\nnamespace LANG_NAMESPACE {\\nnamespace lexyacc {\\n\\n&@'" -e "'\$ s@.*@&\\n}}\\n@'"
generated makefile:

Code:
/bin/sed -e '1\ s@.*@#include\ "config.hpp"\nnamespace\ LANG_NAMESPACE\ {\nnamespace\ lexyacc\ {\n\n&@' -e '$\ s@.*@&\n}}\n@'

Last edited by MTK358; 04-16-2011 at 11:34 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cmake: Using find_package(Boost) when FindBoost.cmake is not in the default location damien_d Programming 3 10-27-2010 03:40 PM
custom sles11 sha1sum issue sanketks Linux From Scratch 1 05-18-2010 05:58 PM
cmake command missing LiNuXMaN31509 Linux - Newbie 11 06-27-2009 03:26 AM
using cmake: "could not find qtglobal header". Issue with qt4? perturbed Linux - Newbie 1 01-20-2009 01:38 PM
cmake or make: debug output, show command Ephracis Programming 4 03-01-2008 03:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration