Page tree
Skip to end of metadata
Go to start of metadata

2- Setting up the Development Environment:


  • mkdir ~/projects
  • cd ~/projects
  • mkdir bin lib include debug debug/bin debug/lib debug/include


Create the Cross-Compilation configuration file that you will use for Owasys 4 projects for cmake:

/home/politick/projects/Toolchain-arm-linux-gneabi.cmake

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
SET(CMAKE_C_COMPILER /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-c++)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf )

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)


### !!!!! These will prevent finding SSL libraries and stuff below !!! What a pain in the ass

# for libraries and headers in the target directories
#SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


SET(OPENSSL_ROOT_DIR /opt/compiled-arm-linux/openssl-1.1.0)


Create a New Owasys Project

Open KDevelop

  • Project → New From Template → Standard & Terminal

  • Next
  • Version Control → GIT
  • Finish
  • In Configure build dialog NEED TO ADD: 


Extra Arguments

-DCMAKE_TOOLCHAIN_FILE=/home/politick/projects/Toolchain-arm-linux-gneabi.cmake




APPLY configuration

You will need to have the IDE regenerate the CMake files. To do this,

Right click on the project,

Open Configuration...

Select a configuration or press Show Advanced or someting... so the Apply button becomes active. Once you press the Apply button, cmake will re-run.

I typically have 2 configurations,= { rel and debug }. The differences:

Installation prefix:

  • /home/politick/projects/debug
  • /home/politick/projects/

Build Type

  • Debug
  • Release



Delete Default

NOTE: For some reason, it did not take when I added it in the wizard. I had to follow the steps below an delete the current build anyway as the target was the x64 and not the ARM for some reason.

My guess is that CMake is not re-run and the project is not re-configured for the new tool chain. But if you delete and add a new, CMake is re-run automatically.


You can go into the build directory and remove the CMakeCache.txt and Makefile, that will likely fix as they will have to be re-generated



In case you forgot to add this IMPORTANT step, you can

  1. Right click on project
  2. Click on "Open Configuration..."
  3. Then click on CMake icon
    1. Delete current build by clicking on the "Minus" button
  4. Re-do the configuration and don't forget to add the extra parameter
  5. Press the Apply button to generate the new cmake files



Maintain your CMakeLists.txt

You need to maintain your CMakeList manually.  It should probably look like this:

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
project(owasys4)

#link_directories(
#/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib
#/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/ 
#)

include_directories(
~/projects/include/
)

add_executable(owasys4 main.cpp)

target_link_libraries(owasys4 RTU_Module IOs_Module GPS2_Module pthread dl )
#set_target_properties(owasys4 PROPERTIES PUBLIC_HEADER "Message.h")

install(TARGETS owasys4 
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include
)


Adding a new source.c file to the project

  • Right click on Project Name in Project tree → Create file →  Example.c
  • Now the CMake window will appear and now your file name should automatically be added to the add_executable list.  Line number 2 in red below.  Press OK.

  • Since we're here, you need to know that you need to maintain line #3.  The libraries that the linker must link to.  One ODD thing, the first element in the list MUST BE the name of your binary (program).  If you want to add any other C or CPP files to your project, you can add them to line #2 in the add_executable list.
  • Finally, you probably won't need to adjust the link_directories (line #1), unless you add or create your own libraries.  Then if there are new directories you want the linker to search through, then add them here.  But if you don't know what you're doing... then it is safe to leave this line aone.
  • No labels
Write a comment…