Skip to content

Commit

Permalink
Add target_top_level_statement command
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Nov 10, 2024
1 parent 603142a commit 4b8dd68
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions scripts/cmake/xtd_commands.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,57 @@ macro(target_startup ...)
set(PROJECT_SOURCES "${PROJECT_SOURCES};${STARTUP_FILE}")
endmacro()

## @brief Generates top-level statements with specified source file.
## @param TOP_LEVEL_FILE the file that contains the content of the main entry point.
## @remarks Do not use this method of startup_(...) is present in your files or if you use standard c++ main() method.
## @remarks Call only once by project.
## @remarks This method must be call before target_type().
## @remarks This method is optional.
## @par Examples
## ```cpp
## cmake_minimum_required(VERSION 3.20)
##
## project(my_project)
## find_package(xtd REQUIRED)
## add_sources(my_project.cpp)
##
## target_top_level_statement(my_project.cpp)
## target_type(GUI_APPLICATION)
## ```
macro(target_top_level_statement TOP_LEVEL_FILE)
message(VERBOSE "Add top level statement [\"${TOP_LEVEL_FILE}\"]...")
set(STARTUP_FILE properties/startup.cpp)
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" TOP_LEVEL_FILE ${TOP_LEVEL_FILE})
file(RELATIVE_PATH STARTUP_OBJECT_RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Properties ${CMAKE_CURRENT_SOURCE_DIR}/${TOP_LEVEL_FILE})
set(INCLUDE_FILE "#include \"${STARTUP_OBJECT_RELATIVE_PATH}\"\n")
file(WRITE ${STARTUP_FILE}
"#pragma region xtd generated code\n"
"// This code was generated by CMake script.\n"
"//\n"
"// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.\n"
"\n"
"#include <xtd/xtd>\n"
"\n"
"auto main() -> int {\n"
" xtd::startup::safe_run([] {\n"
" using namespace xtd;\n"
" using namespace xtd::collections::generic;\n"
" using namespace xtd::io;\n"
" //using namespace xtd::linq;\n"
" //using namespace xtd::net::http;\n"
" using namespace xtd::threading;\n"
" using namespace xtd::threading::tasks;\n"
" \n"
" ${INCLUDE_FILE}"
" });\n"
"}\n"
"#pragma endregion\n"
)
#source_group(src\\properties FILES ${STARTUP_FILE})
auto_source_group(${STARTUP_FILE})
set(PROJECT_SOURCES "${PROJECT_SOURCES};${STARTUP_FILE}")
endmacro()

## @brief Specifies the type of application to build.
## @param TYPE Type of application.
## Possible values :
Expand Down

0 comments on commit 4b8dd68

Please sign in to comment.