cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) project(SX7H_Shifter VERSION 0.2.0 LANGUAGES C ASM) add_executable(SX7H_Shifter ${CMAKE_CURRENT_SOURCE_DIR}/Application/source/main.c) set_target_properties(SX7H_Shifter PROPERTIES SUFFIX ".elf") # get git tag execute_process( COMMAND git --git-dir ${PROJECT_SOURCE_DIR}/.git describe --tags TIMEOUT 10 # if this lasts more then 10s something is wrong OUTPUT_VARIABLE GIT_TAG ) string(REGEX REPLACE "\n$" "" GIT_TAG "${GIT_TAG}") string(REGEX MATCH "[0-9][0-9].[0-9][0-9].[0-9][0-9][0-9]" SX7H_Shifter_VERSION "${GIT_TAG}") # get git commit id execute_process( COMMAND git --git-dir ${PROJECT_SOURCE_DIR}/.git rev-parse --short HEAD TIMEOUT 10 # if this lasts more then 10s something is wrong OUTPUT_VARIABLE COMMIT_ID ) string(REGEX REPLACE "\n$" "" COMMIT_ID "${COMMIT_ID}") # get cmake arguments list get_cmake_property(CACHE_VARS CACHE_VARIABLES) foreach(CACHE_VAR ${CACHE_VARS}) get_property(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING) if(CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on the command line.") get_property(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE) if(CACHE_VAR_TYPE STREQUAL "UNINITIALIZED") set(CACHE_VAR_TYPE) else() set(CACHE_VAR_TYPE :${CACHE_VAR_TYPE}) endif() set(CMAKE_ARGS "${CMAKE_ARGS} -D${CACHE_VAR}${CACHE_VAR_TYPE}=\"${${CACHE_VAR}}\"") endif() endforeach() string(REGEX REPLACE "\"" "'" CMAKE_ARGS "${CMAKE_ARGS}") # version info set(PROJECT_NAME ${PROJECT_NAME}) set(SX7H_Shifter_VERSION ${SX7H_Shifter_VERSION}) set(BUILD_ID 0) set(GIT_TAG ${GIT_TAG}) set(COMMIT_ID ${COMMIT_ID}) set(BOARD_CONFIG ${BOARD_CONFIG}) set(CMAKE_STRING ${CMAKE_ARGS}) # add version info in version.h configure_file ( "${PROJECT_SOURCE_DIR}/version.h.in" "${PROJECT_BINARY_DIR}/version.h" ) # Set a default build type if none was specified if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "[INFO]: Setting build type to Debug as none was specified.") set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "RelWithDebInfo") # Set the possible values of build type for cmake-gui endif() # set(BOARD_CONFIG "L1_BP_f091" CACHE STRING "Choose the type of board configuration") # set_property(CACHE BOARD_CONFIG PROPERTY STRINGS L1_BP_f091 L1_BP_l443 L4_CAHB_f091 L4_CAHB_l443 L3_XXXX_f091) # if(BOARD_CONFIG STREQUAL "L1_BP_f091" OR BOARD_CONFIG STREQUAL "L1_BP_l443") # set(ACTUATOR_TYPE "TLT" CACHE STRING "Choose the type of ACTUATOR version") # set_property(CACHE ACTUATOR_TYPE PROPERTY STRINGS TLT MAX7) # elseif(BOARD_CONFIG STREQUAL "L4_CAHB_f091" OR BOARD_CONFIG STREQUAL "L4_CAHB_l443") # set(ACTUATOR_TYPE "CAHB12" CACHE STRING "Choose the type of ACTUATOR version") # set_property(CACHE ACTUATOR_TYPE PROPERTY STRINGS CAHB12 CAHB24) # elseif(BOARD_CONFIG STREQUAL "L3_XXXX_f091") # set(ACTUATOR_TYPE "CAHB12" CACHE STRING "Choose the type of ACTUATOR version") # set_property(CACHE ACTUATOR_TYPE PROPERTY STRINGS CAHB12 CAHB24) # endif() # set(APP_CONFIG "SIMPLE_SLAVE" CACHE STRING "Choose the type of can node") # set_property(CACHE APP_CONFIG PROPERTY STRINGS SYNC2 SIMPLE_SLAVE IO SYNC2IO) # set(COMM_CONFIG "CANOPEN" CACHE STRING "Choose the type of communication") # set_property(CACHE COMM_CONFIG PROPERTY STRINGS CANOPEN J1939 USART) # set(ENCODER_TYPE "CAPACITIVE" CACHE STRING "Choose the type of the encoder") # set_property(CACHE ENCODER_TYPE PROPERTY STRINGS CAPACITIVE MAGNETIC INCREMENTAL) # #Board Selection # if(BOARD_CONFIG STREQUAL "L1_BP_f091") # set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "bp_f091") # set(ENCODER_TYPE "CAPACITIVE") # this will overwrite whatever parameter is set in command line # set(COMM_CONFIG "CANOPEN") # this will overwrite whatever parameter is set in command line # set(GENERIC_FLAGS "-mcpu=cortex-m0 -mthumb") # set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options") # set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options") # set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options") # set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L1_BP_f091/STM32F091CBTx_FLASH.ld") # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}") # add_subdirectory(SX7H_Shifter_hal/L1_BP_f091) # elseif(BOARD_CONFIG STREQUAL "L1_BP_l443") # set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "bp_l443") # set(ENCODER_TYPE "CAPACITIVE") # this will overwrite whatever parameter is set in command line # set(COMM_CONFIG "CANOPEN") # this will overwrite whatever parameter is set in command line # set(GENERIC_FLAGS "-mcpu=cortex-m4 -mthumb") # set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options") # set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options") # set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options") # set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L1_BP_l443/STM32L443CCTX_FLASH.ld") # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}") # add_subdirectory(SX7H_Shifter_hal/L1_BP_l443) # elseif(BOARD_CONFIG STREQUAL "L4_CAHB_f091") # set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "cahb_f091") # set(ENCODER_TYPE "MAGNETIC") # this will overwrite whatever parameter is set in command line # set(COMM_CONFIG "J1939") # this will overwrite whatever parameter is set in command line # set(GENERIC_FLAGS "-mcpu=cortex-m0 -mthumb") # set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options") # set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options") # set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options") # set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L4_CAHB_f091/STM32F091CBTx_FLASH.ld") # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}") # add_subdirectory(SX7H_Shifter_hal/L4_CAHB_f091) # elseif(BOARD_CONFIG STREQUAL "L4_CAHB_l443") # set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "cahb_l443") # set(ENCODER_TYPE "MAGNETIC") # this will overwrite whatever parameter is set in command line # set(COMM_CONFIG "J1939") # this will overwrite whatever parameter is set in command line # set(GENERIC_FLAGS "-mcpu=cortex-m4 -mthumb") # set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options") # set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options") # set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options") # set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L4_CAHB_l443/STM32L443CCTX_FLASH.ld") # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}") # add_subdirectory(SX7H_Shifter_hal/L4_CAHB_l443) # elseif(BOARD_CONFIG STREQUAL "L3_XXXX_f091") set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "xl6600") # set(ENCODER_TYPE "MAGNETIC") # this will overwrite whatever parameter is set in command line # set(COMM_CONFIG "J1939") # this will overwrite whatever parameter is set in command line set(GENERIC_FLAGS "-mcpu=cortex-m3 -mthumb") set(CMAKE_C_FLAGS "${GENERIC_FLAGS} --specs=nano.specs -std=gnu11 -ffunction-sections -fdata-sections -Wall -fstack-usage" CACHE INTERNAL "C Compiler options") set(CMAKE_ASM_FLAGS "${GENERIC_FLAGS}" CACHE INTERNAL "ASM Compiler options") set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -static -Wl,--print-memory-usage -Wl,--start-group -lc -lm -Wl,--end-group" CACHE INTERNAL "Linker options") set(LINKER_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SX7H_Shifter_hal/L3_XXXX_f091/STM32F091CBTx_FLASH.ld") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T${LINKER_SCRIPT_PATH}") # add_subdirectory(SX7H_Shifter_hal/L3_XXXX_f091) # endif() #string(APPEND CMAKE_C_FLAGS " -lglapi") string(APPEND CMAKE_C_FLAGS " -save-temps") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-wchar-size-warning") #CAN communication stack Selection # if(COMM_CONFIG STREQUAL "CANOPEN") # add_subdirectory(drivers/canopen) # target_link_libraries(SX7H_Shifter PRIVATE SX7H_Shifter-hal canfestival LL-SX7H_Shifter Appl-SX7H_Shifter) # elseif(COMM_CONFIG STREQUAL "J1939") # add_subdirectory(drivers/j1939) # target_link_libraries(SX7H_Shifter PRIVATE SX7H_Shifter-hal j1939-hal LL-SX7H_Shifter Appl-SX7H_Shifter) # elseif(COMM_CONFIG STREQUAL "USART") # endif() target_compile_definitions(SX7H_Shifter PRIVATE ${MCU_CONFIG}) get_target_property(ELF_NAME SX7H_Shifter OUTPUT_NAME) if(CMAKE_BUILD_TYPE STREQUAL "Release") set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "${ELF_NAME}_Release") elseif(CMAKE_BUILD_TYPE STREQUAL "Debug") set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "${ELF_NAME}_Debug") elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") set_target_properties(SX7H_Shifter PROPERTIES OUTPUT_NAME "${ELF_NAME}_RelWithDebInfo") endif() add_subdirectory(Application) add_subdirectory(Cmsis) add_subdirectory(Driver) add_subdirectory(Hal) target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Application/include) target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Cmsis/Core) target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Cmsis/Startup) target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Driver/include) target_include_directories(SX7H_Shifter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Hal/include) get_target_property(PREFIX SX7H_Shifter PREFIX) get_target_property(NAME SX7H_Shifter OUTPUT_NAME) get_target_property(SUFFIX SX7H_Shifter SUFFIX) add_custom_target(bin) add_custom_command( TARGET bin POST_BUILD COMMAND ${CMAKE_OBJCOPY} --gap-fill 0xFF -O binary --remove-section=.isr_vector_dup ${PREFIX}${NAME}${SUFFIX} ${PREFIX}${NAME}.bin DEPENDS "${PREFIX}${NAME}${SUFFIX}" )