vscode intellisense cmake-tools with external library - visual-studio-code

I'm trying to configure a template project for my STM32 blue pill board with CMake and cmake-tools for Visual Studio Code. It builds just fine, but the Intellisense feature of cmake-tools seems not to work with an external library (libopencm3 in this case).
This is most likely a configuration error on my side. Following my CMakeLists.txt. The toolchain is defined in a seperate .cmake file.
set(PRJ_NAME STM32_Template_Project)
cmake_minimum_required(VERSION 3.6)
project(${PRJ_NAME} C ASM)
set(COMMON_FLAGS "-mcpu=${MCU_ARCH} -mthumb -mthumb-interwork -mfloat-abi=${MCU_FLOAT_ABI} -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0 -DSTM32F1")
if (MCU_FLOAT_ABI STREQUAL hard)
set(COMMON_FLAGS "${COMMON_FLAGS} -mfpu=${MCU_FPU}")
endif ()
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${CMAKE_SOURCE_DIR}/${MCU_LINKER_SCRIPT}")
set(DEFINITIONS "${DEFINITIONS} -D${MCU_LINE}")
set(LIBOPENCM3_DIR "../libopencm3")
#headers
include_directories(sys)
include_directories(Inc)
include_directories(${LIBOPENCM3_DIR}/include)
# libopencm3
# Make sure that git submodule is initialized and updated
if (NOT EXISTS ${LIBOPENCM3_DIR}/Makefile)
message(FATAL_ERROR "libopencm3 submodule not found. Initialize with 'git submodule update --init' in the source directory")
endif()
add_custom_target(libopencm3 make TARGETS=stm32/f1 WORKING_DIRECTORY ${LIBOPENCM3_DIR})
link_directories(${LIBOPENCM3_DIR}/lib)
#files
file(GLOB_RECURSE USER_SOURCES Src/*.c)
set(CMSIS_STARTUP startup_${MCU_LINE}.s)
set(SOURCE_FILES ${USER_SOURCES} ${CMSIS_STARTUP} ${MCU_LINKER_SCRIPT})
# target
add_executable(${PROJECT_NAME}.elf ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME}.elf opencm3_stm32f1)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")
I am not very experienced with CMake and cmake-tools.

Related

CMake install not working in Visual Studio Code

I'm trying to generate a static library and install it using Cmake and Visual Studio Code, but the files are not installed where I want to.
The folder structure is as follows:
Main_Folder
- Poly
- - CMakeLists.txt
- - src
- - - Poly.cpp
- - - Poly.h
- Test
- - TestLibs
- - - TestLibs.cpp
- - - TestLibs.h
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.0.0)
project(poly)
set(CMAKE_BUILD_TYPE Debug)
#Bring the headers, such as Student.h into the project
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*")
#Generate the static library from the sources
add_library(poly STATIC ${SOURCES})
#Set the location for library installation
install(
TARGETS poly
LIBRARY DESTINATION /Main_Folder/Test/TestLibs/Poly
ARCHIVE DESTINATION /Main_Folder/Test/TestLibs/Poly
RUNTIME DESTINATION /Main_Folder/Test/TestLibs/Poly
)
And this is my cmake_install.cmake:
# Install script for directory: Main_Folder/Poly
# Set the install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr/local")
endif()
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
if(BUILD_TYPE)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "Debug")
endif()
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
endif()
# Set the component getting installed.
if(NOT CMAKE_INSTALL_COMPONENT)
if(COMPONENT)
message(STATUS "Install component: \"${COMPONENT}\"")
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
else()
set(CMAKE_INSTALL_COMPONENT)
endif()
endif()
# Install shared libraries without execute permission?
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
set(CMAKE_INSTALL_SO_NO_EXE "0")
endif()
# Is this installation the result of a crosscompile?
if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING "FALSE")
endif()
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx" OR NOT CMAKE_INSTALL_COMPONENT)
list(APPEND CMAKE_ABSOLUTE_DESTINATION_FILES "/Main_Folder/Test/TestLibs/Poly/libpoly.a")
if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)
message(WARNING "ABSOLUTE path INSTALL DESTINATION : ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
endif()
if(CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION)
message(FATAL_ERROR "ABSOLUTE path INSTALL DESTINATION forbidden (by caller): ${CMAKE_ABSOLUTE_DESTINATION_FILES}")
endif()
file(INSTALL DESTINATION "/Main_Folder/Test/TestLibs/Poly/" TYPE STATIC_LIBRARY FILES "/home/myUser/git/Main_Folder/Test/TestLibs/Poly/libpoly.a")
endif()
The library (libpoly.a) is created, but instead of being installed in /Main_Folder/Test/TestLibs/Poly is found on /Main_Folder/Poly and I dont understand what I'm missing.
I'm using Linux and cmake 3.17.3, I don't know if this might cause the issue.

Need help translating a Make File into Meson Build File for Vala

I am working on an Application in Vala. I need to use both webkit2gtk-web-extension-4.0 and webkit2gtk-4.0 in an single project.
I am following the example from -
https://github.com/rschroll/webkitdom/tree/extension
The Make File from the example is as follows:
PKGS=--pkg gtk+-3.0 --pkg libsoup-2.4
EXEC=dom-test
SOURCES=dom-test.vala custom-web-view.vala
LIB_BASE=dom-server
LIB_SOURCES=$(LIB_BASE).vala
LIBRARY=$(LIB_BASE).so
# If you have webkit2gtk-4.0 installed, you will need a Vala from git
# version 6a1a1ab1 (2014/10/16) or later, in order to have the fixed
# .vapi files.
#WEBKIT_VAPI=--pkg webkit2gtk-4.0
#WEBKIT_EXT_VAPI=--pkg webkit2gtk-web-extension-4.0
# Otherwise, use the -3.0 versions included here
WEBKIT_VAPI=--vapidir=. --pkg webkit2gtk-3.0
WEBKIT_EXT_VAPI=--vapidir=. --pkg webkit2gtk-web-extension-3.0 -X -I/usr/include/webkitgtk-3.0
all: $(EXEC) $(LIBRARY)
$(EXEC): $(SOURCES)
valac $(WEBKIT_VAPI) $(PKGS) $^
$(LIBRARY): $(LIB_SOURCES)
valac $(WEBKIT_EXT_VAPI) $(PKGS) --library=$(LIB_BASE) -X -fPIC -X -shared -o $# $^
clean:
rm $(EXEC) $(LIBRARY)
With Meson Build system, I tried to create a subproject with the shared library and link the shared library in the main project. But I am getting the error
DOMServer.vala:1.1-1.10: error: The root namespace already contains a definition for `WebKit'
The main project meson.build file as follows:
project('com.linappfoundry.athmanam', ['c', 'vala'])
domserver_proj = subproject('DOMServer')
domserver_lib = domserver_proj.get_variable('domserver_lib')
cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : false)
executable(
meson.project_name(),
'AthmanamApp.vala',
'Widgets/MainWindow.vala',
'Widgets/PoemParserWebView.vala',
dependencies: [
dependency('gtk+-3.0'),
dependency('glib-2.0'),
dependency('libsoup-2.4'),
dependency('webkit2gtk-4.0'),
dependency('json-glib-1.0'),
dependency('libxml-2.0'),
m_dep
],
link_with: [domserver_lib],
install: true
)
And subproject's meson.build file is as follows:
project('com.linappfoundry.athmanam.DOMServer', ['c', 'vala'])
domserver_lib = shared_library(
'com.linappfoundry.athmanam.DOMServer',
'src/DOMServer.vala',
dependencies: [
dependency('glib-2.0'),
dependency('gtk+-3.0'),
dependency('libsoup-2.4'),
dependency('webkit2gtk-web-extension-4.0')
],
install: true
)
I am not sure what I am doing wrong here, as I am new to both Vala and Meson.
The error
DOMServer.vala:1.1-1.10: error: The root namespace already contains a definition for `WebKit'
is from the Vala compiler and is saying there is already a definition of Webkit in the global namespace. The error could be as simple as using a keyword with the wrong case, e.g. Using Webkit; when it should be using Webkit;.
Webkit is defined as a namespace in the global (root) namespace and that is done in the VAPI file. Try and find where it is being redefined as something else.

buildroot external cmake package makefile fails install

I am trying to install my external package, which is built fine by the cross-compile toolchain but fails on the install step with the error
Install the project...
-- Install configuration: "Release"
-- Installing: /home/username/Projects/ProjectName/ProjectName_software/ProjectName_OS/build_ProjectName_os_raspberrypi3/target/home/username/Projects/ProjectName/ProjectName_software/ProjectName_
OS/build_ProjectName_os_raspberrypi3/build/APPNAME/APPNAME
APPNAME: installs files in /home/userName/Projects/ProjectName/ProjectName_software/ProjectName_OS/build_ProjectName_os_raspberrypi3/target//home/username/Projects/ProjectName/ProjectName
_software/ProjectName_OS/build_ProjectName_os_raspberrypi3
package/pkg-generic.mk:315: recipe for target '/home/alex/Projects/BlackBox/bbefx_software/BBEFX_OS/build_bbefx_os_raspberrypi3/build/BBEFX_CORE/.stamp_
target_installed' failed
I am guessing that the path prefixed by --Installing is the one generated by the package makefile and the one prefixed by APPNAME is the one that buildroot is expecting APPNAME to install to. Hence why the .stamp_target_install fails
The obvious issue is that the path buildroot expects is
/target//home/username/
This isn't the path that I would like to install to (usr/bin would be preferable). However I can't see how to specify a path within the package make file, which is as follows:
APPNAME_SITE = $(TOPDIR)/../../APPNAME
APPNAME_SITE_METHOD = local
APPNAME_INSTALL_TARGET = YES
$(eval $(cmake-package))
With the CMakeLists.txt being:
#
# CMake options
#
# CMake version
cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
option(BUILD_DOC "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
# project name
project(APPNAME)
IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "No build type selected, default to Release")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF()
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
IF(CMAKE_BUILD_TYPE AND
NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE)$")
MESSAGE(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
ENDIF()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++14")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -std=c++14")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++14")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -w -std=c++14")
endif()
# enable c++
enable_language(C CXX)
# project version
set(VERSION_MAJOR 0)
set(VERSION_MINOR 1)
set(VERSION_PATCH 0)
# Find all sources and headers in the source folder
file(GLOB_RECURSE APPNAME_SOURCES "source/*.cpp")
file(GLOB_RECURSE APPNAME_HEADERS "source/*.hpp" "source/*.h")
# Add header directories, remove dupes
set (APPNAME_INCLUDE_DIRS "")
foreach (_headerFile ${APPNAME_HEADERS})
get_filename_component(_dir ${_headerFile} PATH)
list (APPEND APPNAME_INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES APPNAME_INCLUDE_DIRS)
# Add sources and headers to exec
add_executable (APPNAME ${APPNAME_SOURCES})
target_include_directories(APPNAME PRIVATE ${APPNAME_INCLUDE_DIRS})
# Add Libs to link
find_package(libconfigpp REQUIRED)
find_package(Boost COMPONENTS system log REQUIRED)
include_directories(${LIBCONFIGPP_INCLUDE_DIR} $Boost_INCLUDE_DIRS)
target_link_libraries(APPNAME ${Boost_LIBRARIES} ${LIBCONFIGPP_LIBRARIES})
add_definitions(-DBOOST_LOG_DYN_LINK)
# Add platform specific Libs and preproc macros
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_definitions(-DSYSTEM_LINUX)
add_definitions(-D__UNIX_JACK__ )
find_package(libjack REQUIRED)
target_link_libraries(APPNAME ${JACK_LIBRARIES})
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(APPNAME Threads::Threads)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
add_definitions(-DSYSTEM_DARWIN)
add_definitions(-D__MACOSX_CORE__)
find_library(COREMIDI_LIBRARY CoreMIDI)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
find_library(COREAUDIO_LIBRARY CoreAudio)
target_link_libraries(APPNAME ${COREFOUNDATION_LIBRARY} ${COREMIDI_LIBRARY} ${COREAUDIO_LIBRARY})
endif()
set(CONFIGFILE source/APPNAME_CONFIG.cfg)
#file(COPY ${CONFIGFILE} DESTINATION ${CMAKE_BINARY_DIR})
install (TARGETS APPNAME DESTINATION ${CMAKE_BINARY_DIR})
#
# Build Documentation
#
find_package(Doxygen)
if(BUILD_DOC)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/source/doc/Doxyfile.in)
set(DOXYFILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYFILE_IN} ${DOXYFILE} #ONLY)
add_custom_target(DOC
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
add_custom_command(TARGET DOC
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/source/doc/Documentation.html ${CMAKE_SOURCE_DIR}/doc
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
endif()
This line:
install (TARGETS APPNAME DESTINATION ${CMAKE_BINARY_DIR})
is wrong. According to the CMake documentation, CMAKE_BINARY_DIR is the The path to the top level of the build tree., which is why your binary gets installed in the wrong place.
Please replace this line with:
install (TARGETS APPNAME DESTINATION bin)

GO: {GOOS} and {GOARCH} not recognised in environment

I want to change my diretory to go/pkg/darwin_amd64 but $ cd $GOPATH/pkg/${GOOS}_${GOARCH} doesn't find the folder though directory exists.
$ echo $GOPATH/pkg/${GOOS}_${GOARCH} gives /go/pkg/_ instead of /go/pkg/darwin_amd64.
$ go env prints:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sahilkapoor/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
We can see that GOOS and GOARCH are defined here. I am using terminal on Mac OSX 10.10.3. What am I missing?
$GOOS and $GOARCH will only be defined in your shell if you have exported them (which, unless you are doing cross compilation, is unlikely).
When you run go env, default values are shown when they have not been overwritten by your environment. You should change your command to the following to get the desired results:
cd $(go env GOPATH)/pkg/$(go env GOOS)_$(go env GOARCH)

How to disable debug optimization in eclipse cdt

I want to stop debug optimization in eclipse cdt and I read article about this
http://husks.wordpress.com/2012/03/29/hardware-debugging-the-arduino-using-eclipse-and-the-avr-dragon/
it supposed to see tool setting in eclipse indigo but I didn't see it.
what is the problem
see this for more info
https://sourceforge.net/projects/cmusphinx/forums/forum/5471/topic/5170910
this is my make file
TOP=../../..
DIRNAME=src/programs/init_gau
BUILD_DIRS =
ALL_DIRS= $(BUILD_DIRS)
SRCS = \
accum.c \
init_gau.c \
main.c \
parse_cmd_ln.c
H = \
accum.h \
init_gau.h \
mk_sseq.h \
parse_cmd_ln.h
FILES = Makefile $(SRCS) $(H)
TARGET = init_gau
ALL = $(BINDIR)/$(TARGET)
include $(TOP)/config/common_make_rules
I found this config file
# -*- makefile -*-
#
# This file is automatically generated by configure.
# Do not hand edit.
CC = gcc
CFLAGS = -g -O0 -Wall -fPIC -DPIC
CPPFLAGS = -I/media/sda5/sphinx/tutorial/SphinxTrain/../sphinxbase/include -I/media/sda5/sphinx/tutorial/SphinxTrain/../sphinxbase/include
DEFS = -DPACKAGE_NAME=\"SphinxTrain\" -DPACKAGE_TARNAME=\"sphinxtrain\" -DPACKAGE_VERSION=\"1.0.99\" -DPACKAGE_STRING=\"SphinxTrain\ 1.0.99\" -DPACKAGE_BUGREPORT=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIBM=1
LIBS = -lm -lsphinxbase
LDFLAGS = -L/media/sda5/sphinx/tutorial/SphinxTrain/../sphinxbase/src/libsphinxad -L/media/sda5/sphinx/tutorial/SphinxTrain/../sphinxbase/src/libsphinxbase -L/media/sda5/sphinx/tutorial/SphinxTrain/../sphinxbase/src/libsphinxbase/.libs
AR = ar
RANLIB = ranlib
FESTIVAL = /usr/bin/festival
PERL = /usr/bin/perl
The options are under project properties as explained in first tutorial. If you are trying to build a project with existing makefile, then you need to edit the makefile.
You dont typiclly need to change project properties. Debug configuration builds without optimization by default. You just need to make sure you jave it selected. This is done using the icon (sundial? - the one next to CDT's build (hammer)).