I'm trying to convert my old makefile code to CMake. Can you help me? This is the part where I'm currently stuck. I don't know how to pass these arguments to the compiler.
COMPILE_FLAGS = -c -m32 -O3 -fPIC -w -DSOMETHING -Wall -I src/sdk/core
ifdef STATIC
OUTFILE = "bin/test_static.so"
COMPILE_FLAGS_2 = ./lib/ABC.a
else
OUTFILE = "bin/test.so"
COMPILE_FLAGS_2 = -L/usr/lib/mysql -lABC
endif
all:
g++ $(COMPILE_FLAGS) src/sdk/*.cpp
g++ $(COMPILE_FLAGS) src/*.cpp
g++ -fshort-wchar -shared -o $(OUTFILE) *.o $(COMPILE_FLAGS_2)
rm -f *.o
Thank you!
Let's try to map
Makefile
syntax toCMake
:This statement directly maps to:
A conditional of the type:
is translated in CMake in this way:
To modify the default compilation flags you can set the variables
CMAKE_<LANG>_FLAGS_RELEASE
,CMAKE_<LANG>_FLAGS_DEBUG
, etc. , appropriately.Finally the compilation of an executable requires you to use the
ADD_EXECUTABLE
command, which is explained in many CMake tutorials.In any case I suggest you to refer to the online documentation for further details, as it is quite explanatory and complete.