I know there is no straight forward way to convert make files to cmake, but need some guidance. I have a make file for an embedded machine, and want to move forward using cmake.
I am cross-compiling on a linux dev machine for an embedded arm running a linux kernel.
currently, all files are in the same folder. I am working to move them to this structure: -build -documentation -includes -src CMakeLists.txt -test CMakeLists.txt
I want to put header files in the /includes folder, and the c/cpp files in the src folder.
OUT = enterprise.exe
CC = g++
CCFLAGS = -lrt -Wall -pthread
HEADERS = logobj.h message.h channel.h utilities.h parameter.h mycan.h vthread.h logger.h protocol_quest.h protocol_can.h protocol_io.h protocol_navitrol.h qt_nav.h qt_battery.h qt_iodealer.h enterprise.h
OBJECTS = logobj.o message.o channel.o utilities.o parameter.o mycan.o vthread.o logger.o protocol_quest.o protocol_can.o protocol_io.o protocol_navitrol.o qt_nav.o qt_battery.o qt_iodealer.o enterprise.o
GPIOHEADERS = evgpio.h
GPIOOBJECTS = evgpio.o
%.o: %.c $(HEADERS)
$(CC) $(CCFLAGS) -c -o $@ $<
%.o: %.c $(GPIOHEADERS)
$(CC) $(CCFLAGS) -c -o $@ $< -mcpu=arm9
$(OUT): $(OBJECTS) $(GPIOOBJECTS)
$(CC) $(CCFLAGS) -o $@ $^ $(LIB)
clean:
-rm -f $(OBJECTS) $(GPIOOBJECTS)
-rm -f $(OUT)
I am thinking it will look like this:
Top folder CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(enterprise)
set(CMAKE_CXX_COMPILER /opt/toolchains/arm-2008q3/bin/arm-none-linux-gnueabi-g++)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(COMPILE_FLAGS "-lrt -Wall -pthread")
add_subdirectory(src)
/src folder CMakeLists.txt
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) //haven't moved the headers yet
set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR} filename1.cpp filename2.cpp etc.cpp)
set(vendorLib filenameVendor1.o filenameVendor2.o etcVendor.o)
add_executable(enterprise ${SOURCES})
target_link_libraries(enterprise vendorLib)
Part of me thinks there should be something linking, but not sure where. At this time, I can get through cmake process, but fails on make. Undefined references and such...
Thoughts?
*****EDIT** Updated src/CMakeLists.txt to include comments and updates from testing.