unified_retro_keyboard/firmware/asdf/src/CMakeLists.txt
Dave 9aa3bf4681 Fix compiler warning for GCC >= 11.3
- GCC version 12 generates a warnings for certain pointer
references.  Apparently this is to decect invalid offsets.  To properly
compiler, the recommended remedy is to add the compiler option
"--param=min-pagesize=0" to the flags.  This option was introduced in
version 11.3, so we need to check the compiler version and only add for
>11.3.

- Moved setting of compiler flags to a new function c_toolchain_flags in
the toolchain file "generic-gcc-avr.cmake".  This function is now called
from the CMakeLists.txt file in the src directory.  This allows the test
for the compiler version to be specified in the toolchain file, but not
executed until called by the src subdir CMakeLists.txt.  Delaying
evaluation of the function ensures that the CMAKE_C_VERSION variable is
properly set when the function is called.

- Moving the compiler flags out of the source dir CMakeLists.txt file
also improves portability by moving architecture-specific compiler
details from the source tree to the toolchain file.
2022-09-02 00:00:55 -05:00

110 lines
3.6 KiB
CMake

message("C compiler: ${CMAKE_C_COMPILER}")
function(create_keymap_setups keymaps keymap_table)
list(TRANSFORM keymaps REPLACE "<\(.+\):\(.+\)>" "\n case \\2: setup_\\1_keymap();break" OUTPUT_VARIABLE temp_list)
# we can keep the ';' cmake list separators as the C statement separators.
# However, we need to append an extra ';' at the end.
string(APPEND temp_list ";")
set(${keymap_table} "${temp_list}" PARENT_SCOPE)
endfunction(create_keymap_setups)
function(create_keymap_valid keymaps keymap_valid)
list(TRANSFORM keymaps REPLACE "<\(.+\):\(.+\)>" "\n case \\2:" OUTPUT_VARIABLE temp_list)
# we can keep the ';' cmake list separators as the C statement separators.
# However, we need to append an extra ';' at the end.
string(APPEND temp_list ";")
set(${keymap_valid} "${temp_list}" PARENT_SCOPE)
endfunction(create_keymap_valid)
function(create_keymap_declarations keymaps keymap_decl)
list(TRANSFORM keymaps REPLACE "<\(.+\):\(.+\)>" "\n void setup_\\1_keymap(void)" OUTPUT_VARIABLE temp_list)
# we can keep the ';' cmake list separators as the C statement separators.
# However, we need to append an extra ';' at the end.
string(APPEND temp_list ";")
set(${keymap_decl} "${temp_list}" PARENT_SCOPE)
endfunction(create_keymap_declarations)
function(create_keymap_report keymaps keymap_report)
list(TRANSFORM keymaps REPLACE "<\(.+\):\(.+\)>" "\nkeymap [\\2]: \\1" OUTPUT_VARIABLE temp_list)
string(REPLACE ";" "" temp_list2 "${temp_list}")
set(${keymap_report} "${temp_list2}" PARENT_SCOPE)
endfunction(create_keymap_report)
include(../keymap_list.cmake)
create_keymap_setups("${keymap_list}" keymap_table)
create_keymap_valid("${keymap_list}" keymap_valid)
create_keymap_report("${keymap_list}" keymap_report)
create_keymap_declarations("${keymap_list}" keymap_declarations)
# get list length and decrement by one to account for trailing semicolon
list (LENGTH keymap_list num_keymaps)
message("**********************")
message("Keymap table: ${keymap_report}")
message("**********************\n\n")
set (ASDF_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
configure_file(${ASDF_SRC_DIR}/Arch/asdf_arch_${ARCH}.h ${CMAKE_CURRENT_BINARY_DIR}/asdf_arch.h COPYONLY)
configure_file(${ASDF_SRC_DIR}/Arch/asdf_arch_${ARCH}.c ${CMAKE_CURRENT_BINARY_DIR}/asdf_arch.c COPYONLY)
configure_file(${ASDF_SRC_DIR}/asdf_keymap_setup.c.in ${CMAKE_CURRENT_BINARY_DIR}/asdf_keymap_setup.c)
configure_file(${ASDF_SRC_DIR}/asdf_keymap_setup.h.in ${CMAKE_CURRENT_BINARY_DIR}/asdf_keymap_setup.h)
c_toolchain_flags()
list (APPEND SOURCES
asdf.c
${CMAKE_CURRENT_BINARY_DIR}/asdf_arch.c
${CMAKE_CURRENT_BINARY_DIR}/asdf_keymap_setup.c
asdf_buffer.c
asdf_hook.c
asdf_keymap_setup.c
asdf_keymaps.c
asdf_modifiers.c
asdf_physical.c
asdf_repeat.c
asdf_virtual.c
asdf_print.c
Keymaps/asdf_keymap_classic.c
Keymaps/asdf_keymap_classic_caps.c
Keymaps/asdf_keymap_classic_add_map.c
Keymaps/asdf_keymap_apple2.c
Keymaps/asdf_keymap_apple2_caps.c
Keymaps/asdf_keymap_apple2_add_map.c
Keymaps/asdf_keymap_sol.c
main.c
)
# create a library for the keymap modules
#add_subdirectory(Keymaps)
# add the executable
if (COMMAND custom_add_executable)
custom_add_executable(${ASDF_TARGET_NAME}
${SOURCES}
)
else()
add_executable(${ASDF_TARGET_NAME}
${SOURCES}
)
endif()
target_include_directories(${ASDF_EXECUTABLE_TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/Keymaps
)
target_compile_options(${ASDF_EXECUTABLE_TARGET_NAME}
PRIVATE
${CFLAGS}
)
#target_link_libraries(${ASDF_EXECUTABLE_TARGET_NAME}
# keymaps
# )