mirror of
https://github.com/fltk/fltk.git
synced 2026-08-17 00:23:56 +08:00
Fluid: new command line option -pr
...to genearte file relative to the project file instead of the corrent working directory * documentation updates
This commit is contained in:
@@ -20,6 +20,7 @@ Changes in FLTK 1.5.0 Released: xxx yy 2026
|
||||
|
||||
- The Strings file name for internationalization can now be fully customized.
|
||||
- Bigger and clearly assigned fields for custom code for widgets.
|
||||
- New command line argument `-pr` writes files relative to the project file.
|
||||
|
||||
Documentation Improvements
|
||||
|
||||
|
||||
+3
-3
@@ -166,7 +166,7 @@ std::string Project::projectfile_name() const {
|
||||
*/
|
||||
std::string Project::codefile_path() const {
|
||||
std::string path = fl_filename_path_str(code_file_name);
|
||||
if (Fluid.batch_mode)
|
||||
if (Fluid.batch_mode && !Fluid.args.project_relative)
|
||||
return end_with_slash(fl_filename_absolute_str(path, Fluid.launch_path()));
|
||||
else
|
||||
return end_with_slash(fl_filename_absolute_str(path, projectfile_path()));
|
||||
@@ -195,7 +195,7 @@ std::string Project::codefile_name() const {
|
||||
*/
|
||||
std::string Project::headerfile_path() const {
|
||||
std::string path = fl_filename_path_str(header_file_name);
|
||||
if (Fluid.batch_mode)
|
||||
if (Fluid.batch_mode && !Fluid.args.project_relative)
|
||||
return end_with_slash(fl_filename_absolute_str(path, Fluid.launch_path()));
|
||||
else
|
||||
return end_with_slash(fl_filename_absolute_str(path, projectfile_path()));
|
||||
@@ -228,7 +228,7 @@ std::string Project::headerfile_name() const {
|
||||
*/
|
||||
std::string Project::stringsfile_path() const {
|
||||
std::string path = fl_filename_path_str(strings_file_name);
|
||||
if (Fluid.batch_mode)
|
||||
if (Fluid.batch_mode && !Fluid.args.project_relative)
|
||||
return end_with_slash(fl_filename_absolute_str(path, Fluid.launch_path()));
|
||||
else
|
||||
return end_with_slash(fl_filename_absolute_str(path, projectfile_path()));
|
||||
|
||||
@@ -53,6 +53,7 @@ int Args::load(int argc,char **argv) {
|
||||
" -o <name> : .cxx output filename, or extension if <name> starts with '.'\n"
|
||||
" -h <name> : .h output filename, or extension if <name> starts with '.'\n"
|
||||
" -s <name> : i18n strings filename, or extension if <name> starts with '.'\n"
|
||||
" -pr : make all output file paths relative to the .fl project file path\n"
|
||||
" --help : brief usage information\n"
|
||||
" --version, -v : print fluid version number\n"
|
||||
" -d : enable internal debugging\n";
|
||||
@@ -95,6 +96,10 @@ int Args::arg(int argc, char** argv, int& i) {
|
||||
Fluid.debug_external_editor=1;
|
||||
i++; return 1;
|
||||
}
|
||||
if (strcmp(argv[i], "-pr")==0) {
|
||||
project_relative = true;
|
||||
i++; return 1;
|
||||
}
|
||||
if (argv[i][1] == 'u' && !argv[i][2]) {
|
||||
update_file++;
|
||||
Fluid.batch_mode++;
|
||||
|
||||
@@ -44,6 +44,9 @@ public:
|
||||
std::string autodoc_path { }; // fluid --autodoc path
|
||||
/// Set, if Fluid was started with the command line argument -v
|
||||
int show_version { 0 }; // fluid -v
|
||||
/// Make all output file paths relative to the .fl project file path
|
||||
/// instead of the current working directory, if set.
|
||||
bool project_relative { false }; // fluid -pr
|
||||
/// Constructor.
|
||||
Args() = default;
|
||||
// Load args from command line into variables.
|
||||
|
||||
@@ -48,29 +48,45 @@ FLUID understands all of the standard FLTK switches before the filename:
|
||||
<!-- ---------------------------------------------------------------------- -->
|
||||
\section commandline_passive Compile Tool Options
|
||||
|
||||
FLUID can also be called as a command-line only tool to create
|
||||
the `.cxx` and `.h` file from a `.fl` file directly. To do this type:
|
||||
FLUID can also be used as a command-line tool to generate `.cxx` and `.h`
|
||||
files directly from a `.fl` file. To do this, run:
|
||||
|
||||
```
|
||||
fluid -c filename.fl
|
||||
```
|
||||
|
||||
This is the same as the menu __File > Write Code...__ .
|
||||
It will read the `filename.fl` file and write
|
||||
`filename.cxx` and `filename.h`. Any leading
|
||||
directory on `filename.fl` will be stripped, so they are
|
||||
always written to the current directory. If there are any errors
|
||||
reading or writing the files, FLUID will print the error and
|
||||
exit with a non-zero code. You can use the following lines in a
|
||||
Makefile to automate the creation of the source and header
|
||||
files:
|
||||
This is equivalent to the menu command __File > Write Code...__.
|
||||
FLUID reads `filename.fl` and writes `filename.cxx` and `filename.h`.
|
||||
|
||||
If there are any errors while reading or writing the files, FLUID prints an
|
||||
error message and exits with a non-zero status code. If the generated C++ or
|
||||
header files are identical to the existing files, they are not overwritten to
|
||||
avoid unnecessary recompilation.
|
||||
|
||||
The output file names are stored in the `.fl` file, but they can be
|
||||
overridden from the command line:
|
||||
|
||||
- `-o filename` overrides the generated C++ file extension, name, or path
|
||||
- `-h filename` overrides the generated header file extension, name, or path
|
||||
- `-s filename` overrides the generated translation strings file extension, name, or path
|
||||
|
||||
In command line mode, relative output paths are interpreted relative to the
|
||||
current working directory. `-pr` changes this behavior and makes relative
|
||||
output paths use the directory of the `.fl` project file instead, as in
|
||||
interactive mode.
|
||||
|
||||
For details on how file names and paths are generated, see \ref setting_project.
|
||||
|
||||
|
||||
The following lines in a Makefile can be used to automate the creation of the
|
||||
source and header files:
|
||||
|
||||
```
|
||||
my_panels.h my_panels.cxx: my_panels.fl
|
||||
fluid -c my_panels.fl
|
||||
```
|
||||
|
||||
Most versions of "make" support rules that cause `.fl` files to be compiled:
|
||||
or as a more general rule:
|
||||
|
||||
```
|
||||
.SUFFIXES: .fl .cxx .h
|
||||
@@ -78,32 +94,51 @@ Most versions of "make" support rules that cause `.fl` files to be compiled:
|
||||
fluid -c $<
|
||||
```
|
||||
|
||||
Check `README.CMake.txt` for examples on how to integrate FLUID into the
|
||||
`CMake` build process.
|
||||
To automate this in `CMakeLists.txt`, add a custom command for the `.fl` file
|
||||
and list the generated `.cxx` file as a source of your target:
|
||||
|
||||
If you use
|
||||
```cmake
|
||||
find_package(FLTK CONFIG REQUIRED)
|
||||
|
||||
\code
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/MyUI.cxx ${CMAKE_CURRENT_BINARY_DIR}/MyUI.h
|
||||
COMMAND fltk::fluid -c ${CMAKE_CURRENT_SOURCE_DIR}/MyUI.fl
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MyUI.fl
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_executable(myapp
|
||||
main.cxx
|
||||
${CMAKE_CURRENT_BINARY_DIR}/MyUI.cxx
|
||||
)
|
||||
|
||||
target_include_directories(myapp PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(myapp PRIVATE fltk::fltk)
|
||||
```
|
||||
|
||||
FLUID also has basic support for internationalization:
|
||||
|
||||
```
|
||||
fluid -cs filename.fl
|
||||
\endcode
|
||||
```
|
||||
|
||||
FLUID will also write the "strings" for internationalization into the file
|
||||
'filename.txt', 'filename.po', or 'filename.msg', depending on the chosen type
|
||||
of i18n (menu: 'File/Write Strings...').
|
||||
This writes label strings and tooltip text to `filename.txt`, `filename.po`,
|
||||
or `filename.msg`, depending on the selected i18n type. See the menu command
|
||||
__File > Write Strings...__ or the *Locale* tab in the *Settings* dialog.
|
||||
|
||||
Finally there is another option which is useful for program developers
|
||||
who have many `.fl` files and want to upgrade them to the current FLUID
|
||||
version. FLUID will read the `filename.fl` file, save it, and exit
|
||||
immediately. This writes the file with current syntax and options and
|
||||
the current FLTK version in the header of the file. Use
|
||||
Another useful option for developers with many `.fl` files is the ability to
|
||||
upgrade them to the current FLUID file format. FLUID reads `filename.fl`,
|
||||
writes it back, and exits immediately. This updates the file to the current
|
||||
syntax and options and writes the current FLTK version into the file header.
|
||||
Use
|
||||
|
||||
```
|
||||
fluid -u filename.fl
|
||||
```
|
||||
|
||||
to 'upgrade' `filename.fl` . You may combine this with `-c` or `-cs`.
|
||||
to upgrade `filename.fl`. You may combine this with `-c` or `-cs`.
|
||||
|
||||
\note All these commands overwrite existing files w/o warning. You should
|
||||
\note All these commands overwrite existing files without warning. You should
|
||||
particularly take care when running `fluid -u` since this overwrites the
|
||||
original `.fl` project file.
|
||||
|
||||
|
||||
@@ -73,16 +73,31 @@
|
||||
<img src="w_settings_project_tab.png" align="left" hspace="10" vspace="10" />
|
||||
\image latex w_settings_project_tab.png "Project Settings Tab" width=7cm
|
||||
|
||||
__Header File__, __Code File__:
|
||||
__Code File__, __Header File__, __Strings File__:
|
||||
|
||||
These fields are used to build the file path and name of the generated header
|
||||
and source file. If one field is empty the value defaults to `.h` and `.cxx`
|
||||
respectively. If a name starts with a `.`, FLUID assumes that the rest of the
|
||||
text is a file extension. The code file name is then generated by replacing
|
||||
the extension of the `.fl` project file name.
|
||||
These fields define the output path and file name of the generated header,
|
||||
source, and optional strings file.
|
||||
|
||||
\todo Document the exact way the source and header file paths are calculated
|
||||
for interactive FLUID, and for FLUID launched from the command line.
|
||||
If a field contains only a file extension such as `.h`, `.cxx`, `.po`, or
|
||||
`.msg`, FLUID keeps the base name of the `.fl` project file and replaces only
|
||||
its extension. If a field contains a full file name, that name is used as-is.
|
||||
If it also contains a path, that path is used as well.
|
||||
|
||||
For the header and code file, an empty field defaults to `.h` and `.cxx`
|
||||
respectively. For the strings file, an empty field uses the project base name
|
||||
and an extension that depends on the selected internationalization mode:
|
||||
`.txt`, `.po`, or `.msg`.
|
||||
|
||||
In interactive FLUID, relative output paths are interpreted relative to the
|
||||
directory of the `.fl` project file. In command line mode, relative output
|
||||
paths are interpreted relative to the directory where FLUID was launched.
|
||||
|
||||
All three settings can be overridden from the command line: `-h` for the
|
||||
header file, `-o` for the code file, and `-s` for the strings file.
|
||||
|
||||
In command line mode, `-pr` changes the base for relative output paths from
|
||||
the directory where FLUID was launched to the directory of the `.fl` project
|
||||
file.
|
||||
|
||||
__Include Header from Code__:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user