summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-07-01 09:21:18 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2016-07-01 09:21:18 +0200
commit3bf71c66f63f33471b172570a3a20710d6fe6b72 (patch)
tree55be59add176bedaf0a9e08bca33ce4a435dcfd4 /cmake
downloadintel-quark-d2000-playground-3bf71c66f63f33471b172570a3a20710d6fe6b72.tar.gz
intel-quark-d2000-playground-3bf71c66f63f33471b172570a3a20710d6fe6b72.tar.bz2
intel-quark-d2000-playground-3bf71c66f63f33471b172570a3a20710d6fe6b72.tar.xz
intel-quark-d2000-playground-3bf71c66f63f33471b172570a3a20710d6fe6b72.zip
o Initial commit.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/intel-quark-d2000.toolchain.cmake176
1 files changed, 176 insertions, 0 deletions
diff --git a/cmake/intel-quark-d2000.toolchain.cmake b/cmake/intel-quark-d2000.toolchain.cmake
new file mode 100644
index 0000000..3e15792
--- /dev/null
+++ b/cmake/intel-quark-d2000.toolchain.cmake
@@ -0,0 +1,176 @@
+if (${INTEL_QUARK_TOOLCHAIN_LOADED})
+ return()
+endif()
+set(INTEL_QUARK_TOOLCHAIN_LOADED TRUE)
+
+include(CMakeForceCompiler)
+
+set(TRIPLE "i586-intel-elfiamcu")
+
+if (NOT IS_DIRECTORY "${ISSM_DIR}")
+ message(FATAL_ERROR "ISSM_DIR has to be set to a directory:" ${ISSM_DIR})
+ set(ISSM_DIR CACHE PATH "The path to Intes ISSM")
+endif()
+
+if (NOT INTEL_QUARK_CHIP)
+ set(INTEL_QUARK_CHIP CACHE STRING "The Intel Quark chip to build for")
+ message(FATAL_ERROR "INTEL_QUARK_CHIP has to be set before including the toolchain file")
+endif()
+
+set(CMAKE_SYSTEM_NAME Generic)
+set(CMAKE_SYSTEM_PROCESSOR intel)
+set(CMAKE_CROSSCOMPILING 1)
+
+set(TARGET_FLAGS "-march=lakemont -mtune=lakemont -miamcu -msoft-float")
+set(BASE_FLAGS "-std=c90 -Wall -Wextra -Werror -Wno-unused-parameter")
+
+set(INCLUDES "")
+
+if(IS_DIRECTORY "${QMSI_DIR}")
+ message("Using QMSI_DIR: ${QMSI_DIR}")
+else()
+ message("Detecting QMSI_DIR..")
+
+ find_path(QMSI_DIR qm_common.h
+ HINTS "${ISSM_DIR}/firmware/bsp/1.0/include"
+ NO_DEFAULT_PATH)
+
+ if(IS_DIRECTORY "${QMSI_DIR}")
+ message("Found QMSI_DIR: ${QMSI_DIR}")
+ else()
+ message(FATAL_ERROR "Could not find QMSI directory")
+ endif()
+
+endif()
+
+# TODO: these directories should be validated
+list(APPEND includes "${ISSM_DIR}/firmware/bsp/1.0/include")
+list(APPEND includes "${ISSM_DIR}/firmware/bsp/1.0/board/drivers")
+#list(APPEND includes "${ISSM_DIR}/firmware/bsp/1.0/drivers/include")
+list(APPEND includes "${ISSM_DIR}/firmware/bsp/1.0/drivers/bmc150")
+
+if (INTEL_QUARK_CHIP STREQUAL D2000)
+ list(APPEND includes "${ISSM_DIR}/firmware/bsp/1.0/soc/quark_d2000/include")
+ set(ld_file "${ISSM_DIR}/firmware/bsp/1.0/soc/quark_d2000/quark_d2000.ld")
+elseif (INTEL_QUARK_CHIP STREQUAL SE)
+ list(APPEND includes "${ISSM_DIR}/firmware/bsp/1.0/soc/quark_se/include")
+endif()
+
+# QMSI Library
+file(GLOB_RECURSE qmsi_sources ${ISSM_DIR}/firmware/bsp/1.0/drivers/*.c)
+add_library(qmsi STATIC ${qmsi_sources})
+target_include_directories(qmsi PUBLIC "${ISSM_DIR}/firmware/bsp/1.0/drivers/include")
+
+# SYS Library - dunno if this really is the best name
+file(GLOB_RECURSE intel_sys ${ISSM_DIR}/firmware/bsp/1.0/sys/*.c)
+add_library(intel_sys STATIC ${intel_sys})
+#target_include_directories(intel_sys PUBLIC "${ISSM_DIR}/firmware/bsp/1.0/drivers/include")
+target_link_libraries(intel_sys PRIVATE qmsi)
+
+# BMC Library
+file(GLOB_RECURSE bmc_sources ${ISSM_DIR}/firmware/bsp/1.0/board/drivers/bmc150/*.c)
+add_library(bmc STATIC ${bmc_sources})
+target_link_libraries(bmc PRIVATE qmsi)
+target_include_directories(bmc PUBLIC "${ISSM_DIR}/firmware/bsp/1.0/board/drivers/bmc150")
+
+# IPP Library
+#file(GLOB_RECURSE ipp_sources ${ISSM_DIR}/firmware/lib/ipp/1.0.0/*.c)
+add_library(ipp STATIC IMPORTED)
+set_property(TARGET ipp PROPERTY IMPORTED_LOCATION "${ISSM_DIR}/firmware/lib/ipp/1.0.0/lib/libippsq.a")
+#target_include_directories(ipp PUBLIC "${ISSM_DIR}/firmware/lib/ipp/1.0.0/include")
+set_property(TARGET ipp APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ISSM_DIR}/firmware/lib/ipp/1.0.0/include")
+#target_compile_definitions(ipp PUBLIC -D__IPP_ENABLED__)
+#target_compile_options(ipp PUBLIC -Wno-empty-body)
+#target_link_libraries(ipp INTERFACE qmsi)
+
+# Compilation
+# -O0
+# -g
+# -DDEBUG
+# -fmessage-length=0
+# -I../include
+# -fno-asynchronous-unwind-tables
+# -I../drivers
+# -I../drivers/include
+#
+# -DSPI_IRQ_MST
+# -I../soc/quark_d2000/include
+# -c
+# -o ../drivers/debug/quark_d2000/obj/qm_i2c.o
+# ../drivers/qm_i2c.c
+
+# Linking
+# i586-intel-elfiamcu-gcc
+# -nostdlib
+# -L./bsp/build/debug/quark_d2000/libqmsi/lib
+# -Xlinker -T./bsp/soc/quark_d2000/quark_d2000.ld
+# -Xlinker -A
+# -Xlinker --oformat
+# -Xlinker -Map=./debug/quark_d2000/obj/accel_test.map
+# -o ./debug/quark_d2000/obj/accel_test.elf
+# ./debug/quark_d2000/obj/main.o
+# ./bsp/sys/debug/quark_d2000/obj/app_entry.o
+# ./bsp/sys/debug/quark_d2000/obj/newlib-syscalls.o
+# ./bsp/board/drivers/debug/quark_d2000/obj/bmc150.o
+# -L/home/trygvis/intel/issm_2016.0.019/firmware/lib/ipp/1.0.0/lib
+# -lippsq
+# -lc
+# -lnosys
+# -lsoftfp
+# -lgcc
+# -lqmsi
+
+set(o_level "$<TARGET_PROPERTY:O_LEVEL>")
+add_compile_options("$<$<BOOL:${o_level}>:-O${o_level}>$<$<NOT:$<BOOL:${o_level}>>:-O3>")
+unset(o_level)
+
+include_directories("${includes}")
+set(CMAKE_C_FLAGS "${BASE_FLAGS} ${TARGET_FLAGS} " CACHE STRING "c flags")
+set(CMAKE_CXX_FLAGS "${BASE_FLAGS} ${TARGET_FLAGS} -fno-exceptions -fno-rtti -felide-constructors -std=c++14" CACHE STRING "c++ flags")
+
+# ${CMAKE_C_FLAGS} is prepended to this string
+set(LD_FILE )
+set(linker_flags "")
+set(linker_flags "${linker_flags} -nostdlib")
+set(linker_flags "${linker_flags} -Xlinker -A")
+set(linker_flags "${linker_flags} -Xlinker --oformat")
+
+#set(LINKER_LIBS "-larm_cortexM4l_math -lm")
+
+# http://stackoverflow.com/questions/16588097/cmake-separate-linker-and-compiler-flags
+set(CMAKE_EXE_LINKER_FLAGS "${linker_flags}" CACHE STRING "linker flags" FORCE)
+#unset(linker_flags)
+
+set(GCC "${ISSM_DIR}/tools/compiler/bin/${TRIPLE}-gcc")
+
+if(NOT EXISTS "${GCC}")
+ message(FATAL_ERROR "Could not find ${TRIPLE}-gcc. Is $ISSM_DIR set correctly?")
+endif()
+
+# No C++ support for D2000
+# set(GXX "${ISSM_DIR}/tools/compiler/bin/${TRIPLE}-g++")
+# if(NOT EXISTS "${GXX}")
+# message(FATAL_ERROR "Could not find ${TRIPLE}-g++. Is $ISSM_DIR set correctly?")
+# endif()
+# cmake_force_cxx_compiler("${GXX}" GNU)
+
+cmake_force_c_compiler("${GCC}" GNU)
+
+# search for programs in the build host directories
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+# for libraries and headers in the target directories
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+
+function(toolchain_target TARGET)
+ target_link_libraries("${TARGET}" intel_sys)
+ target_link_libraries("${TARGET}" qmsi)
+ target_link_libraries("${TARGET}" ipp)
+ target_link_libraries("${TARGET}" bmc)
+ target_link_libraries("${TARGET}" softfp)
+ target_link_libraries("${TARGET}" c)
+ target_link_libraries("${TARGET}" g)
+# target_link_libraries("${TARGET}" gcc)
+ target_compile_definitions("${TARGET}" PUBLIC -D__IPP_ENABLED__)
+ target_link_libraries("${TARGET}" "-Xlinker" "-T${ld_file}")
+endfunction()