#Portable implementation of the BSD config program. #Updated to generate cmake script files. #This config program will run on BSD/Linux/Windows, and allows us to build the #BSD kernel on any HOST PLATFORM supported by cmake using any TOOLCHAIN #supported by cmake (for example Visual Studio, clang or gcc). This in turn #allows us to use a wide range of BSD/Linux/Windows tools like static #analyzers etc on the BSD kernel source code which do not require us to #actually run the kernel on the final target. cmake_minimum_required(VERSION 3.1) project (bsdconfig) include (CheckSymbolExists) find_package (BISON REQUIRED) find_package (FLEX REQUIRED) find_package (getopt CONFIG REQUIRED) find_package (file2c CONFIG REQUIRED) check_symbol_exists ("strlcpy" "string.h" HAVE_STRLCPY) check_symbol_exists ("strlcat" "string.h" HAVE_STRLCAT) flex_target (config_lexer lang.l ${CMAKE_CURRENT_BINARY_DIR}/config-lexer.lex.cpp DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/y.tab.h ) bison_target (config_parser config.y ${CMAKE_CURRENT_BINARY_DIR}/config-parser.tab.cpp DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/y.tab.h ) add_flex_bison_dependency (config_lexer config_parser) add_executable (config "") add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/kernconf.c COMMAND file2c ${CMAKE_CURRENT_SOURCE_DIR}/kernconf.tmpl ${CMAKE_CURRENT_BINARY_DIR}/kernconf.c "char kernconfstr [] = {" ",0};" DEPENDS ${CMAKE_SOURCE_DIR}/kernconf.tmpl ) target_sources (config PRIVATE config.h configvers.h main.cpp mkheaders.cpp mkmakefile.cpp mkcmakefile.cpp mkoptions.cpp sbuf/subr_sbuf.c include/err.h sys/sbuf.h portable/verr.c portable/err.c portable/errx.c portable/verrx.c ${CMAKE_CURRENT_BINARY_DIR}/kernconf.c lang.l config.y ${FLEX_config_lexer_OUTPUTS} ${BISON_config_parser_OUTPUTS} ) #Files we generate source files from. #We want them listed in the solution explorer view of Visual Studio. source_group ("SBuf" FILES sys/sbuf.h sbuf/subr_sbuf.c) source_group ("Error Handling" FILES include/err.h portable/verr.c portable/err.c portable/errx.c portable/verrx.c) #source_group ("Nvlist" FILES include/common_impl.h include/nv_impl.h sys/cnv.h sys/nv.h include/nvlist_impl.h include/nvpair_impl.h nv/cnvlist.c nv/nvlist.c nv/nvpair.c) source_group ("Parser" FILES lang.l config.y) source_group ("Generated" FILES ${FLEX_config_lexer_OUTPUTS} ${BISON_config_parser_OUTPUTS} ${CMAKE_CURRENT_BINARY_DIR}/kernconf.c) #source_group ("Portability Layer" FILES sys/endian.h sys/queue.h) if (WIN32) target_sources (config PRIVATE win32/realpath.c) source_group ("Portability Layer" FILES win32/realpath.c) endif() if (NOT HAVE_STRLCPY) target_sources (config PRIVATE portable/strlcpy.c) target_include_directories (config PRIVATE portable) source_group ("Portability Layer" FILES portable/strlcpy.c) endif() if (NOT HAVE_STRLCAT) target_sources (config PRIVATE portable/strlcat.c) target_include_directories (config PRIVATE portable) source_group ("Portability Layer" FILES portable/strlcat.c) endif() target_include_directories (config PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/sys ${CMAKE_CURRENT_BINARY_DIR} ) #If getopt() must be linked in explicitly, do so... if (TARGET getopt) target_link_libraries (config getopt) endif() if (MSVC) target_compile_definitions(config PRIVATE _CRT_SECURE_NO_WARNINGS MAXPATHLEN=260 YY_NO_UNISTD_H __va_list=... __extension__=) endif (MSVC) install (TARGETS config RUNTIME DESTINATION bin)