How do I get CMake to check for TeXLive in Pandoc? - cmake

In PerfectTIN (https://github.com/phma/perfecttin), I build the documentation with this CMakeLists file:
find_program(PANDOC pandoc)
if (PANDOC)
execute_process(COMMAND ${PANDOC} "--resource-path=/" INPUT_FILE /dev/null ERROR_FILE /dev/null RESULT_VARIABLE pandoc_exit)
endif ()
if (PANDOC AND NOT pandoc_exit)
add_custom_command(OUTPUT perfecttin.pdf MAIN_DEPENDENCY perfecttin.xml COMMAND pandoc -f docbook -o perfecttin.pdf -V papersize=a4 -V margin-left=15mm -V margin-right=15mm -V margin-top=15mm -V margin-bottom=20mm --resource-path=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/perfecttin.xml)
add_custom_command(OUTPUT fileformat.pdf MAIN_DEPENDENCY fileformat.xml COMMAND pandoc -f docbook -o fileformat.pdf -V papersize=a4 -V margin-left=15mm -V margin-right=15mm -V margin-top=15mm -V margin-bottom=20mm --resource-path=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/fileformat.xml)
add_custom_target(perfecttin-doc ALL DEPENDS perfecttin.pdf fileformat.pdf)
install(FILES ${PROJECT_BINARY_DIR}/doc/fileformat.pdf ${PROJECT_BINARY_DIR}/doc/perfecttin.pdf DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/perfecttin)
endif ()
If Pandoc is absent, it doesn't build the documentation. If Pandoc and TeXLive are both present, it builds the documentation. But if Pandoc is present but TeXLive is not, the build fails. How can I check that Pandoc has what it needs before trying to build the documentation?
I tried "--resource-path=/ -f docbook -o /dev/zero"; it didn't fix it.

The program Pandoc uses is pdflatex (which is in the texlive-latex-base package in Ubuntu). So I added a search for pdflatex to CMakeLists.txt:
find_program(PANDOC pandoc)
find_program(PDFLATEX pdflatex)
if (PANDOC AND PDFLATEX)
execute_process(COMMAND ${PANDOC} "--resource-path=/" INPUT_FILE /dev/null ERROR_FILE /dev/null RESULT_VARIABLE pandoc_exit)
endif ()
if (PANDOC AND PDFLATEX AND NOT pandoc_exit)
add_custom_command(OUTPUT perfecttin.pdf MAIN_DEPENDENCY perfecttin.xml COMMAND pandoc -f docbook -o perfecttin.pdf -V papersize=a4 -V margin-left=15mm -V margin-right=15mm -V margin-top=15mm -V margin-bottom=20mm --resource-path=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/perfecttin.xml)
add_custom_command(OUTPUT fileformat.pdf MAIN_DEPENDENCY fileformat.xml COMMAND pandoc -f docbook -o fileformat.pdf -V papersize=a4 -V margin-left=15mm -V margin-right=15mm -V margin-top=15mm -V margin-bottom=20mm --resource-path=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/fileformat.xml)
add_custom_target(perfecttin-doc ALL DEPENDS perfecttin.pdf fileformat.pdf)
install(FILES ${PROJECT_BINARY_DIR}/doc/fileformat.pdf ${PROJECT_BINARY_DIR}/doc/perfecttin.pdf DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/perfecttin)
endif ()

Related

When converting DocBook, pandoc can't find image

I'm writing documentation for a program and would like to include a screenshot. The CMakeLists.txt file, which is in the doc subdirectory, looks like this:
find_program(PANDOC pandoc)
if (PANDOC)
add_custom_command(OUTPUT perfecttin.pdf MAIN_DEPENDENCY perfecttin.xml COMMAND pandoc -f docbook -o perfecttin.pdf -V papersize=a4 --data-dir=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/perfecttin.xml)
add_custom_target(perfecttin-doc ALL DEPENDS perfecttin.pdf)
endif ()
The section of the DocBook file looks like this:
<section id="window">
<title>Main Window</title>
<mediaobject>
<imageobject>
<imagedata fileref="window1.png" format="PNG"/>
</imageobject>
</mediaobject>
</section>
window1.png is in the same directory as CMakeLists.txt and perfecttin.xml. I've tried it with and without --data-dir=${PROJECT_SOURCE_DIR}/doc, and I get the same error:
[pandoc warning] Could not find image `window1.png', skipping...
How do I tell pandoc where to look for the image?
The option to do this is --resource-path, but that is not available on the version of pandoc on Ubuntu Bionic. So to build the documentation on a newer version, but not break the entire build on an older version, I added code to check whether pandoc supports the option. Here is the working CMakeLists.txt:
find_program(PANDOC pandoc)
if (PANDOC)
execute_process(COMMAND ${PANDOC} "--resource-path=/" INPUT_FILE /dev/null ERROR_FILE /dev/null RESULT_VARIABLE pandoc_exit)
endif ()
if (PANDOC AND NOT pandoc_exit)
add_custom_command(OUTPUT perfecttin.pdf MAIN_DEPENDENCY perfecttin.xml COMMAND pandoc -f docbook -o perfecttin.pdf -V papersize=a4 --resource-path=${PROJECT_SOURCE_DIR}/doc ${PROJECT_SOURCE_DIR}/doc/perfecttin.xml)
add_custom_target(perfecttin-doc ALL DEPENDS perfecttin.pdf)
endif ()
if (PANDOC AND NOT pandoc_exit) sounds backward, but the exit code for success is 0, which CMake takes as false, while the code for error is 2, which it takes as true.

Can I build my PC file (Oracle Pro*c) conditionally inside of my application's make file?

I'm attempting to combine my makefiles so I can simply build once and it will precompile the pc file completely before continuing to build the application. This should be possible but for the life of me I cannot figure it out. Here is my makefile (for redhat 7).
COMPILEDATE = $(shell date)
COMPILE=g++ -std=c++11 -Wall -Wuninitialized -g
OSTYPE = $(shell uname)
LIBDIR=../../lib/
INC=../../include/
FILES=myProcess
OBJS= myProcess.o \
sqlStuff.o
O8P=$(ORACLE_HOME)
O8P=/u01/app/oracle/11.2.0/client_1
ORACLE_HOME=/u01/app/oracle/11.2.0/client_1
PROC_LINES=proc lines=yes code=ANSI_C iname=sqlStuff.pc parse=partial iname=sqlStuff include=. include=$(ORACLE_HOME)/precomp/public include=$(ORACLE_HOME)/rdbms/public include=$(ORACLE_HOME)/rdbms/demo include=$(ORACLE_HOME)/plsql/public include=$(ORACLE_HOME)/network/public
all: $(FILES)
compileInfo.o : FORCE
$(COMPILE) -c compileInfo.cpp -o $# -I$(INC) -DCDATE="\"$(COMPILEDATE)\"" -DBUILD="\"$(LSWBUILD)\""
FORCE :
%.o : %.cpp $(INC)myProcess.h
$(COMPILE) -c $< -o $# -I$(INC) -DCDATE="\"$(COMPILEDATE)\""
sqlStuff.o : sqlStuff.c
gcc -g -Wall -O -c -lclntsh -I. -I$(ORACLE_HOME)/precomp/public -I$(ORACLE_HOME)/rdbms/public -I$(ORACLE_HOME)/rdbms/demo -I$(ORACLE_HOME)/plsql/lib -I$(ORACLE_HOME)/network/lib
sqlStuff.c : sqlStuff.pc
$(PROC_LINES)
myProcess: $(OBJS) $(LIBDIR)libbase.a $(INC)myProcess.h sqlStuff.o
$(COMPILE) -o myProcess$(OBJS) -L$(LIBDIR) -lbase
clean:
rm -f $(FILES)
rm -f sqlStuff
rm -f sqlStuff.c
rm -f sqlStuff.lis
rm -f $(OBJS)
rm -f core
rm -f *.out
rm -f *.log
rm -f *.err
My fault, I didn't explain what the issue was:
I'm compiling in netbeans using this build command: ${MAKE} -f Makefile. The error is PCC-S-02015, unable to open include file on my object that is not being precompiled, sqlStuff.o
Looking at the gcc command under sqlStuff.o : sqlStuff.c, it looks to me that there should be a -o sqlStuff.o flag to tell gcc that the output should be written to sqlStuff.o instead of the default, which is a.out.
Best of luck.

How to generate OCLint report to html format file?

I'm trying to use OCLint as primary code analyzer for my objc project. I follow OCLint guide and get a json file with named "compile_commands.json". But I can't generate it to HTML format file? Anybody can help me? Athought tried a dozen ways but it doesn't work. Any help is appreciate. Thank you
Here is my json file's content, a tiny part
{
"command" : "\/Applications\/Xcode.app\/Contents\/Developer\/Toolchains\/XcodeDefault.xctoolchain\/usr\/bin\/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-cache-path=\/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/ModuleCache -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -isysroot \/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/SDKs\/iPhoneOS7.0.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -miphoneos-version-min=7.0 -iquote \/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Intermediates\/IPSignDoc.build\/Debug-iphoneos\/IPSignDoc.build\/IPSignDoc-generated-files.hmap -I\/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Intermediates\/IPSignDoc.build\/Debug-iphoneos\/IPSignDoc.build\/IPSignDoc-own-target-headers.hmap -I\/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Intermediates\/IPSignDoc.build\/Debug-iphoneos\/IPSignDoc.build\/IPSignDoc-all-target-headers.hmap -iquote \/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Intermediates\/IPSignDoc.build\/Debug-iphoneos\/IPSignDoc.build\/IPSignDoc-project-headers.hmap -I\/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Products\/Debug-iphoneos\/include -I\/Applications\/Xcode.app\/Contents\/Developer\/Toolchains\/XcodeDefault.xctoolchain\/usr\/include -I\/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Intermediates\/IPSignDoc.build\/Debug-iphoneos\/IPSignDoc.build\/DerivedSources\/armv7 -I\/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Intermediates\/IPSignDoc.build\/Debug-iphoneos\/IPSignDoc.build\/DerivedSources -F\/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Products\/Debug-iphoneos -include \/Users\/cscv\/Documents\/WORKSPACE_iPOS_iOS\/Main\/IPSignDoc\/IPSignDoc\/IPSignDoc-Prefix.pch -MMD -MT dependencies -MF \/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Intermediates\/IPSignDoc.build\/Debug-iphoneos\/IPSignDoc.build\/Objects-normal\/armv7\/IPSignDoc.d --serialize-diagnostics \/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Intermediates\/IPSignDoc.build\/Debug-iphoneos\/IPSignDoc.build\/Objects-normal\/armv7\/IPSignDoc.dia -c \/Users\/cscv\/Documents\/WORKSPACE_iPOS_iOS\/Main\/IPSignDoc\/IPSignDoc\/IPSignDoc.m -o \/Users\/cscv\/Library\/Developer\/Xcode\/DerivedData\/iPOS-bpnrfhmrxtknspfladklyclnczrw\/Build\/Intermediates\/IPSignDoc.build\/Debug-iphoneos\/IPSignDoc.build\/Objects-normal\/armv7\/IPSignDoc.o",
"file" : "\/Users\/cscv\/Documents\/WORKSPACE_iPOS_iOS\/Main\/IPSignDoc\/IPSignDoc\/IPSignDoc.m",
"directory" : "\/Users\/cscv\/Documents\/WORKSPACE_iPOS_iOS\/Main\/IPSignDoc"
},
And use oclint-json-compilation-database -v oclint_args "-report-type html -o report.html"
But nothing happen!
Below is the script I am using to generate html file.
OCLINT_HOME is the path for oclint downloaded folder. I have renamed the folder to oclintrelease.
OCLINT_HOME=/Users/Dheeraj/Downloads/oclintrelease
export PATH=$OCLINT_HOME/bin:$PATH
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi
cd ${TARGET_TEMP_DIR}
if [ ! -f compile_commands.json ]; then
echo "[*] compile_commands.json not found, possibly clean was performed"
echo "[*] starting xcodebuild to rebuild the project.."
# clean previous output
if [ -f xcodebuild.log ]; then
rm xcodebuild.log
fi
cd ${SRCROOT}
xcodebuild clean
#build xcodebuild.log
xcodebuild | tee ${TARGET_TEMP_DIR}/xcodebuild.log
#xcodebuild <options>| tee ${TARGET_TEMP_DIR}/xcodebuild.log
echo "[*] transforming xcodebuild.log into compile_commands.json..."
cd ${TARGET_TEMP_DIR}
#transform it into compile_commands.json
oclint-xcodebuild
fi
echo "[*] starting analyzing"
cd ${TARGET_TEMP_DIR}
oclint-json-compilation-database -v oclint_args "-report-type html -o $OCLINT_HOME/report.html"
Your report would be generated to the provided path in OCLINT_HOME using the above script.
If you want to generate report in your derived data folder then replace the last line with :
oclint-json-compilation-database -v oclint_args "-report-type html -o report.html"
HTML report would be generated if and only if your build is successful and you can check your generated report path and script report into Log Navigator of Xcode.

makefile, size of an executable, static/dynamic

I have a makefile, for a C project with 2 sub-C-files and I can create two exe, one static and one dynamic.
But the static is lighter in space than the dynamic!
The programs can be launched and seems to be the sames
Is it normal?
Thank you very much, I have an exam in 2 days and I hope I will fix that problem :)
Simon
CC = gcc
CFLAGS = -Wall
CFLAGS2 = -shared
CFLAGS3 = -fPIC
LIB_U_CAM_TTL = -l_projet_vision_u_cam_ttl
LIB_SERIAL_LINUX = -l_projet_vision_serial_linux
CHEMIN = -L/usr/local/lib
lib_projet_vision_serial_linux.so: serial_linux.o
$(CC) $(CFLAGS2) $^ -o $#
lib_projet_vision_u_cam_ttl.so: u_cam_ttl.o
$(CC) $(CFLAGS2) $^ -o $#
lib_projet_vision_serial_linux.a : serial_linux.o
ar -rv $# $^
lib_projet_vision_u_cam_ttl.a : u_cam_ttl.o
ar -rv $# $^
projet_vision_dynamic: main_vision.c install
$(CC) $(CFLAGS3) $^ $(CHEMIN) $(LIB_SERIAL_LINUX) $(LIB_U_CAM_TTL) -o $#
projet_vision_static: main_vision.c install
$(CC) $^ $(CHEMIN) $(LIB_SERIAL_LINUX) $(LIB_U_CAM_TTL) -o $#
%.o : %.c
$(CC) $(CFLAGS) -c $< -o $#
install: lib_projet_vision_serial_linux.so lib_projet_vision_serial_linux.a lib_projet_vision_u_cam_ttl.so lib_projet_vision_u_cam_ttl.a
sudo cp -f *.h /usr/local/include/
sudo cp -f *.so /usr/local/lib/
sudo cp -f *.a /usr/local/lib/
sudo cp projet_vision_dynamic /usr/bin/
sudo cp projet_vision_static /usr/bin/
sudo ldconfig
uninstall: clean
sudo rm -f /usr/local/include/serial_linux.h
sudo rm -f /usr/local/include/u_cam_ttl.h
sudo rm -f /usr/local/lib/lib_projet_vision_serial_linux.so
sudo rm -f /usr/local/lib/lib_projet_vision_u_cam_ttl.so
sudo rm -f /usr/local/lib/lib_projet_vision_u_cam_ttl.a
sudo rm -f /usr/local/lib/lib_projet_vison_serial_linux.a
sudo ldconfig
clean:
rm -f *.o *~ *.so *.a
rm -f projet_vision_static projet_vision_dynamic

How to write a shell script to compile multiple embedded sql in C files (.sqc)?

I have written 3 .sqc files i.e. embedded sql in host language C. I need to make a (Unix) shell script to simply compile all 3 sqc files in a row. How can I do that? Right now, I can individually run each .sqc file using a Makefile that basically converts the .sqc file to a c file and then compiles it. Can I make 3 individual Makefiles and run all of them through a shell script? If so, then how? Can I make one Makefile that can compile all 3 .sqc independently and compile them thereafter through a shell script? If so, then how? Any other options?
Here is the Makefile that can only compile a single .sqc file:
NAME=sample
DB2PATH = /sqllib
CC=gcc
CFLAGS=-I$(DB2PATH)/include
LIBS=-L$(DB2PATH)/lib -R$(DB2PATH)/lib -ldb2
all: $(NAME)
$(NAME): $(NAME).sqc util.o
db2 connect to sampleDB
db2 prep $(NAME).sqc bindfile
db2 bind $(NAME).bnd
db2 connect reset
$(CC) $(CFLAGS) -c $(NAME).c
$(CC) $(CFLAGS) -o $(NAME) $(NAME).o util.o $(LIBS)
clean:
rm -f $(NAME) $(NAME).c $(NAME).o $(NAME).bnd
util.o : util.c
$(CC) -c util.c $(CFLAGS)
A possible (Unix) shell script and Makefile example would suffice to help.
Thank you.
This Makefile should do all three in one step, just type "make". Note that you'll have to change the second line to reflect the names of your real .sqc files.
Also note that I'm not familiar with sqc and I haven't tested this, I'm just working from your Makefile.
# THIS IS THE ONLY LINE YOU'LL HAVE TO CHANGE:
NAMES = file1 file2 file3
DB2PATH = /sqllib
CC=gcc
CFLAGS=-I$(DB2PATH)/include
LIBS=-L$(DB2PATH)/lib -R$(DB2PATH)/lib -ldb2
all: $(NAMES)
# This will convert .sqc into .c
%.c: %.sqc
db2 connect to sampleDB
db2 prep $< bindfile
db2 bind $*.bnd
db2 connect reset
# This will compile .c into .o, whether it's fileN.c or util.c
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $#
# This will link fileN.o and util.o into fileN
$(NAMES): % : %.o util.o
$(CC) $(CFLAGS) -o $# $^ $(LIBS)
# This is just to assure Make that that isn't really a file called "clean"
.PHONY: clean
clean:
rm -f $(NAMES) $(NAMES:=.c) $(NAMES:=.o) $(NAMES:=.bnd)
DB2PATH = /sqllib
CC=gcc
CFLAGS=-I$(DB2PATH)/include
LIBS=-L$(DB2PATH)/lib -R$(DB2PATH)/lib -ldb2
all: $(NAME)
$(NAME): $(NAME).sqc util.o
db2 connect to sampleDB
db2 prep $(NAME).sqc bindfile
db2 bind $(NAME).bnd
db2 connect reset
$(CC) $(CFLAGS) -c $(NAME).c
$(CC) $(CFLAGS) -o $(NAME) $(NAME).o util.o $(LIBS)
clean:
rm -f $(NAME) $(NAME).c $(NAME).o $(NAME).bnd
util.o : util.c
$(CC) -c util.c $(CFLAGS)
suppose you have three files: file1.sqc file2.sqc file3.sqc, and your makefile is saved as mksqc.mk
Script:
make -f mksqc.mk NAME=file1
make -f mksqc.mk NAME=file2
make -f mksqc.mk NAME=file3