project(linux C ASM) cmake_minimum_required(VERSION 3.2) find_package(BISON) set(LIBV "6.6.0") set(Upstream_VERSION 6.6.0) if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR "x86") set(linuxarch x86) endif() add_definitions( -DKERNELVERSION=Upstream_VERSION -DARCH=x86_64 ) if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") add_definitions(-DLLVM=1) add_definitions(-DCC=clang) add_definitions(-D AS_IS_LLVM=TRUE) list(APPEND LINUXCMDOPTS LLVM=1) message(STATUS "Using compiler: ${CMAKE_C_COMPILER_ID}") add_compile_options( "-fintegrated-as" "-Werror=unknown-warning-option" "-Werror=ignored-optimization-argument" "-Werror=option-ignored" "-Werror=unused-command-line-argument" ) elseif("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") message(STATUS "Using compiler: ${CMAKE_C_COMPILER_ID}") add_definitions(-DGCC) add_definitions(-DCC=gcc) else() message(FATAL_ERROR "Your Compiler: ${CMAKE_C_COMPILER_ID} aren't supported") endif() list(APPEND LINUXCMDOPTS "ASM=${CMAKE_ASM_COMPILER}" "CC=${CMAKE_C_COMPILER}" "LD=${CMAKE_LINKER}" "srctree=${CMAKE_SOURCE_DIR}" "SRCARCH=${linuxarch}" "ARCH=${CMAKE_SYSTEM_PROCESSOR}" ) include_directories( ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} ) if(BISON_FOUND) find_program(bison flex ) find_program(yacc yacc ) set(menuconfigsrc scripts/kconfig/mconf.c scripts/kconfig/lxdialog/checklist.c scripts/kconfig/lxdialog/inputbox.c scripts/kconfig/lxdialog/menubox.c scripts/kconfig/lxdialog/textbox.c scripts/kconfig/lxdialog/util.c scripts/kconfig/lxdialog/yesno.c scripts/kconfig/confdata.c scripts/kconfig/expr.c scripts/kconfig/menu.c scripts/kconfig/preprocess.c scripts/kconfig/symbol.c scripts/kconfig/util.c scripts/kconfig/mconf.c ) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig/lexer.c ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig/parser.tab.h COMMAND flex -o lexer.c -d "${CMAKE_SOURCE_DIR}/scripts/kconfig/lexer.l" COMMAND yacc -o parser.tab.h "${CMAKE_SOURCE_DIR}/scripts/kconfig/parser.y" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig ) add_custom_target(menuconfig DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig/lexer.c ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig/parser.tab.h WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig ) add_executable(menuexe EXCLUDE_FROM_ALL ${menuconfigsrc} #generated by command flex ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig/lexer.c #generated by command yacc ${CMAKE_CURRENT_BINARY_DIR}/scripts/kconfig/parser.tab.h ) target_include_directories(menuexe PRIVATE ${CMAKE_SOURCE_DIR}/scripts/kconfig ) target_compile_definitions(menuexe PRIVATE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 ) target_compile_definitions(menuexe PRIVATE -DYYDEBUG=1 ) target_link_libraries(menuexe ncursesw tinfo ) add_dependencies(menuconfig menuexe) list(JOIN LINUXCMDOPTS ";" MENUCMD) add_custom_command( TARGET menuconfig POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig ${CMAKE_CURRENT_BINARY_DIR}/Kconfig ) add_custom_command( TARGET menuconfig COMMAND ${MENUCMD} $ "Kconfig" DEPENDS menuexe WORKING_DIRECTORY ${CMAKE_BINARY_DIR} USES_TERMINAL ) endif(BISON_FOUND)