fast_excel 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +2 -0
  3. data/.gitignore +7 -0
  4. data/.travis.yml +32 -9
  5. data/CHANGELOG.md +36 -1
  6. data/Dockerfile.test +17 -0
  7. data/Gemfile +2 -1
  8. data/Gemfile.lock +33 -24
  9. data/LICENSE +21 -0
  10. data/Makefile +13 -0
  11. data/README.md +177 -40
  12. data/Rakefile +11 -1
  13. data/benchmarks/1k_rows.rb +17 -4
  14. data/benchmarks/20k_rows.rb +4 -0
  15. data/benchmarks/auto_width.rb +37 -0
  16. data/benchmarks/init.rb +14 -2
  17. data/benchmarks/memory.rb +8 -0
  18. data/benchmarks/profiler.rb +27 -0
  19. data/benchmarks/write_value.rb +62 -0
  20. data/examples/example.rb +3 -3
  21. data/examples/example_auto_width.rb +26 -0
  22. data/examples/example_filters.rb +36 -0
  23. data/examples/example_formula.rb +1 -3
  24. data/examples/example_hyperlink.rb +20 -0
  25. data/ext/fast_excel/extconf.rb +3 -0
  26. data/ext/fast_excel/text_width_ext.c +460 -0
  27. data/fast_excel.gemspec +3 -4
  28. data/letters.html +114 -0
  29. data/lib/fast_excel.rb +131 -25
  30. data/lib/fast_excel/binding.rb +33 -21
  31. data/lib/fast_excel/binding/chart.rb +20 -1
  32. data/lib/fast_excel/binding/format.rb +11 -4
  33. data/lib/fast_excel/binding/workbook.rb +10 -2
  34. data/lib/fast_excel/binding/worksheet.rb +44 -27
  35. data/libxlsxwriter/.gitignore +1 -0
  36. data/libxlsxwriter/.indent.pro +8 -0
  37. data/libxlsxwriter/.travis.yml +12 -0
  38. data/libxlsxwriter/CMakeLists.txt +338 -0
  39. data/libxlsxwriter/CONTRIBUTING.md +1 -1
  40. data/libxlsxwriter/Changes.txt +162 -0
  41. data/libxlsxwriter/LICENSE.txt +65 -4
  42. data/libxlsxwriter/Makefile +33 -11
  43. data/libxlsxwriter/Readme.md +3 -1
  44. data/libxlsxwriter/cocoapods/libxlsxwriter-umbrella.h +2 -1
  45. data/libxlsxwriter/cocoapods/libxlsxwriter.modulemap +2 -2
  46. data/libxlsxwriter/include/xlsxwriter.h +2 -2
  47. data/libxlsxwriter/include/xlsxwriter/app.h +2 -2
  48. data/libxlsxwriter/include/xlsxwriter/chart.h +164 -13
  49. data/libxlsxwriter/include/xlsxwriter/chartsheet.h +544 -0
  50. data/libxlsxwriter/include/xlsxwriter/common.h +35 -6
  51. data/libxlsxwriter/include/xlsxwriter/content_types.h +5 -2
  52. data/libxlsxwriter/include/xlsxwriter/core.h +2 -2
  53. data/libxlsxwriter/include/xlsxwriter/custom.h +2 -2
  54. data/libxlsxwriter/include/xlsxwriter/drawing.h +3 -2
  55. data/libxlsxwriter/include/xlsxwriter/format.h +8 -8
  56. data/libxlsxwriter/include/xlsxwriter/hash_table.h +1 -1
  57. data/libxlsxwriter/include/xlsxwriter/packager.h +18 -8
  58. data/libxlsxwriter/include/xlsxwriter/relationships.h +2 -2
  59. data/libxlsxwriter/include/xlsxwriter/shared_strings.h +5 -3
  60. data/libxlsxwriter/include/xlsxwriter/styles.h +10 -5
  61. data/libxlsxwriter/include/xlsxwriter/theme.h +2 -2
  62. data/libxlsxwriter/include/xlsxwriter/utility.h +35 -5
  63. data/libxlsxwriter/include/xlsxwriter/workbook.h +234 -57
  64. data/libxlsxwriter/include/xlsxwriter/worksheet.h +780 -91
  65. data/libxlsxwriter/include/xlsxwriter/xmlwriter.h +4 -2
  66. data/libxlsxwriter/libxlsxwriter.podspec +4 -2
  67. data/libxlsxwriter/src/Makefile +31 -6
  68. data/libxlsxwriter/src/app.c +2 -2
  69. data/libxlsxwriter/src/chart.c +116 -23
  70. data/libxlsxwriter/src/chartsheet.c +508 -0
  71. data/libxlsxwriter/src/content_types.c +12 -4
  72. data/libxlsxwriter/src/core.c +11 -11
  73. data/libxlsxwriter/src/custom.c +3 -3
  74. data/libxlsxwriter/src/drawing.c +114 -17
  75. data/libxlsxwriter/src/format.c +5 -5
  76. data/libxlsxwriter/src/hash_table.c +1 -1
  77. data/libxlsxwriter/src/packager.c +378 -61
  78. data/libxlsxwriter/src/relationships.c +2 -2
  79. data/libxlsxwriter/src/shared_strings.c +18 -4
  80. data/libxlsxwriter/src/styles.c +59 -12
  81. data/libxlsxwriter/src/theme.c +2 -2
  82. data/libxlsxwriter/src/utility.c +93 -6
  83. data/libxlsxwriter/src/workbook.c +379 -61
  84. data/libxlsxwriter/src/worksheet.c +1240 -174
  85. data/libxlsxwriter/src/xmlwriter.c +18 -9
  86. data/libxlsxwriter/third_party/minizip/Makefile +6 -1
  87. data/libxlsxwriter/third_party/minizip/ioapi.c +10 -0
  88. data/libxlsxwriter/third_party/minizip/zip.c +2 -0
  89. data/libxlsxwriter/third_party/tmpfileplus/tmpfileplus.c +2 -2
  90. data/libxlsxwriter/version.txt +1 -1
  91. data/test/auto_width_test.rb +19 -0
  92. data/test/date_test.rb +34 -0
  93. data/test/format_test.rb +8 -0
  94. data/test/reopen_test.rb +22 -0
  95. data/test/test_helper.rb +8 -5
  96. data/test/text_width_test.rb +80 -0
  97. data/test/tmpfile_test.rb +1 -0
  98. data/test/validations_test.rb +47 -0
  99. data/test/worksheet_test.rb +44 -1
  100. metadata +33 -9
@@ -906,7 +906,23 @@ module Libxlsxwriter
906
906
  :end_, 0,
907
907
  :no, 1
908
908
  ]
909
-
909
+
910
+ enum :chart_error_bar_axis, [
911
+ :axis_x, 0,
912
+ :axis_y, 1
913
+ ]
914
+
915
+ enum :chart_axis_label_alignment, [
916
+ :align_center, 0,
917
+ :align_left, 1,
918
+ :align_right, 2
919
+ ]
920
+
921
+ enum :chart_axis_type, [
922
+ :axis_type_x, 0,
923
+ :axis_type_y, 1
924
+ ]
925
+
910
926
  # = Fields:
911
927
  # :type ::
912
928
  # (Integer)
@@ -1268,6 +1284,7 @@ module Libxlsxwriter
1268
1284
  :show_labels_legend, :uchar,
1269
1285
  :show_labels_percent, :uchar,
1270
1286
  :label_position, :uchar,
1287
+ :label_align, :uchar,
1271
1288
  :label_separator, :uchar,
1272
1289
  :default_label_position, :uchar,
1273
1290
  :label_num_format, :string,
@@ -1934,6 +1951,7 @@ module Libxlsxwriter
1934
1951
  :in_use, :uchar,
1935
1952
  :chart_group, :uchar,
1936
1953
  :cat_has_num_fmt, :uchar,
1954
+ :is_chartsheet, :uchar,
1937
1955
  :has_horiz_cat_axis, :uchar,
1938
1956
  :has_horiz_val_axis, :uchar,
1939
1957
  :style_id, :uchar,
@@ -1976,6 +1994,7 @@ module Libxlsxwriter
1976
1994
  :up_bar_fill, ChartFill,
1977
1995
  :down_bar_fill, ChartFill,
1978
1996
  :default_label_position, :uchar,
1997
+ :is_protected, :uchar,
1979
1998
  :ordered_list_pointers, ChartOrderedListPointers.by_value,
1980
1999
  :list_pointers, ChartListPointers.by_value
1981
2000
  end
@@ -684,12 +684,19 @@ module Libxlsxwriter
684
684
  def set_theme(value)
685
685
  Libxlsxwriter.format_set_theme(self, value)
686
686
  end
687
+
688
+ [:font_size, :underline, :font_script, :rotation, :indent, :pattern, :border, :num_format, :font_name].each do |prop|
689
+ alias :"#{prop}=" :"set_#{prop}"
690
+ define_method(prop) do
691
+ self[prop]
692
+ end
693
+ end
687
694
  end
688
695
 
689
696
  class Format < FFI::Struct
690
697
  include FormatWrappers
691
698
  layout :file, :pointer,
692
- :xf_format_indices, HashTable.ptr,
699
+ :xf_format_indices, :pointer, #HashTable.ptr,
693
700
  :num_xf_formats, :pointer,
694
701
  :xf_index, :int32_t,
695
702
  :dxf_index, :int32_t,
@@ -700,7 +707,7 @@ module Libxlsxwriter
700
707
  :font_index, :uint16,
701
708
  :has_font, :uchar,
702
709
  :has_dxf_font, :uchar,
703
- :font_size, :uint16,
710
+ :font_size, :double,
704
711
  :bold, :uchar,
705
712
  :italic, :uchar,
706
713
  :font_color, :int,
@@ -786,7 +793,7 @@ module Libxlsxwriter
786
793
  # (Integer)
787
794
  class Font < FFI::Struct
788
795
  layout :font_name, [:char, 128],
789
- :font_size, :ushort,
796
+ :font_size, :double,
790
797
  :bold, :uchar,
791
798
  :italic, :uchar,
792
799
  :underline, :uchar,
@@ -904,7 +911,7 @@ module Libxlsxwriter
904
911
  # @param [Integer] size
905
912
  # @return [nil]
906
913
  # @scope class
907
- attach_function :format_set_font_size, :format_set_font_size, [Format, :ushort], :void
914
+ attach_function :format_set_font_size, :format_set_font_size, [Format, :double], :void
908
915
 
909
916
  # @method format_set_font_color(format, color)
910
917
  # @param [Format] format
@@ -6,7 +6,8 @@ module Libxlsxwriter
6
6
  # (String) Directory to use for the temporary files created by libxlsxwriter.
7
7
  class WorkbookOptions < FFI::Struct
8
8
  layout :constant_memory, :uchar,
9
- :tmpdir, :string
9
+ :tmpdir, :string,
10
+ :use_zip64, :uchar
10
11
  end
11
12
 
12
13
  # = Fields:
@@ -168,8 +169,11 @@ module Libxlsxwriter
168
169
  class Workbook < FFI::Struct
169
170
  include WorkbookWrappers
170
171
  layout :file, :pointer,
172
+ :sheets, Sheets.ptr,
171
173
  :worksheets, Worksheets.ptr,
174
+ :chartsheets, :pointer,
172
175
  :worksheet_names, WorksheetNames.ptr,
176
+ :chartsheet_names, :pointer,
173
177
  :charts, Charts.ptr,
174
178
  :ordered_charts, Charts.ptr,
175
179
  :formats, Formats.ptr,
@@ -180,6 +184,8 @@ module Libxlsxwriter
180
184
  :filename, :pointer,
181
185
  :options, WorkbookOptions.by_value,
182
186
  :num_sheets, :uint16,
187
+ :num_worksheets, :uint16,
188
+ :num_chartsheets, :uint16,
183
189
  :first_sheet, :uint16,
184
190
  :active_sheet, :uint16,
185
191
  :num_xf_formats, :uint16,
@@ -192,7 +198,9 @@ module Libxlsxwriter
192
198
  :has_png, :uchar,
193
199
  :has_jpeg, :uchar,
194
200
  :has_bmp, :uchar,
195
- :used_xf_formats, HashTable.ptr
201
+ :used_xf_formats, HashTable.ptr,
202
+ :vba_project, :pointer,
203
+ :vba_codename, :pointer
196
204
  end
197
205
 
198
206
  attach_function :workbook_default_format, :workbook_default_format, [Workbook], Format
@@ -593,7 +593,7 @@ module Libxlsxwriter
593
593
  end
594
594
 
595
595
  # @return [nil]
596
- def right_to_left()
596
+ def set_right_to_left()
597
597
  Libxlsxwriter.worksheet_right_to_left(self)
598
598
  end
599
599
 
@@ -689,6 +689,7 @@ module Libxlsxwriter
689
689
  :array, :pointer,
690
690
  :merged_ranges, MergedRanges.ptr,
691
691
  :selections, Selections.ptr,
692
+ :data_validations, :pointer, # TODO add real definition for lxw_data_validations
692
693
  :image_data, ImageData.ptr,
693
694
  :chart_data, ChartData.ptr,
694
695
  :dim_rowmin, :uint32,
@@ -705,6 +706,7 @@ module Libxlsxwriter
705
706
  :hidden, :uint8,
706
707
  :active_sheet, :pointer,
707
708
  :first_sheet, :pointer,
709
+ :is_chartsheet, :uint8,
708
710
  :col_options, :pointer,
709
711
  :col_options_max, :uint16,
710
712
  :col_sizes, :pointer,
@@ -724,25 +726,29 @@ module Libxlsxwriter
724
726
  :rel_count, :uint16,
725
727
  :vertical_dpi, :uint16,
726
728
  :zoom, :uint16,
727
- :filter_on, :uint8,
728
- :fit_page, :uint8,
729
- :hcenter, :uint8,
730
- :orientation, :uint8,
731
- :outline_changed, :uint8,
732
- :outline_on, :uint8,
733
- :page_order, :uint8,
734
- :page_setup_changed, :uint8,
735
- :page_view, :uint8,
736
- :paper_size, :uint8,
737
- :print_gridlines, :uint8,
738
- :print_headers, :uint8,
729
+ :filter_on, :uint8,
730
+ :fit_page, :uint8,
731
+ :hcenter, :uint8,
732
+ :orientation, :uint8,
733
+ :outline_changed, :uint8,
734
+ :outline_on, :uint8,
735
+ :outline_style, :uint8,
736
+ :outline_below, :uint8,
737
+ :outline_right, :uint8,
738
+ :page_order, :uint8,
739
+ :page_setup_changed, :uint8,
740
+ :page_view, :uint8,
741
+ :paper_size, :uint8,
742
+ :print_gridlines, :uint8,
743
+ :print_headers, :uint8,
739
744
  :print_options_changed, :uint8,
740
- :right_to_left, :uint8,
741
- :screen_gridlines, :uint8,
742
- :show_zeros, :uint8,
743
- :vba_codename, :uint8,
744
- :vcenter, :uint8,
745
- :zoom_scale_normal, :uint8,
745
+ :right_to_left, :uint8,
746
+ :screen_gridlines, :uint8,
747
+ :show_zeros, :uint8,
748
+ :vcenter, :uint8,
749
+ :zoom_scale_normal, :uint8,
750
+ :num_validations, :uint8,
751
+ :vba_codename, :pointer,
746
752
  :tab_color, :int,
747
753
  :margin_left, :double,
748
754
  :margin_right, :double,
@@ -891,13 +897,14 @@ module Libxlsxwriter
891
897
  :number_cell, 1,
892
898
  :string_cell, 2,
893
899
  :inline_string_cell, 3,
894
- :formula_cell, 4,
895
- :array_formula_cell, 5,
896
- :blank_cell, 6,
897
- :boolean_cell, 7,
898
- :hyperlink_url, 8,
899
- :hyperlink_internal, 9,
900
- :hyperlink_external, 10
900
+ :inline_rich_string_cell, 4,
901
+ :formula_cell, 5,
902
+ :array_formula_cell, 6,
903
+ :blank_cell, 7,
904
+ :boolean_cell, 8,
905
+ :hyperlink_url, 9,
906
+ :hyperlink_internal, 10,
907
+ :hyperlink_external, 11
901
908
  ]
902
909
 
903
910
  # = Fields:
@@ -1552,4 +1559,14 @@ module Libxlsxwriter
1552
1559
  layout :stqh_first, Worksheet.ptr,
1553
1560
  :stqh_last, :pointer
1554
1561
  end
1555
- end
1562
+
1563
+ class Sheet < FFI::Struct
1564
+ layout :is_chartsheet, :uchar,
1565
+ :list_pointers, :pointer
1566
+ end
1567
+
1568
+ class Sheets < FFI::Struct
1569
+ layout :stqh_first, Sheet.ptr,
1570
+ :stqh_last, :pointer
1571
+ end
1572
+ end
@@ -20,6 +20,7 @@ TAGS
20
20
  *.bak
21
21
  !test/functional/xlsx_files/*.xlsx
22
22
  *.pyc
23
+ .pytest_cache/
23
24
  .cproject
24
25
  .project
25
26
  .pydevproject
@@ -50,10 +50,13 @@
50
50
  -T lxw_chart
51
51
  -T lxw_chart_axis
52
52
  -T lxw_chart_axis_display_unit
53
+ -T lxw_chart_axis_label_alignment
53
54
  -T lxw_chart_axis_label_position
54
55
  -T lxw_chart_axis_tick_mark
55
56
  -T lxw_chart_axis_tick_position
57
+ -T lxw_chart_axis_type
56
58
  -T lxw_chart_blank
59
+ -T lxw_chart_error_bar_axis
57
60
  -T lxw_chart_error_bar_cap
58
61
  -T lxw_chart_error_bar_direction
59
62
  -T lxw_chart_error_bar_type
@@ -75,6 +78,8 @@
75
78
  -T lxw_chart_title
76
79
  -T lxw_chart_trendline_type
77
80
  -T lxw_chart_type
81
+ -T lxw_chartsheet
82
+ -T lxw_chartsheet_name
78
83
  -T lxw_col_options
79
84
  -T lxw_col_t
80
85
  -T lxw_color_t
@@ -82,6 +87,7 @@
82
87
  -T lxw_core
83
88
  -T lxw_custom
84
89
  -T lxw_custom_property
90
+ -T lxw_data_validation
85
91
  -T lxw_datetime
86
92
  -T lxw_defined_name
87
93
  -T lxw_doc_properties
@@ -107,6 +113,7 @@
107
113
  -T lxw_relationships
108
114
  -T lxw_repeat_cols
109
115
  -T lxw_repeat_rows
116
+ -T lxw_rich_string_tuple
110
117
  -T lxw_row
111
118
  -T lxw_row_col_options
112
119
  -T lxw_row_t
@@ -114,6 +121,7 @@
114
121
  -T lxw_series_data_point
115
122
  -T lxw_series_error_bars
116
123
  -T lxw_series_range
124
+ -T lxw_sheet
117
125
  -T lxw_sst
118
126
  -T lxw_styles
119
127
  -T lxw_theme
@@ -1,4 +1,5 @@
1
1
  language: c
2
+ dist: trusty
2
3
 
3
4
  compiler:
4
5
  - clang
@@ -8,18 +9,29 @@ env:
8
9
  - CFLAGS='-Werror'
9
10
  - NO_VALGRIND=1 USE_STANDARD_TMPFILE=1 CFLAGS='-Werror'
10
11
  - NO_VALGRIND=1 CFLAGS='-Werror -m32'
12
+ - NO_VALGRIND=1 USE_SYSTEM_MINIZIP=1 CFLAGS='-Werror'
13
+ - NO_VALGRIND=1 USE_DOUBLE_FUNCTION=1 CFLAGS='-Werror'
11
14
 
12
15
  install:
13
16
  - sudo pip install pytest
14
17
  - sudo apt-get update
18
+ - sudo apt-get remove -y oracle-java9-installer
15
19
  - sudo apt-get install -y gcc-multilib
16
20
  - sudo apt-get install -y zlib1g-dev
17
21
  - sudo apt-get install -y zlib1g-dev:i386
18
22
  - sudo apt-get install -y gcc
19
23
  - sudo apt-get install -y valgrind
20
24
 
25
+ - wget http://mirrors.kernel.org/ubuntu/pool/universe/m/minizip/libminizip-dev_1.1-8_amd64.deb
26
+ - wget http://mirrors.kernel.org/ubuntu/pool/universe/m/minizip/libminizip1_1.1-8_amd64.deb
27
+ - sudo dpkg -i libminizip1_1.1-8_amd64.deb
28
+ - sudo dpkg -i libminizip-dev_1.1-8_amd64.deb
29
+
21
30
  script:
22
31
  - make V=1
23
32
  - make test_functional V=1
24
33
  - make test_unit V=1
34
+ - make examples V=1
25
35
  - make test_valgrind V=1
36
+ - sudo make install V=1
37
+ - sudo make uninstall V=1
@@ -0,0 +1,338 @@
1
+ # :copyright: (c) 2017 Alex Huszagh.
2
+ # :license: FreeBSD, see LICENSE.txt for more details.
3
+
4
+ # Description
5
+ # ===========
6
+ #
7
+ # Use:
8
+ # Move to a custom directory, ideally out of source, and
9
+ # type `cmake $LXW_SOURCE $FLAGS`, where `LXW_SOURCE` is the
10
+ # path to the libxlsxwriter project, and `FLAGS` are custom
11
+ # flags to pass to the compiler.
12
+ #
13
+ # Example:
14
+ # For example, in the project directory, to build libxlsxwriter
15
+ # and the unittests in release mode, type:
16
+ # mkdir build && cd build
17
+ # cmake .. -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
18
+ # cmake --build . --config Release
19
+ # ctest -C Release -V
20
+ # cmake --build . --config Release --target install
21
+ #
22
+ # If using a Makefile generator, you may use the simpler
23
+ # mkdir build && cd build
24
+ # cmake .. -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
25
+ # make
26
+ # make test
27
+ # make install
28
+ #
29
+ # Flags:
30
+ # ZLIB_ROOT
31
+ # The ZLIB root directory can be specified either through
32
+ # an environment variable (`export ZLIB_ROOT=/usr/include`)
33
+ # or using a flag with CMake (`-DZLIB_ROOT:STRING=/usr/include`).
34
+ # This sets the preferred search path for the ZLIB installation.
35
+ #
36
+ # BUILD_TESTS
37
+ # Build unittests (default off). To build the unittests,
38
+ # pass `-DBUILD_TESTS=ON` during configuration.
39
+ #
40
+ # BUILD_EXAMPLES
41
+ # Build example files (default off). To build the examples,
42
+ # pass `-DBUILD_EXAMPLES=ON` during configuration.
43
+ #
44
+ # USE_STANDARD_TMPFILE
45
+ # Use the standard tmpfile() function (default off). To enable
46
+ # the standard tmpfile, pass `-DUSE_STANDARD_TMPFILE=ON`
47
+ # during configuration. This may produce bugs while cross-
48
+ # compiling or using MinGW/MSYS.
49
+ #
50
+ # USE_STATIC_MSVC_RUNTIME
51
+ # Use the static msvc runtime library when compiling with msvc (default off)
52
+ # To enable, pass `-DUSE_STATIC_MSVC_RUNTIME` during configuration.
53
+ #
54
+ # Toolchains:
55
+ # On multiarch Linux systems, which can build and run multiple
56
+ # binary targets on the same system, we include an `i686-toolchain`
57
+ # file to enable building i686 (x86 32-bit) targets on x86_64 systems.
58
+ # To use the i686 toolchain, pass the `-DCMAKE_TOOLCHAIN_FILE` option
59
+ # during CMake configuration. For example, from the build directory,
60
+ # you would use:
61
+ # cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/i686-toolchain.cmake
62
+ #
63
+ # CMake Options:
64
+ # CMake sets debug and release builds with the `CMAKE_BUILD_TYPE`
65
+ # option, which can be set as a flag during configuration.
66
+ # To build in release mode, pass `-DCMAKE_BUILD_TYPE=Release`
67
+ # during configuration.
68
+ #
69
+ # CMake sets the creation of static and shared libraries with the
70
+ # `BUILD_SHARED_LIBS` option, which can be set as a flag during
71
+ # configuration. To build a static library, pass
72
+ # `-DBUILD_SHARED_LIBS=OFF` during configuration.
73
+ #
74
+ # Generators:
75
+ # CMake also supports custom build generators, such as MakeFiles,
76
+ # Ninja, Visual Studio, and XCode. For example, to generate
77
+ # a Visual Studio solution, configure with:
78
+ # cmake .. -G "Visual Studio 14 2015 Win64"
79
+ #
80
+ # For more information on using generators, see:
81
+ # https://cmake.org/cmake/help/v3.0/manual/cmake-generators.7.html
82
+ #
83
+
84
+ set(CMAKE_LEGACY_CYGWIN_WIN32 1)
85
+ if(MSVC)
86
+ cmake_minimum_required(VERSION 3.4)
87
+ else()
88
+ cmake_minimum_required(VERSION 3.1)
89
+ endif()
90
+
91
+ SET(PROJECT_NAME "xlsxwriter" CACHE STRING "Optional project and binary name")
92
+ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
93
+ project(${PROJECT_NAME} C)
94
+ enable_testing()
95
+
96
+ # OPTIONS
97
+ # -------
98
+
99
+ SET(ZLIB_ROOT "" CACHE STRING "Optional root for the ZLIB installation")
100
+
101
+ option(BUILD_TESTS "Build libxlsxwriter tests" OFF)
102
+ option(BUILD_EXAMPLES "Build libxlsxwriter examples" OFF)
103
+ option(USE_SYSTEM_MINIZIP "Use system minizip installation" OFF)
104
+ option(USE_STANDARD_TMPFILE "Use the C standard library's tmpfile()" OFF)
105
+ option(IOAPI_NO_64 "Disable 64-bit filesystem support" OFF)
106
+ if(MSVC)
107
+ option(USE_STATIC_MSVC_RUNTIME "Use the static runtime library" OFF)
108
+ endif()
109
+ if(DEFINED ENV{${ZLIB_ROOT}})
110
+ set(ZLIB_ROOT $ENV{ZLIB_ROOT})
111
+ endif()
112
+
113
+ if(IOAPI_NO_64)
114
+ list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS IOAPI_NO_64=1)
115
+ endif()
116
+
117
+ # CONFIGURATIONS
118
+ # --------------
119
+
120
+ if(USE_SYSTEM_MINIZIP)
121
+ list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS USE_SYSTEM_MINIZIP)
122
+ endif()
123
+
124
+ if(USE_STANDARD_TMPFILE)
125
+ list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS USE_STANDARD_TMPFILE)
126
+ endif()
127
+
128
+ if(NOT BUILD_SHARED_LIBS)
129
+ if(UNIX)
130
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
131
+ elseif(MINGW OR MSYS)
132
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static -static-libgcc -Wno-char-subscripts -Wno-long-long")
133
+ list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS USE_FILE32API)
134
+ elseif(MSVC)
135
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /O0 /Fd${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb")
136
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Ox /Zi /Fd${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb")
137
+ set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /Zi /Fd${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb")
138
+ set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /Fd${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb")
139
+ endif()
140
+ endif()
141
+
142
+ message(status "BEFORE: ${CMAKE_C_FLAGS_DEBUG}")
143
+
144
+ if(MSVC AND USE_STATIC_MSVC_RUNTIME)
145
+ foreach(flag_var CMAKE_C_FLAGS
146
+ CMAKE_C_FLAGS_DEBUG
147
+ CMAKE_C_FLAGS_RELEASE
148
+ CMAKE_C_FLAGS_MINSIZEREL
149
+ CMAKE_C_FLAGS_RELWITHDEBINFO)
150
+ if(${flag_var} MATCHES "/MD")
151
+ string(REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
152
+ endif()
153
+ endforeach()
154
+ endif()
155
+
156
+ # INCLUDES
157
+ # --------
158
+
159
+ enable_language(CXX)
160
+ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
161
+
162
+ # ZLIB
163
+ find_package(ZLIB REQUIRED "1.0")
164
+ list(APPEND LXW_PRIVATE_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS})
165
+ message("zlib version: " ${ZLIB_VERSION})
166
+
167
+ # MINIZIP
168
+ if (USE_SYSTEM_MINIZIP)
169
+ find_package(MINIZIP REQUIRED "1.0")
170
+ list(APPEND LXW_PRIVATE_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIRS})
171
+ endif()
172
+
173
+ # LIBRARY
174
+ # -------
175
+
176
+ list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS NOCRYPT NOUNCRYPT)
177
+
178
+ # Fix for modified zconf.h on Gentoo.
179
+ if(${CMAKE_HOST_SYSTEM} MATCHES gentoo)
180
+ list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS OF=_Z_OF)
181
+ endif()
182
+
183
+ # Ensure CRT Secure warnings are disabled
184
+ if(MSVC)
185
+ list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS _CRT_SECURE_NO_WARNINGS)
186
+ endif()
187
+
188
+ # Ensure "TESTING" macro is defined if building tests
189
+ if(BUILD_TESTS)
190
+ list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS TESTING)
191
+ endif()
192
+
193
+ file(GLOB LXW_SOURCES src/*.c)
194
+ file(GLOB_RECURSE LXW_HEADERS RELATIVE include *.h)
195
+ if(NOT USE_SYSTEM_MINIZIP)
196
+ list(APPEND LXW_SOURCES third_party/minizip/ioapi.c third_party/minizip/zip.c)
197
+ if(MSVC)
198
+ list(APPEND LXW_SOURCES third_party/minizip/iowin32.c)
199
+ endif()
200
+ endif()
201
+ if (NOT USE_STANDARD_TMPFILE)
202
+ list(APPEND LXW_SOURCES third_party/tmpfileplus/tmpfileplus.c)
203
+ endif()
204
+
205
+ set(LXW_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
206
+ set(LXW_LIB_DIR "${LXW_PROJECT_DIR}/lib")
207
+ add_library(${PROJECT_NAME} "")
208
+ target_sources(${PROJECT_NAME}
209
+ PRIVATE ${LXW_SOURCES}
210
+ PUBLIC ${LXW_HEADERS}
211
+ )
212
+ target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${ZLIB_LIBRARIES} ${MINIZIP_LIBRARIES})
213
+ target_compile_definitions(${PROJECT_NAME} PRIVATE ${LXW_PRIVATE_COMPILE_DEFINITIONS})
214
+ target_include_directories(${PROJECT_NAME}
215
+ PRIVATE ${LXW_PRIVATE_INCLUDE_DIRS}
216
+ PUBLIC include include/xlsxwriter
217
+ )
218
+
219
+ # TESTS
220
+ # -----
221
+
222
+ # Create test and runner.
223
+ #
224
+ # Args:
225
+ # sources Name of variable holding source files
226
+ # target Test name
227
+ #
228
+ macro(CreateTest sources target)
229
+ set(output_name xlsxwriter_${target})
230
+ set(dependencies ${output_name})
231
+
232
+ add_executable(${output_name} ${${sources}})
233
+ target_link_libraries(${output_name} ${PROJECT_NAME})
234
+ target_compile_definitions(${output_name} PRIVATE TESTING COLOR_OK)
235
+ add_test(NAME ${output_name}
236
+ COMMAND ${output_name}
237
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
238
+ )
239
+ endmacro(CreateTest)
240
+
241
+
242
+ file(GLOB LXW_UTILITY_SOURCES test/unit/utility/test*.c)
243
+ file(GLOB LXW_XMLWRITER_SOURCES test/unit/xmlwriter/test*.c)
244
+ file(GLOB LXW_WORKSHEET_SOURCES test/unit/worksheet/test*.c)
245
+ file(GLOB LXW_SST_SOURCES test/unit/sst/test*.c)
246
+ file(GLOB LXW_WORKBOOK_SOURCES test/unit/workbook/test*.c)
247
+ file(GLOB LXW_APP_SOURCES test/unit/app/test*.c)
248
+ file(GLOB LXW_CONTENTTYPES_SOURCES test/unit/content_types/test*.c)
249
+ file(GLOB LXW_CORE_SOURCES test/unit/core/test*.c)
250
+ file(GLOB LXW_RELATIONSHIPS_SOURCES test/unit/relationships/test*.c)
251
+ file(GLOB LXW_FORMAT_SOURCES test/unit/format/test*.c)
252
+ file(GLOB LXW_STYLES_SOURCES test/unit/styles/test*.c)
253
+ file(GLOB LXW_DRAWING_SOURCES test/unit/drawing/test*.c)
254
+ file(GLOB LXW_CHART_SOURCES test/unit/chart/test*.c)
255
+ file(GLOB LXW_CUSTOM_SOURCES test/unit/custom/test*.c)
256
+ file(GLOB LXW_FUNCTIONAL_SOURCES test/functional/src/*.c)
257
+
258
+ set(LXW_UNIT_SOURCES
259
+ test/unit/test_all.c
260
+ ${LXW_UTILITY_SOURCES}
261
+ ${LXW_XMLWRITER_SOURCES}
262
+ ${LXW_WORKSHEET_SOURCES}
263
+ ${LXW_SST_SOURCES}
264
+ ${LXW_WORKBOOK_SOURCES}
265
+ ${LXW_APP_SOURCES}
266
+ ${LXW_CONTENTTYPES_SOURCES}
267
+ ${LXW_CORE_SOURCES}
268
+ ${LXW_RELATIONSHIPS_SOURCES}
269
+ ${LXW_FORMAT_SOURCES}
270
+ ${LXW_STYLES_SOURCES}
271
+ ${LXW_DRAWING_SOURCES}
272
+ ${LXW_CHART_SOURCES}
273
+ ${LXW_CUSTOM_SOURCES}
274
+ )
275
+
276
+ if(BUILD_TESTS)
277
+ # unit tests
278
+ CreateTest(LXW_UNIT_SOURCES unit)
279
+
280
+ # functional tests
281
+ # WARNING: currently doesn't work, since the Python tests expect
282
+ # in-source builds
283
+ #find_program(PYTHON python)
284
+ #foreach(source ${LXW_FUNCTIONAL_SOURCES})
285
+ # get_filename_component(basename ${source} NAME_WE)
286
+ # add_executable(${basename} ${source})
287
+ # target_link_libraries(${basename} xlsxwriter)
288
+ #endforeach(source)
289
+ endif()
290
+
291
+ # EXAMPLES
292
+ # --------
293
+
294
+ file(GLOB LXW_EXAMPLE_SOURCES examples/*.c)
295
+
296
+ if(BUILD_EXAMPLES)
297
+ foreach(source ${LXW_EXAMPLE_SOURCES})
298
+ get_filename_component(basename ${source} NAME_WE)
299
+ add_executable(${basename} ${source})
300
+ target_link_libraries(${basename} ${PROJECT_NAME})
301
+ endforeach(source)
302
+ endif()
303
+
304
+ # INSTALL
305
+ # -------
306
+
307
+ include(GNUInstallDirs)
308
+
309
+ if(MSVC)
310
+ if(CMAKE_CL_64)
311
+ set(MSVC_FOLDER_PREFIX x64)
312
+ else()
313
+ set(MSVC_FOLDER_PREFIX Win32)
314
+ endif()
315
+
316
+ install(TARGETS ${PROJECT_NAME}
317
+ LIBRARY DESTINATION "lib/${MSVC_FOLDER_PREFIX}/\${CMAKE_INSTALL_CONFIG_NAME}"
318
+ ARCHIVE DESTINATION "lib/${MSVC_FOLDER_PREFIX}/\${CMAKE_INSTALL_CONFIG_NAME}"
319
+ RUNTIME DESTINATION "bin/${MSVC_FOLDER_PREFIX}/\${CMAKE_INSTALL_CONFIG_NAME}"
320
+ )
321
+ if (NOT BUILD_SHARED_LIBS)
322
+ install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pdb
323
+ DESTINATION "lib/${MSVC_FOLDER_PREFIX}/\${CMAKE_INSTALL_CONFIG_NAME}"
324
+ )
325
+ endif()
326
+
327
+ else(MSVC)
328
+ install(TARGETS ${PROJECT_NAME}
329
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
330
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
331
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
332
+ )
333
+ endif(MSVC)
334
+ install(FILES include/xlsxwriter.h DESTINATION include)
335
+ install(DIRECTORY include/xlsxwriter
336
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
337
+ FILES_MATCHING PATTERN "*.h"
338
+ )