2020-05-15 07:52:37 +00:00
|
|
|
cmake_minimum_required(VERSION 3.16)
|
|
|
|
project(SerenityOS C CXX ASM)
|
2020-05-06 15:40:06 +00:00
|
|
|
|
2020-06-06 01:23:31 +00:00
|
|
|
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
|
|
|
|
message(FATAL
|
|
|
|
": Don't use CMAKE_BUILD_TYPE when building serenity.\n"
|
|
|
|
"The default build type is optimized with debug info and asserts enabled,\n"
|
|
|
|
"and that's all there is.")
|
|
|
|
endif()
|
|
|
|
|
2020-06-19 14:52:39 +00:00
|
|
|
set(CMAKE_INSTALL_MESSAGE NEVER)
|
|
|
|
|
2020-05-06 15:40:06 +00:00
|
|
|
enable_testing()
|
|
|
|
|
2020-11-11 22:59:06 +00:00
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
2020-05-06 15:40:06 +00:00
|
|
|
add_custom_target(run
|
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/Meta/run.sh
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
|
|
|
|
2020-06-20 01:04:42 +00:00
|
|
|
add_custom_target(image
|
|
|
|
DEPENDS qemu-image
|
|
|
|
)
|
|
|
|
add_custom_target(qemu-image
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E env "SERENITY_ROOT=${CMAKE_SOURCE_DIR}" ${CMAKE_SOURCE_DIR}/Meta/build-image-qemu.sh
|
|
|
|
BYPRODUCTS ${CMAKE_BINARY_DIR}/_disk_image
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
2020-05-26 21:51:18 +00:00
|
|
|
add_custom_target(grub-image
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E env "SERENITY_ROOT=${CMAKE_SOURCE_DIR}" ${CMAKE_SOURCE_DIR}/Meta/build-image-grub.sh
|
2020-05-28 08:08:38 +00:00
|
|
|
BYPRODUCTS ${CMAKE_BINARY_DIR}/grub_disk_image
|
2020-05-26 21:51:18 +00:00
|
|
|
USES_TERMINAL
|
|
|
|
)
|
|
|
|
|
2020-05-28 19:06:44 +00:00
|
|
|
add_custom_target(lint-shell-scripts
|
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/Meta/lint-shell-scripts.sh
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
|
|
|
add_custom_target(check-style
|
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/Meta/check-style.sh
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
|
|
|
|
2020-12-22 00:47:47 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2020-12-22 01:04:46 +00:00
|
|
|
add_compile_options(-Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -ftls-model=initial-exec)
|
|
|
|
|
2020-08-04 15:08:03 +00:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
2020-12-22 01:04:46 +00:00
|
|
|
add_compile_options(-fconcepts)
|
2020-08-04 15:08:03 +00:00
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
2020-12-22 01:04:46 +00:00
|
|
|
add_compile_options(-Wno-overloaded-virtual)
|
2020-08-04 15:08:03 +00:00
|
|
|
endif()
|
2020-05-06 15:40:06 +00:00
|
|
|
|
2020-08-26 22:59:36 +00:00
|
|
|
if (ALL_THE_DEBUG_MACROS)
|
2020-12-21 17:48:32 +00:00
|
|
|
include(Meta/all_the_debug_macros.cmake)
|
2020-08-26 22:59:36 +00:00
|
|
|
endif(ALL_THE_DEBUG_MACROS)
|
|
|
|
|
2020-05-06 15:40:06 +00:00
|
|
|
include_directories(Libraries)
|
|
|
|
include_directories(.)
|
|
|
|
|
|
|
|
add_subdirectory(Meta/Lagom)
|
|
|
|
add_subdirectory(DevTools/IPCCompiler)
|
|
|
|
add_subdirectory(Libraries/LibWeb/CodeGenerators)
|
|
|
|
add_subdirectory(AK/Tests)
|
LibRegex: Add a regular expression library
This commit is a mix of several commits, squashed into one because the
commits before 'Move regex to own Library and fix all the broken stuff'
were not fixable in any elegant way.
The commits are listed below for "historical" purposes:
- AK: Add options/flags and Errors for regular expressions
Flags can be provided for any possible flavour by adding a new scoped enum.
Handling of flags is done by templated Options class and the overloaded
'|' and '&' operators.
- AK: Add Lexer for regular expressions
The lexer parses the input and extracts tokens needed to parse a regular
expression.
- AK: Add regex Parser and PosixExtendedParser
This patchset adds a abstract parser class that can be derived to implement
different parsers. A parser produces bytecode to be executed within the
regex matcher.
- AK: Add regex matcher
This patchset adds an regex matcher based on the principles of the T-REX VM.
The bytecode pruduced by the respective Parser is put into the matcher and
the VM will recursively execute the bytecode according to the available OpCodes.
Possible improvement: the recursion could be replaced by multi threading capabilities.
To match a Regular expression, e.g. for the Posix standard regular expression matcher
use the following API:
```
Pattern<PosixExtendedParser> pattern("^.*$");
auto result = pattern.match("Well, hello friends!\nHello World!"); // Match whole needle
EXPECT(result.count == 1);
EXPECT(result.matches.at(0).view.starts_with("Well"));
EXPECT(result.matches.at(0).view.end() == "!");
result = pattern.match("Well, hello friends!\nHello World!", PosixFlags::Multiline); // Match line by line
EXPECT(result.count == 2);
EXPECT(result.matches.at(0).view == "Well, hello friends!");
EXPECT(result.matches.at(1).view == "Hello World!");
EXPECT(pattern.has_match("Well,....")); // Just check if match without a result, which saves some resources.
```
- AK: Rework regex to work with opcodes objects
This patchsets reworks the matcher to work on a more structured base.
For that an abstract OpCode class and derived classes for the specific
OpCodes have been added. The respective opcode logic is contained in
each respective execute() method.
- AK: Add benchmark for regex
- AK: Some optimization in regex for runtime and memory
- LibRegex: Move regex to own Library and fix all the broken stuff
Now regex works again and grep utility is also in place for testing.
This commit also fixes the use of regex.h in C by making `regex_t`
an opaque (-ish) type, which makes its behaviour consistent between
C and C++ compilers.
Previously, <regex.h> would've blown C compilers up, and even if it
didn't, would've caused a leak in C code, and not in C++ code (due to
the existence of `OwnPtr` inside the struct).
To make this whole ordeal easier to deal with (for now), this pulls the
definitions of `reg*()` into LibRegex.
pros:
- The circular dependency between LibC and LibRegex is broken
- Eaiser to test (without accidentally pulling in the host's libc!)
cons:
- Using any of the regex.h functions will require the user to link -lregex
- The symbols will be missing from libc, which will be a big surprise
down the line (especially with shared libs).
Co-Authored-By: Ali Mohammad Pur <ali.mpfard@gmail.com>
2020-04-26 12:45:10 +00:00
|
|
|
add_subdirectory(Libraries/LibRegex/Tests)
|
2020-05-06 15:40:06 +00:00
|
|
|
|
2020-08-02 13:54:06 +00:00
|
|
|
set(write_if_different ${CMAKE_SOURCE_DIR}/Meta/write-only-on-difference.sh)
|
|
|
|
|
2020-05-26 18:20:24 +00:00
|
|
|
function(serenity_install_headers target_name)
|
2020-05-06 15:40:06 +00:00
|
|
|
file(GLOB_RECURSE headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
|
|
|
|
foreach(header ${headers})
|
|
|
|
get_filename_component(subdirectory ${header} DIRECTORY)
|
|
|
|
install(FILES ${header} DESTINATION usr/include/${target_name}/${subdirectory})
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
2020-08-15 12:11:10 +00:00
|
|
|
function(serenity_install_sources target_name)
|
|
|
|
file(GLOB_RECURSE sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.cpp")
|
|
|
|
foreach(source ${sources})
|
|
|
|
get_filename_component(subdirectory ${source} DIRECTORY)
|
|
|
|
install(FILES ${source} DESTINATION usr/src/serenity/${target_name}/${subdirectory})
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
2020-06-21 16:59:26 +00:00
|
|
|
function(serenity_generated_sources target_name)
|
2020-05-06 15:40:06 +00:00
|
|
|
if(DEFINED GENERATED_SOURCES)
|
|
|
|
set_source_files_properties(${GENERATED_SOURCES} PROPERTIES GENERATED 1)
|
|
|
|
foreach(generated ${GENERATED_SOURCES})
|
|
|
|
get_filename_component(generated_name ${generated} NAME)
|
|
|
|
add_dependencies(${target_name} generate_${generated_name})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2020-06-21 16:59:26 +00:00
|
|
|
function(serenity_lib target_name fs_name)
|
|
|
|
serenity_install_headers(${target_name})
|
2020-08-15 12:11:10 +00:00
|
|
|
serenity_install_sources("Libraries/${target_name}")
|
2020-10-17 11:39:36 +00:00
|
|
|
#add_library(${target_name} SHARED ${SOURCES} ${GENERATED_SOURCES})
|
|
|
|
add_library(${target_name} SHARED ${SOURCES} ${GENERATED_SOURCES} ${CMAKE_SOURCE_DIR}/Libraries/LibC/crt0_shared.cpp)
|
|
|
|
#library_sources("{target_name}" PRIVATE ${CMAKE_SOURCE_DIR}/Libraries/LibC/crt0_shared.cpp)
|
|
|
|
install(TARGETS ${target_name} DESTINATION usr/lib)
|
2020-06-21 16:59:26 +00:00
|
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
|
|
serenity_generated_sources(${target_name})
|
|
|
|
endfunction()
|
|
|
|
|
2020-10-17 11:39:36 +00:00
|
|
|
function(serenity_shared_lib target_name fs_name)
|
|
|
|
serenity_install_headers(${target_name})
|
|
|
|
serenity_install_sources("Libraries/${target_name}")
|
|
|
|
add_library(${target_name} SHARED ${SOURCES} ${GENERATED_SOURCES})
|
|
|
|
install(TARGETS ${target_name} DESTINATION usr/lib)
|
2020-05-06 15:40:06 +00:00
|
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
2020-06-21 16:59:26 +00:00
|
|
|
serenity_generated_sources(${target_name})
|
2020-05-06 15:40:06 +00:00
|
|
|
endfunction()
|
|
|
|
|
2020-10-17 11:39:36 +00:00
|
|
|
function(serenity_libc target_name fs_name)
|
2020-10-16 09:57:15 +00:00
|
|
|
serenity_install_headers("")
|
|
|
|
serenity_install_sources("Libraries/LibC")
|
2020-10-17 11:39:36 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -fpic")
|
2020-10-16 09:57:15 +00:00
|
|
|
add_library(${target_name} SHARED ${SOURCES})
|
|
|
|
install(TARGETS ${target_name} DESTINATION usr/lib)
|
|
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
|
|
target_link_directories(LibC PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
serenity_generated_sources(${target_name})
|
|
|
|
endfunction()
|
|
|
|
|
2020-11-20 12:18:53 +00:00
|
|
|
function(serenity_libc_static target_name fs_name)
|
|
|
|
serenity_install_headers("")
|
|
|
|
serenity_install_sources("Libraries/LibC")
|
|
|
|
add_library(${target_name} ${SOURCES})
|
|
|
|
install(TARGETS ${target_name} ARCHIVE DESTINATION usr/lib)
|
|
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
|
|
target_link_directories(${target_name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
serenity_generated_sources(${target_name})
|
|
|
|
endfunction()
|
|
|
|
|
2020-05-06 15:40:06 +00:00
|
|
|
function(serenity_bin target_name)
|
|
|
|
add_executable(${target_name} ${SOURCES})
|
2020-10-17 11:39:36 +00:00
|
|
|
target_sources(${target_name} PRIVATE ${CMAKE_SOURCE_DIR}/Libraries/LibC/crt0_shared.cpp)
|
2020-05-06 15:40:06 +00:00
|
|
|
install(TARGETS ${target_name} RUNTIME DESTINATION bin)
|
2020-06-21 16:59:26 +00:00
|
|
|
serenity_generated_sources(${target_name})
|
2020-05-06 15:40:06 +00:00
|
|
|
endfunction()
|
|
|
|
|
2020-12-20 18:26:09 +00:00
|
|
|
function(serenity_app target_name)
|
|
|
|
cmake_parse_arguments(SERENITY_APP "" "ICON" "" ${ARGN})
|
|
|
|
|
|
|
|
serenity_bin("${target_name}")
|
|
|
|
set(small_icon "${CMAKE_SOURCE_DIR}/Base/res/icons/16x16/${SERENITY_APP_ICON}.png")
|
|
|
|
set(medium_icon "${CMAKE_SOURCE_DIR}/Base/res/icons/32x32/${SERENITY_APP_ICON}.png")
|
2020-12-22 00:47:47 +00:00
|
|
|
|
2020-12-20 18:26:09 +00:00
|
|
|
if (EXISTS "${small_icon}")
|
|
|
|
embed_resource("${target_name}" serenity_icon_s "${small_icon}")
|
|
|
|
endif()
|
|
|
|
if (EXISTS "${medium_icon}")
|
|
|
|
embed_resource("${target_name}" serenity_icon_m "${medium_icon}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# TODO: Issue warnings if the app icons don't exist
|
|
|
|
endfunction()
|
|
|
|
|
2020-12-20 10:47:44 +00:00
|
|
|
function(compile_gml source output string_name)
|
2020-09-14 14:11:28 +00:00
|
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${output}
|
|
|
|
COMMAND ${write_if_different} ${output} ${CMAKE_SOURCE_DIR}/Meta/text-to-cpp-string.sh ${string_name} ${source}
|
|
|
|
VERBATIM
|
|
|
|
DEPENDS ${CMAKE_SOURCE_DIR}/Meta/text-to-cpp-string.sh
|
|
|
|
MAIN_DEPENDENCY ${source}
|
|
|
|
)
|
|
|
|
get_filename_component(output_name ${output} NAME)
|
|
|
|
add_custom_target(generate_${output_name} DEPENDS ${output})
|
|
|
|
endfunction()
|
|
|
|
|
2020-12-20 10:47:44 +00:00
|
|
|
|
2020-05-06 15:40:06 +00:00
|
|
|
function(compile_ipc source output)
|
|
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${output}
|
2020-08-02 13:54:06 +00:00
|
|
|
COMMAND ${write_if_different} ${output} ${CMAKE_BINARY_DIR}/DevTools/IPCCompiler/IPCCompiler ${source}
|
2020-05-06 15:40:06 +00:00
|
|
|
VERBATIM
|
|
|
|
DEPENDS IPCCompiler
|
|
|
|
MAIN_DEPENDENCY ${source}
|
|
|
|
)
|
|
|
|
get_filename_component(output_name ${output} NAME)
|
|
|
|
add_custom_target(generate_${output_name} DEPENDS ${output})
|
|
|
|
endfunction()
|
|
|
|
|
2020-12-20 18:26:09 +00:00
|
|
|
function(embed_resource target section file)
|
|
|
|
get_filename_component(asm_file "${file}" NAME)
|
|
|
|
set(asm_file "${CMAKE_CURRENT_BINARY_DIR}/${target}-${section}.s")
|
|
|
|
get_filename_component(input_file "${file}" ABSOLUTE)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${asm_file}"
|
2020-12-22 00:47:47 +00:00
|
|
|
COMMAND "${CMAKE_SOURCE_DIR}/Meta/generate-embedded-resource-assembly.sh" "${asm_file}" "${section}" "${input_file}"
|
2020-12-20 18:26:09 +00:00
|
|
|
DEPENDS "${input_file}" "${CMAKE_SOURCE_DIR}/Meta/generate-embedded-resource-assembly.sh"
|
|
|
|
COMMENT "Generating ${asm_file}"
|
|
|
|
)
|
|
|
|
target_sources("${target}" PRIVATE "${asm_file}")
|
|
|
|
endfunction()
|
|
|
|
|
2020-05-06 15:40:06 +00:00
|
|
|
find_program(CCACHE_PROGRAM ccache)
|
|
|
|
if(CCACHE_PROGRAM)
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
unset(CMAKE_SYSROOT)
|
|
|
|
set(CMAKE_STAGING_PREFIX ${CMAKE_BINARY_DIR}/Root)
|
|
|
|
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/Root)
|
|
|
|
set(CMAKE_INSTALL_DATAROOTDIR ${CMAKE_BINARY_DIR}/Root/res)
|
|
|
|
|
|
|
|
set(TOOLCHAIN_PATH ${CMAKE_SOURCE_DIR}/Toolchain/Local/bin)
|
|
|
|
set(TOOLCHAIN_PREFIX ${TOOLCHAIN_PATH}/i686-pc-serenity-)
|
|
|
|
|
|
|
|
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
|
|
|
|
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
|
|
|
|
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}gcc)
|
|
|
|
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
|
|
|
|
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib)
|
|
|
|
set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}strip)
|
|
|
|
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
|
|
|
|
|
2020-07-08 21:57:51 +00:00
|
|
|
foreach(lang ASM C CXX OBJC OBJCXX)
|
|
|
|
unset(CMAKE_${lang}_OSX_COMPATIBILITY_VERSION_FLAG)
|
|
|
|
unset(CMAKE_${lang}_OSX_CURRENT_VERSION_FLAG)
|
|
|
|
unset(CMAKE_${lang}_LINK_FLAGS)
|
|
|
|
unset(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS)
|
|
|
|
unset(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS)
|
|
|
|
unset(CMAKE_SHARED_MODULE_LOADER_${lang}_FLAG )
|
|
|
|
unset(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG)
|
|
|
|
unset(CMAKE_${lang}_SYSROOT_FLAG)
|
|
|
|
unset(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set(CMAKE_INSTALL_NAME_TOOL "true")
|
|
|
|
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
|
|
|
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-shared")
|
|
|
|
|
2020-05-06 15:40:06 +00:00
|
|
|
#FIXME: -fstack-protector
|
|
|
|
|
2020-12-22 01:04:46 +00:00
|
|
|
add_compile_options(-Os -g1 -fno-exceptions -fno-rtti -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-nonnull-compare -Wno-deprecated-copy -Wno-expansion-to-defined)
|
|
|
|
add_compile_options(-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.)
|
2020-05-06 15:40:06 +00:00
|
|
|
|
2020-12-22 01:04:46 +00:00
|
|
|
add_compile_definitions(DEBUG SANITIZE_PTRS)
|
2020-12-11 13:44:08 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_STATIC "${CMAKE_CXX_FLAGS} -static")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostartfiles -pie -fpic")
|
2020-12-22 00:47:47 +00:00
|
|
|
|
2020-05-06 15:40:06 +00:00
|
|
|
add_link_options(--sysroot ${CMAKE_BINARY_DIR}/Root)
|
|
|
|
|
2020-05-20 12:23:31 +00:00
|
|
|
include_directories(Libraries/LibC)
|
2020-08-12 08:44:45 +00:00
|
|
|
include_directories(Libraries/LibM)
|
2020-05-06 15:40:06 +00:00
|
|
|
include_directories(Services)
|
2020-09-14 10:51:12 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
2020-05-06 15:40:06 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/Services)
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/Libraries)
|
|
|
|
|
2020-05-26 18:20:24 +00:00
|
|
|
add_subdirectory(AK)
|
2020-05-06 15:40:06 +00:00
|
|
|
add_subdirectory(Kernel)
|
|
|
|
add_subdirectory(Libraries)
|
|
|
|
add_subdirectory(Services)
|
|
|
|
add_subdirectory(Applications)
|
|
|
|
add_subdirectory(Games)
|
|
|
|
add_subdirectory(DevTools)
|
|
|
|
add_subdirectory(MenuApplets)
|
|
|
|
add_subdirectory(Shell)
|
|
|
|
add_subdirectory(Demos)
|
|
|
|
add_subdirectory(Userland)
|