1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
|
*************************************************************************
* Build and Install HDF4 C and Fortran Libraries and tools with CMake *
*************************************************************************
Table of Contents
Section I: Preconditions
Section II: Quick Step Building HDF4 Libraries with CMake Script Mode
Section III: Quick Step Building HDF4 Libraries with CMake Command Mode
Section IV: Further Considerations
Section V: Options for building HDF4 Libraries with CMake Command Line
Section VI: CMake option defaults for HDF4
Section VII: User Defined Options for HDF4 Libraries with CMake
Section VIII: Using CMakePresets.json for Compiling
Section IX: Using the Library
Section X: Autotools Configuration and Build
************************************************************************
========================================================================
I. Preconditions
========================================================================
Obtaining HDF4 source code
1. Create a directory for your development; for example, "myhdfstuff".
2. Obtain HDF4 source from Github
development branch: https://github.com/HDFGroup/hdf4
last release: https://github.com/HDFGroup/hdf4/releases/latest
hdf-4_3_"X".tar.gz or hdf-4_3_"X".zip
and put it in "myhdfstuff".
Uncompress the file. There should be a hdf-4.3"X" folder.
CMake version
1. We suggest you obtain the latest CMake from the Kitware web site.
The HDF 4.3"X" product requires a minimum CMake version 3.18,
where "X" is the current HDF4 release version. If you are using
VS2022, the minimum version is 3.21. CMakePresets requires CMake 3.25.
Note:
To change the install prefix from the platform defaults initialize
the CMake variable, CMAKE_INSTALL_PREFIX. Users of build scripts
will use the INSTALLDIR option.
========================================================================
II. Quick Step Building HDF4 Libraries with CMake Script Mode
========================================================================
This short set of instructions is written for users who want to quickly
build the HDF4 C and Fortran shared libraries and tools
from the HDF4 source code package using the CMake tools. This procedure
will use the default settings in the config/cmake/cacheinit.cmake file.
The HDF Group recommends using the presets process to build HDF4.
NOTE: if you are using CMake 3.25 or later, you can use the presets process.
The CMakePresets.json file in the source directory will configure, build, test,
and package HDF4 with the same options that are set in the cacheinit.cmake file.
In addition, it will get the optional files listed below that are needed, from
the appropriate repositories.
See Section VIII: Using CMakePresets.json for compiling
-------------------------------------------------------------------------
-------------------------------------------------------------------------
Individual files needed as mentioned in this document
-------------------------------------------------------------------------
CMake build script from https://github.com/HDFGroup/hdf4/tree/master/config/cmake/scripts:
CTestScript.cmake -- CMake build script
Configuration files from https://github.com/HDFGroup/hdf4/tree/master/config/cmake/scripts:
HDF4config.cmake -- CMake configuration script
HDF4options.cmake -- CMake configuration options script
External compression szip, jpeg, and zlib libraries:
JPEG "https://www.ijg.org/filesz"/jpegsrc.v9e.tar.gz"
ZLIB "https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz"
ZLIBNG "https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.2.2.tar.gz"
LIBAEC "https://github.com/MathisRosenhauer/libaec/releases/download/v1.1.3/libaec-1.1.3.tar.gz"
-------------------------------------------------------------------------
-------------------------------------------------------------------------
Build scripts for windows or linux
-----------------------------------------------
To build HDF4 with the SZIP, ZLIB and JPEG external libraries you will need to:
1. Change to the development directory "myhdfstuff".
2. Download/copy the individual files mentioned above to "myhdfstuff".
Do not uncompress the tar.gz files.
3. Change to the source directory "hdf-4.3.x".
CTestScript.cmake file should not be modified.
4. Edit the platform configuration file, HDF4options.cmake, if you want to change
the default build environment. The file is a compilation of the most used
options and by commenting/uncommenting lines the options can easily be changed.
5. From the "myhdfstuff" directory execute the CTest Script with the
following options:
On 32-bit Windows with Visual Studio 2022, execute:
ctest -S HDF4config.cmake,BUILD_GENERATOR=VS2022 -C Release -VV -O hdf4.log
On 64-bit Windows with Visual Studio 2022, execute:
ctest -S HDF4config.cmake,BUILD_GENERATOR=VS202264 -C Release -VV -O hdf4.log
On 32-bit Windows with Visual Studio 2019, execute:
ctest -S HDF4config.cmake,BUILD_GENERATOR=VS2019 -C Release -VV -O hdf4.log
On 64-bit Windows with Visual Studio 2019, execute:
ctest -S HDF4config.cmake,BUILD_GENERATOR=VS201964 -C Release -VV -O hdf4.log
On 32-bit Windows with Visual Studio 2017, execute:
ctest -S HDF4config.cmake,BUILD_GENERATOR=VS2017 -C Release -VV -O hdf4.log
On 64-bit Windows with Visual Studio 2017, execute:
ctest -S HDF4config.cmake,BUILD_GENERATOR=VS201764 -C Release -VV -O hdf4.log
On 32-bit Windows with Visual Studio 2015, execute:
ctest -S HDF4config.cmake,BUILD_GENERATOR=VS2015 -C Release -VV -O hdf4.log
On 64-bit Windows with Visual Studio 2015, execute:
ctest -S HDF4config.cmake,BUILD_GENERATOR=VS201564 -C Release -VV -O hdf4.log
On Linux and Mac, execute:
ctest -S HDF4config.cmake,BUILD_GENERATOR=Unix -C Release -VV -O hdf4.log
The supplied build scripts are versions of the above.
The command above will configure, build, test, and create an install
package in the myhdfstuff folder. It will have the format:
HDF-4.3.NN-<platform>.<zip or tar.gz>
On Unix, <platform> will be "Linux". A similar .sh file will also be created.
On Windows, <platform> will be "win64" or "win32". If you have an
installer on your system, you will also see a similar file that ends
in either .exe (NSIS) or .msi (WiX).
Notes on the command line options.
The -S option uses the script version of ctest.
The value for the -C option (as shown above, "-C Release") must
match the setting for CTEST_CONFIGURATION_TYPE in the platform
configuration file.
The -VV option is for most verbose; use -V for less verbose.
The "-O hdf4.log" option saves the output to a log file hdf4.log.
6. To install, "X" is the current release version
On Windows (with WiX installed), execute:
HDF-4.3."X"-win32.exe or HDF-4.3."X"-win64.exe
By default this program will install the hdf4 library into the
"C:\Program Files" directory and will create the following
directory structure:
HDF_Group
--HDF
----4.3."X"
------bin
------include
------lib
------cmake
On Linux, change to the install destination directory
(create it if doesn't exist) and execute:
<path-to>/myhdfstuff/HDF-4.3."X"-Linux.sh
After accepting the license, the script will prompt:
By default the HDF4 will be installed in:
"<current directory>/HDF-4.3."X"-Linux"
Do you want to include the subdirectory HDF-4.3."X"-Linux?
Saying no will install in: "<current directory>" [Yn]:
Note that the script will create the following directory structure
relative to the install point:
HDF_Group
--HDF
----4.3."X"
------bin
------include
------lib
------share
On Mac you will find HDF-4.3"X"-Darwin.dmg in the myhdfstuff folder. Click
on the dmg file to proceed with installation. After accepting the license,
there will be a folder with the following structure:
HDF_Group
--HDF
----4.3."X"
------bin
------include
------lib
------share
By default the installation will create the bin, include, lib and cmake
folders in the <install destination directory>/HDF_Group/HDF/4.3."X"
The <install destination directory> depends on the build platform;
Windows will set the default to:
C:/Program Files/HDF_Group/HDF/4.3."X"
Linux will set the default to:
"myhdfstuff/HDF_Group/HDF/4.3."X"
The default can be changed by adding ",INSTALLDIR=<my new dir>" to the
"ctest -S HDF4config.cmake..." command. For example on linux:
ctest -S HDF4config.cmake,INSTALLDIR=/usr/local/myhdf4,BUILD_GENERATOR=Unix -C Release -VV -O hdf4.log
========================================================================
III. Quick Step Building HDF4 C Static Libraries and Tools with CMake
========================================================================
Notes: This short set of instructions is written for users who want to
quickly build just the HDF4 C static library and tools from
the HDF4 source code package using the CMake command line tools.
Avoid the use of drive letters in paths on Windows.
Go through these steps:
1. Change to the development directory "myhdfstuff".
2. Uncompress the HDF4 source file
3. Create a folder "build" in the "myhdfstuff" directory.
4. Change into the "build" folder.
5. Configure the C library, tools and tests with one of the following commands:
On Windows 32 bit
cmake -G "Visual Studio 16 2019" -A Win32 -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTING:BOOL=ON -DHDF4_BUILD_TOOLS:BOOL=ON ..\hdf-4.3"X"
On Windows 64 bit
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTING:BOOL=ON -DHDF4_BUILD_TOOLS:BOOL=ON ..\hdf-4.3"X"
On Linux and Mac
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTING:BOOL=ON -DHDF4_BUILD_TOOLS:BOOL=ON ../hdf-4.3"X"
where "X" is the current release version.
6. Build the C library, tools and tests with this command:
cmake --build . --config Release
7. Test the C library and tools with this command:
ctest . -C Release
8. Create an install image with this command:
cpack -C Release CPackConfig.cmake
9. To install
On Windows (with WiX installed), execute:
HDF-4.3."X"-win32.msi or HDF-4.3."X"-win64.msi
By default this program will install the hdf4 library into the
"C:\Program Files" directory and will create the following
directory structure:
HDF_Group
--HDF
----4.3."X"
------bin
------include
------lib
------cmake
On Linux, change to the install destination directory
(create if doesn't exist) and execute:
<path-to>/myhdfstuff/build/HDF-4.3."X"-Linux.sh
After accepting the license, the script will prompt:
By default the HDF4 will be installed in:
"<current directory>/HDF-4.3."X"-Linux"
Do you want to include the subdirectory HDF-4.3."X"-Linux?
Saying no will install in: "<current directory>" [Yn]:
Note that the script will create the following directory structure
relative to the install point:
HDF_Group
--HDF
----4.3."X"
------bin
------include
------lib
------share
On Mac you will find HDF-4.3."X"-Darwin.dmg in the build folder. Click
on the dmg file to proceed with installation. After accepting the license,
there will be a folder with the following structure:
HDF_Group
--HDF
----4.3."X"
------bin
------include
------lib
------share
========================================================================
IV. Further Considerations
========================================================================
1. We suggest you obtain the latest CMake for windows from the Kitware
web site. The HDF 4.3"X" product requires a minimum CMake version 3.18.
If you are using VS2022, the CMake minimum version is 3.21. CMakePresets
requires CMake 3.25.
2. HDF4 requires Zlib and JPEG. Szip (aka libaec) is optional:
A. Download the binary packages and install them in a central location.
For example on Windows, create a folder extlibs and install the
packages there. Add the following CMake options:
-DJPEG_LIBRARY:FILEPATH=some_location/lib/jpeg.lib
-DJPEG_INCLUDE_DIR:PATH=some_location/include
-DJPEG_USE_EXTERNAL:BOOL=OFF
-DZLIB_LIBRARY:FILEPATH=some_location/lib/zlib.lib
-DZLIB_INCLUDE_DIR:PATH=some_location/include
-DZLIB_USE_EXTERNAL:BOOL=OFF
-DSZIP_LIBRARY:FILEPATH=some_location/lib/libszaec.lib
-DSZIP_INCLUDE_DIR:PATH=some_location/include
-Dlibaec_LIBRARY:FILEPATH=some_location/lib/libaec.lib
-Dlibaec_INCLUDE_DIR:PATH=some_location/include
-DSZIP_USE_EXTERNAL:BOOL=OFF
where "some_location" is the full path to the extlibs folder.
Also if the appropriate environment variable is set, the above options are not required;
set(ENV{JPEG_ROOT} "some_location")
set(ENV{ZLIB_ROOT} "some_location")
set(ENV{SZIP_ROOT} "some_location")
set(ENV{libaec_ROOT} "some_location")
Note that if there is a problem finding the libraries, try adding the
CMake variable CMAKE_FIND_DEBUG_MODE:BOOL=ON to the command line.
B. Use source packages from an GIT server by adding the following CMake
options:
HDF4_ALLOW_EXTERNAL_SUPPORT:STRING="GIT"
JPEG_GIT_URL:STRING="https://some_location/jpeg"
JPEG_GIT_BRANCH="some_branch"
ZLIB_GIT_URL:STRING="https://some_location/zlib"
ZLIB_GIT_BRANCH="some_branch"
SZIP_GIT_URL:STRING="https://some_location/szip"
SZIP_GIT_BRANCH="some_branch"
LIBAEC_GIT_URL:STRING="https://some_location/libaec"
LIBAEC_GIT_BRANCH="some_branch"
where "some_location" is the URL to the GIT repository and "some_branch" is
a branch in the repository, usually the default. Also set
CMAKE_BUILD_TYPE to the configuration type.
C. Use source packages from a compressed file by adding the following
CMake options:
HDF4_ALLOW_EXTERNAL_SUPPORT:STRING="TGZ"
JPEG_TGZ_NAME:STRING="jpeg_src.ext"
ZLIB_TGZ_NAME:STRING="zlib_src.ext"
LIBAEC_TGZ_NAME:STRING="libaec_src.ext"
TGZPATH:STRING="some_location"
where "some_location" is the URL or full path to the compressed
file and ext is the type of compression file. Also set CMAKE_BUILD_TYPE
to the configuration type during configuration. See the settings in the
config/cmake/cacheinit.cmake file HDF uses for testing.
D. Use original source packages from a compressed file by adding the following
CMake options:
JPEG_TGZ_NAME:STRING="jpeg_src.ext"
JPEG_TGZ_ORIGPATH:STRING="some_location"
LIBAEC_TGZ_NAME:STRING="szip_src.ext"
LIBAEC_TGZ_ORIGPATH:STRING="some_location"
ZLIB_TGZ_NAME:STRING="zlib_src.ext"
ZLIB_TGZ_ORIGPATH:STRING="some_location"
HDF4_ALLOW_EXTERNAL_SUPPORT:STRING="TGZ"
where "some_location" is the URL and by setting
JPEG_USE_LOCALCONTENT:BOOL=ON
ZLIB_USE_LOCALCONTENT:BOOL=OFF
LIBAEC_USE_LOCALCONTENT:BOOL=OFF
or full path to the compressed file and ext is the type of compression file.
Also set CMAKE_BUILD_TYPE to the configuration type during configuration.
See the settings in the config/cmake/cacheinit.cmake file HDF uses for testing.
The files can also be retrieved from a local path if necessary
TGZPATH:STRING="some_location"
by setting
JPEG_USE_LOCALCONTENT:BOOL=ON
ZLIB_USE_LOCALCONTENT:BOOL=ON
LIBAEC_USE_LOCALCONTENT:BOOL=ON
3. If you are building on Apple Darwin platforms, you should add the
following options:
Compiler choice - use xcode by setting the ENV variables of CC
Shared Fortran is not supported, build static:
BUILD_SHARED_LIBS:BOOL=OFF
Additional options:
BUILD_JPEG_WITH_PIC:BOOL=ON
CTEST_USE_LAUNCHERS:BOOL=ON
CMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF
4. Windows developers should install NSIS or WiX to create an install image with CPack.
Visual Studio Express users will not be able to package HDF4 into
an install image executable.
5. Developers can copy the config/cmake/cacheinit.cmake file and alter the
the settings for the developers' environment. Then the only options needed
on the command line are those options that are different. Example using HDF
default cache file:
cmake -C ../config/cmake/cacheinit.cmake -G "Visual Studio 16 2019" \
-DHDF4_ENABLE_SZIP_SUPPORT:BOOL=OFF -DHDF4_ENABLE_EXAMPLES:BOOL=OFF \
-DCMAKE_BUILD_TYPE:STRING=Release ..
6. CMake uses a toolchain of utilities to compile, link libraries and
create archives, and other tasks to drive the build. The toolchain
utilities available are determined by the languages enabled. In normal
builds, CMake automatically determines the toolchain for host builds
based on system introspection and defaults. In cross-compiling
scenarios, a toolchain file may be specified with information about
compiler and utility paths.
Variables and Properties
Several variables relate to the language components of a toolchain which
are enabled. CMAKE_<LANG>_COMPILER is the full path to the compiler used
for <LANG>. CMAKE_<LANG>_COMPILER_ID is the identifier used by CMake for
the compiler and CMAKE_<LANG>_COMPILER_VERSION is the version of the compiler.
The CMAKE_<LANG>_FLAGS variables and the configuration-specific equivalents
contain flags that will be added to the compile command when compiling a
file of a particular language.
As the linker is invoked by the compiler driver, CMake needs a way to
determine which compiler to use to invoke the linker. This is calculated
by the LANGUAGE of source files in the target, and in the case of static
libraries, the language of the dependent libraries. The choice CMake makes
may be overridden with the LINKER_LANGUAGE target property.
See the CMake help for more information on using toolchain files.
To use a toolchain file with the supplied cmake scripts, see the
HDF4options.cmake file under the toolchain section.
Notes: CMake and HDF4
1. CMake support for HDF4 development should be usable on any
system where CMake is supported. Please send us any comments on
how CMake support can be improved on any system. Visit the
Kitware site for more information about CMake.
2. Build and test results can be submitted to our CDash server:
The CDash server for community submissions of hdf is at
https://my.cdash.org.
We ask that all submissions include the configuration information and
contact information in the CTest Notes Files upload step. See the
current reports on CDash for examples.
Please follow the convention that "NIGHTLY" submissions maintain the same
configuration every time. "EXPERIMENTAL" submissions can be expected to
be different for each submission.
3. See the appendix at the bottom of this file for examples of using
a ctest script for building and testing. Using a ctest script is
preferred because of its flexibility.
Notes: CMake in General
1. More information about using CMake can be found at the Kitware site at
www.cmake.org.
2. CMake uses the command line; however, the visual CMake tool is
available for the configuration step. The steps are similar for
all the operating systems supported by CMake.
3. Setting the installation location from the command line at configure time
a. Using the --install-prefix command line option, which is available since
CMake version 3.21:
cmake --install-prefix /my/folder/to/install/to ..
b. Using -DCMAKE_INSTALL_PREFIX :
cmake -DCMAKE_INSTALL_PREFIX=/my/folder/to/install/to ..
c. Using the CMAKE_INSTALL_PREFIX environment variable, which is available
since CMake version 3.29:
CMAKE_INSTALL_PREFIX=/my/folder/to/install/to cmake ..
========================================================================
V. Options for Building HDF4 Libraries with the CMake Command Line
========================================================================
To build the HDF4 Libraries with CMake, go through these five steps:
1. Run CMake
2. Configure the cache settings
3. Build HDF4
4. Test HDF4
5. Package HDF4 (create install image)
These five steps are described in detail below.
========================================================================
1. Run CMake
The visual CMake executable is named "cmake-gui.exe" on Windows and should be
available in your Start menu. For Linux, UNIX, and Mac users the
executable is named "cmake-gui" and can be found where CMake was
installed.
Another option is to use the presets file, CMakePresets.json, to configure,
build, test, and package HDF4. See section VIII: Using CMakePresets.json for compiling
for use of that file. You can create a CMakeUserPresets.json file to create a
specific configuration for your environment. Note that Visual Studio and XCode can
use the presets files.
Specify the source and build directories.
***** Make the build and source directories different. ******
For example on Windows, if the source is at c:\MyHDFstuff\hdf4,
then use c:\MyHDFstuff\hdf4\build or c:\MyHDFstuff\build\hdf4 as the
build directory.
RECOMMENDED:
Users can perform the configuration step without using the visual
cmake-gui program. We use the file cacheinit.cmake in the
config/cmake source folder for our testing. This file enables all of the
basic options and we turn specific options on or off for testing
using the following command line within the build directory:
cmake -C <sourcepath>/config/cmake/cacheinit.cmake -G "<generator>" [-D<options>] <sourcepath>
Where <generator> is
* MinGW Makefiles
* NMake Makefiles
* Unix Makefiles
* Ninja
* Visual Studio 15 2017
* Visual Studio 15 2017 Win64
* Visual Studio 16 2019
* Visual Studio 17 2022
<options> is:
For installed SZIP/libaec:
* SZIP_INCLUDE_DIR:PATH=<path to szip includes directory>
* SZIP_LIBRARY:FILEPATH=<path to szip/library file>
* libaec_INCLUDE_DIR:PATH=<path to libaec includes directory>
* libaec_LIBRARY:FILEPATH=<path to libaec/library file>
or
* SZIP_ROOT:PATH=<path to szip root directory>
* libaec_ROOT:PATH=<path to libaec root directory>
For installed ZLIB/ZLIBNG:
* ZLIB_INCLUDE_DIR:PATH=<path to zlib includes directory>
* ZLIB_LIBRARY:FILEPATH=<path to zlib/library file>
or
* ZLIB_ROOT:PATH=<path to zlib root directory>
For installed JPEG:
* JPEG_INCLUDE_DIR:PATH=<path to jpeg includes directory>
* JPEG_LIBRARY:FILEPATH=<path to jpeg/library file>
or
* JPEG_ROOT:PATH=<path to jpeg root directory>
* <HDF4OPTION>:BOOL=[ON | OFF]
<cacheinit.cmake> is:
# This is the CMakeCache file.
########################
# EXTERNAL cache entries
########################
set (CMAKE_INSTALL_FRAMEWORK_PREFIX "Library/Frameworks" CACHE STRING "Frameworks installation directory" FORCE)
set (HDF_PACKAGE_EXT "" CACHE STRING "Name of HDF package extension" FORCE)
set (HDF_PACKAGE_NAMESPACE "hdf4::" CACHE STRING "Name for HDF package namespace" FORCE)
set (HDF4_BUILD_EXAMPLES ON CACHE BOOL "Build HDF4 Library Examples" FORCE)
set (HDF4_BUILD_JAVA ON CACHE BOOL "Build HDF4 Java" FORCE)
set (HDF4_BUILD_UTILS ON CACHE BOOL "Build HDF4 Library Utilities" FORCE)
set (HDF4_BUILD_GENERATORS OFF CACHE BOOL "Build Test Generators" FORCE)
set (HDF4_ENABLE_SZIP_SUPPORT ON CACHE BOOL "Use SZip Filter" FORCE)
set (HDF4_ENABLE_SZIP_ENCODING ON CACHE BOOL "Use SZip Encoding" FORCE)
set (HDF4_ALLOW_EXTERNAL_SUPPORT "TGZ" CACHE STRING "Allow External Library Building (NO GIT TGZ)" FORCE)
set_property (CACHE HDF4_ALLOW_EXTERNAL_SUPPORT PROPERTY STRINGS NO GIT TGZ)
########################
# compression options
########################
set (ZLIB_PACKAGE_NAME "zlib" CACHE STRING "Name of ZLIB package" FORCE)
set (ZLIB_TGZ_NAME "zlib-1.3.1.tar.gz" CACHE STRING "Use ZLib from compressed file" FORCE)
set (ZLIB_TGZ_ORIGPATH "https://github.com/madler/zlib/releases/download/v1.3.1" CACHE STRING "Use ZLIB from original location" FORCE)
set (ZLIB_USE_LOCALCONTENT ON CACHE BOOL "Use local file for ZLIB FetchContent" FORCE)
set (ZLIB_GIT_URL "https://github.com/madler/zlib.git" CACHE STRING "Use ZLIB from GitHub repository" FORCE)
set (ZLIB_GIT_BRANCH "develop" CACHE STRING "" FORCE)
set (HDF4_USE_ZLIB_NG OFF CACHE BOOL "Use zlib-ng library as zlib library" FORCE)
set (ZLIBNG_PACKAGE_NAME "zlib-ng" CACHE STRING "Name of ZLIBNG package" FORCE)
set (ZLIBNG_TGZ_NAME "2.2.4.tar.gz" CACHE STRING "Use ZLib from compressed file" FORCE)
set (ZLIBNG_TGZ_ORIGPATH "https://github.com/zlib-ng/zlib-ng/archive/refs/tags" CACHE STRING "Use ZLIBNG from original location" FORCE)
set (ZLIBNG_GIT_URL "https://github.com/zlib-ng/zlib-ng.git" CACHE STRING "Use ZLIBNG from GitHub repository" FORCE)
set (ZLIBNG_GIT_BRANCH "develop" CACHE STRING "" FORCE)
set (LIBAEC_PACKAGE_NAME "libaec" CACHE STRING "Name of AEC SZIP package" FORCE)
set (LIBAEC_TGZ_NAME "libaec-1.1.3.tar.gz" CACHE STRING "Use SZip AEC from compressed file" FORCE)
set (LIBAEC_TGZ_ORIGPATH "https://github.com/MathisRosenhauer/libaec/releases/download/v1.1.3" CACHE STRING "Use LIBAEC from original location" FORCE)
set (LIBAEC_USE_LOCALCONTENT ON CACHE BOOL "Use local file for LIBAEC FetchContent" FORCE)
set (LIBAEC_GIT_URL "https://github.com/MathisRosenhauer/libaec.git" CACHE STRING "Use LIBAEC from GitHub repository" FORCE)
set (LIBAEC_GIT_BRANCH "v1.1.3" CACHE STRING "" FORCE)
set (JPEG_PACKAGE_NAME "jpeg" CACHE STRING "Name of JPEG package" FORCE)
set (JPEG_TGZ_ORIGPATH "https://www.ijg.org/filesz" CACHE STRING "Use JPEG from original location" FORCE)
set (JPEG_TGZ_NAME "jpegsrc.v9e.tar.gz" CACHE STRING "Use JPEG from original compressed file" FORCE)
set (JPEG_USE_LOCALCONTENT ON CACHE BOOL "Use local file for JPEG FetchContent" FORCE)
set (JPEG_GIT_URL "https://github.com/libjpeg-turbo/libjpeg-turbo.git" CACHE STRING "Use JPEG from TurboJPEG" FORCE)
set (JPEG_GIT_BRANCH "jpeg-9e" CACHE STRING "" FORCE)
#set (JPEG_GIT_URL "https://github.com/LuaDist/libjpeg.git" CACHE STRING "Use JPEG from ILG" FORCE)
#set (JPEG_GIT_BRANCH "master" CACHE STRING "" FORCE)
2. Configure the cache settings
2.1 Visual CMake users, click the Configure button. If this is the first time you are
running cmake-gui in this directory, you will be prompted for the
generator you wish to use (for example on Windows, Visual Studio 14).
CMake will read in the CMakeLists.txt files from the source directory and
display options for the HDF4 project. After the first configure you
can adjust the cache settings and/or specify the locations of other programs.
Any conflicts or new values will be highlighted by the configure
process in red. Once you are happy with all the settings and there are no
more values in red, click the Generate button to produce the appropriate
build files.
On Windows, if you are using a Visual Studio generator, the solution and
project files will be created in the build folder.
On linux, if you are using the Unix Makefiles generator, the Makefiles will
be created in the build folder.
2.2 Preferred command line example on Windows in c:\MyHDFstuff\hdf4\build directory:
cmake -C ../config/cmake/cacheinit.cmake -G "Visual Studio 16 2019" "-Ax64" \
-DHDF4_ENABLE_SZIP_SUPPORT:BOOL=OFF -DCMAKE_BUILD_TYPE:STRING=Release ..
2.3 On Windows, if you are using a Visual Studio Express version you must
be sure that the following two options are correctly set/unset:
HDF4_NO_PACKAGES:BOOL=ON
HDF4_USE_FOLDERS:BOOL=OFF
3. Build HDF4
On Windows, you can build HDF4 using either the Visual Studio Environment
or the command line. The command line can be used on all platforms;
Windows, linux, Unix, and Mac.
To build from the command line, navigate to your build directory and
execute the following:
cmake --build . --config {Debug | Release}
NOTE: "--config {Debug | Release}" may be optional on your platform. We
recommend choosing either Debug or Release on Windows.
3.1 If you wish to use the Visual Studio environment, open the solution
file in your build directory. Be sure to select either Debug or
Release and build the solution.
3.2.1 The external libraries (zlib, szip, and jpeg) can be configured
to allow building the libraries by downloading from a GIT repository.
The option is 'HDF4_ALLOW_EXTERNAL_SUPPORT'; by adding the following
configuration option:
-DHDF4_ALLOW_EXTERNAL_SUPPORT:STRING="GIT"
The options to control the GIT URL (config/cmake/cacheinit.cmake file) are:
JPEG_GIT_URL:STRING="https://${git_url}/jpeg9e"
JPEG_GIT_BRANCH="${git_branch}"
ZLIB_GIT_URL:STRING="https://${git_url}/zlib"
ZLIB_GIT_BRANCH="${git_branch}"
SZIP_GIT_URL:STRING="https://${git_url}/szip"
SZIP_GIT_BRANCH="${git_branch}"
LIBAEC_GIT_URL:STRING="https://${git_url}/libaec"
LIBAEC_GIT_BRANCH="${git_branch}"
${git_url} should be changed to your location and ${git_branch} is
your branch in the repository. Also define CMAKE_BUILD_TYPE
to be the configuration type.
3.2.2 Or the external libraries (zlib, szip, and jpeg) can be configured
to allow building the libraries by using a compressed file.
The option is 'HDF4_ALLOW_EXTERNAL_SUPPORT' and is enabled by
adding the following configuration option:
-DHDF4_ALLOW_EXTERNAL_SUPPORT:STRING="TGZ"
The options to control the TGZ URL (config/cmake/cacheinit.cmake
file) are:
JPEG_TGZ_NAME:STRING="jpeg_src.ext"
ZLIB_TGZ_NAME:STRING="zlib_src.ext"
LIBAEC_TGZ_NAME:STRING="libaec_src.ext"
TGZPATH:STRING="some_location"
where "some_location/xxxx_src.ext" is the URL or full path to
the compressed file and where ext is the type of the compression
file such as .bz2, .tar, .tar.gz, .tgz, or .zip. Also define
CMAKE_BUILD_TYPE to be the configuration type.
NOTE: the file named by LIBAEC_TGZ_NAME is used to build SZIP.
4. Test HDF4
To test the build, navigate to your build directory and execute:
ctest . -C {Debug | Release}
NOTE: "-C {Debug | Release}" may be optional on your platform. We
recommend choosing either Debug or Release to match the build
step on Windows.
5. Packaging HDF4 (create an install image)
To package the build into a simple installer using WiX toolset or the NullSoft installer NSIS
on Windows, or into compressed files (.tar.gz, .sh, .zip), use the CPack tool.
To package the build, navigate to your build directory and execute;
cpack -C {Debug | Release} CPackConfig.cmake
NOTE: See note 8 of this document for NSIS information.
See note 9 of this document for WiX information.
Also, if you are using a Visual Studio Express version or
want to disable the packaging components, set HDF4_NO_PACKAGES
to ON (on the command line add -DHDF4_NO_PACKAGES:BOOL=ON)
6. The files that support building HDF4 with CMake are all the files in the
config/cmake folder, the CMakeLists.txt files in each source folder, and
CTestConfig.cmake. CTestConfig.cmake is specific to the internal testing
performed by The HDF Group. It should be altered for the user's
installation and needs. The cacheinit.cmake file settings are used by
The HDF Group for daily testing. It should be altered/ignored for the user's
installation and needs.
7. More information about using CMake can be found at the Kitware site,
www.cmake.org.
8. Nullsoft Scriptable Install System
The Nullsoft Scriptable Install System (NSIS) is an open source installation
system. It was created by the WinAmp authors to distribute that application,
but it is now a general-purpose system which anyone might use. NSIS installers
recognize /S for silent installation and /D=dir to specify the
"output directory", which is where the program will be installed. These
options are case-sensitive, so be sure to type them in upper case.
9. WiX Toolset
WiX--the Windows Installer XML toolset--lets developers create installers for
Windows Installer, the Windows installation engine. See http://wixtoolset.org.
========================================================================
VI. CMake Option Defaults for HDF4
========================================================================
In the options listed below, there are three columns of information:
Option Name, Option Description, and Option Default.
The config/cmake/cacheinit.cmake or CMakePresets.json file can override the following values.
---------------- General Build Options -------------------------------------
BUILD_SHARED_LIBS "Build Shared Libraries" ON
BUILD_STATIC_LIBS "Build Static Libraries" ON
BUILD_TESTING "Build HDF4 Unit Testing" ON
---------------- HDF4 Build Options ----------------------------------------
HDF4_BUILD_EXAMPLES "Build HDF4 Library Examples" OFF
HDF4_BUILD_FORTRAN "Build FORTRAN support" OFF
HDF4_BUILD_TOOLS "Build HDF4 Tools" ON
HDF4_BUILD_UTILS "Build HDF4 Utilities" OFF
HDF4_ENABLE_NETCDF "Build HDF4 versions of NetCDF-3 APIS" ON
HDF4_BUILD_JAVA "Build Java HDF Library" OFF
HDF4_BUILD_NETCDF_TOOLS "Build HDF4 versions of ncdump and ncgen" ON
HDF4_BUILD_STATIC_TOOLS "Build Static Tools Not Shared Tools" OFF
---------------- HDF4 Folder Build Options ---------------------------------
Defaults relative to $<INSTALL_PREFIX>
HDF4_INSTALL_BIN_DIR "bin"
HDF4_INSTALL_LIB_DIR "lib"
HDF4_INSTALL_INCLUDE_DIR "include"
HDF4_INSTALL_MODULE_DIR "mod"
HDF4_INSTALL_CMAKE_DIR "cmake"
if (MSVC)
HDF4_INSTALL_DATA_DIR "."
else ()
HDF4_INSTALL_DATA_DIR "share"
HDF4_INSTALL_DOC_DIR "HDF4_INSTALL_DATA_DIR"
HDF4_USE_GNU_DIRS "ON to use GNU Coding Standard install directory variables,
OFF to use historical settings" OFF
Defaults as defined by the `GNU Coding Standards`
HDF4_INSTALL_BIN_DIR "bin"
HDF4_INSTALL_LIB_DIR "lib"
HDF4_INSTALL_INCLUDE_DIR "include"
HDF4_INSTALL_MODULE_DIR "HDF4_INSTALL_INCLUDE_DIR/mod"
HDF4_INSTALL_CMAKE_DIR "HDF4_INSTALL_LIB_DIR/cmake"
HDF4_INSTALL_DATA_DIR "share"
HDF4_INSTALL_DOC_DIR "HDF4_INSTALL_DATA_DIR/doc/hdf"
---------------- HDF4 Advanced Options ---------------------
HDF4_ONLY_SHARED_LIBS "Only Build Shared Libraries" OFF
HDF4_DISABLE_COMPILER_WARNINGS "Disable compiler warnings" OFF
HDF4_ENABLE_COVERAGE "Enable code coverage for Libraries and Programs" OFF
HDF4_ENABLE_DEPRECATED_SYMBOLS "Enable deprecated public API symbols" ON
HDF4_ENABLE_LARGE_FILE "Enable support for large (64-bit) files on Linux." ON
HDF4_NO_PACKAGES "Do not include CPack Packaging" OFF
HDF4_PACKAGE_EXTLIBS "CPACK - include external libraries" OFF
HDF4_USE_FOLDERS "Enable folder grouping of projects in IDEs." OFF
HDF4_MSVC_NAMING_CONVENTION "Use MSVC Naming conventions for Shared Libraries" OFF
HDF4_MINGW_STATIC_GCC_LIBS "Statically link libgcc/libstdc++" OFF
if (APPLE)
HDF4_BUILD_WITH_INSTALL_NAME "Build with library install_name set to the installation path" OFF
if (WIN32)
HDF_LEGACY_NAMING "Use Legacy Names for Libraries and Programs" OFF
HDF4_ENABLE_NETCDF "Build HDF4 versions of NetCDF-3 APIS" ON
HDF4_BUILD_DOC "Build documentation" OFF
HDF4_ENABLE_DOXY_WARNINGS "Enable fail if doxygen parsing has warnings." OFF
HDF4_USING_ANALYSIS_TOOL "Indicate that an analysis checker is used" ON
---------------- External Library Options ---------------------
HDF4_ALLOW_EXTERNAL_SUPPORT "Allow External Library Building" "NO"
HDF4_ENABLE_SZIP_SUPPORT "Use SZip Filter" OFF
JPEG_USE_EXTERNAL "Use External Library Building for JPEG" OFF
JPEG_TGZ_ORIGPATH "Use JPEG from original location" "https://www.ijg.org/filesz"
JPEG_TGZ_NAME "Use JPEG from original compressed file" "jpegsrc.v9e.tar.gz"
JPEG_USE_LOCALCONTENT "Use local file for JPEG FetchContent" OFF
if (HDF4_USE_ZLIB_NG)
ZLIBNG_USE_EXTERNAL "Use External Library Building for ZLIBNG" OFF
ZLIBNG_TGZ_ORIGPATH "Use ZLIBNG from original location" "https://github.com/zlib-ng/zlib-ng/releases/tag/2.2.2"
ZLIBNG_TGZ_NAME "Use ZLIBNG from original compressed file" "2.2.2.tar.gz"
else
ZLIB_USE_EXTERNAL "Use External Library Building for ZLIB" OFF
ZLIB_TGZ_ORIGPATH "Use ZLIB from original location" "https://github.com/madler/zlib/releases/download/v1.3.1"
ZLIB_TGZ_NAME "Use ZLIB from original compressed file" "zlib-1.3.1.tar.gz"
ZLIB_USE_LOCALCONTENT "Use local file for ZLIB FetchContent" ON
HDF4_USE_ZLIB_STATIC "Find static zlib library" OFF
SZIP_USE_EXTERNAL "Use External Library Building for SZIP" OFF
if (HDF4_ENABLE_SZIP_SUPPORT)
HDF4_ENABLE_SZIP_ENCODING "Use SZip Encoding" OFF
LIBAEC_TGZ_ORIGPATH "Use LIBAEC from original location" "https://github.com/MathisRosenhauer/libaec/releases/download/v1.1.3"
LIBAEC_TGZ_NAME "Use LIBAEC from original compressed file" "libaec-1.1.3.tar.gz"
LIBAEC_USE_LOCALCONTENT "Use local file for LIBAEC FetchContent" ON
HDF4_USE_LIBAEC_STATIC "Find static AEC library" OFF
NOTE:
The HDF4_USE_GNU_DIRS option is usually recommended for linux platforms, but may
be useful on other platforms. See the CMake documentation for more details.
========================================================================
VII. User Defined Options for HDF4 Libraries with CMake
========================================================================
Support for User Defined macros and options has been added. The file
UserMacros.cmake has an example of the technique.
Replace the template code with your macro in the UserMacros.cmake file.
Then enable the option to the CMake configuration, build and test process.
========================================================================
VIII: Using CMakePresets.json for Compiling
========================================================================
One problem that CMake users often face is sharing settings with other people for common
ways to configure a project. This may be done to support CI builds, or for users who
frequently use the same build. CMake supports two main files, CMakePresets.json and CMakeUserPresets.json,
that allow users to specify common configure options and share them with others. CMake also supports
files included with the include field.
CMakePresets.json and CMakeUserPresets.json live in the project's root directory. They
both have exactly the same format, and both are optional (though at least one must be
present if --preset is specified). CMakePresets.json is meant to specify project-wide build
details, while CMakeUserPresets.json is meant for developers to specify their own local build details.
See CMake documentation for details: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
HDF-provided CMakePresets.json
-------------------------------
The CMakePresets.json provided by HDF requires CMake version 3.25, which supports package
and workflow presets, and ninja build system. The top-level configuration group is intended to be
a standard set of options to produce a package of shared and staic libraries and tools. Other configurations
used for inheriting settings are in the included json file in "config/cmake-presets/hidden-presets.json".
Available configurations presets can be displayed by executing:
cmake -S <path-to-source> --list-presets
Using individual command presets (where <compiler-type> is GNUC or MSVC or Clang):
change directory to the hdf4 source folder
cmake --preset ci-StdShar-<compiler-type>
cmake --build --preset ci-StdShar-<compiler-type>
ctest --preset ci-StdShar-<compiler-type>
cpack --preset ci-StdShar-<compiler-type>
Using the workflow preset to configure, build, test and package the standard configuration:
change directory to the hdf4 source folder
execute "cmake --workflow --preset ci-StdShar-<compiler-type> --fresh"
where <compiler-type> is GNUC or MSVC or Clang
Creating your own configurations
--------------------------------
The quickest way is to copy CMakePresets.json to CMakeUserPresets.json and
edit CMakeUserPresets.json configuration names from ci-* to my-*. Change the
"configurePresets" section "inherits" field only for those that you have alternate
options. Then change the "configurePreset" field entries in the "buildPresets",
"testPresets", "packagePresets" sections to match your my-StdShar-<compiler-type>.
And finally the names settings in the "workflowPresets" steps will also need the ci-* to my-* change.
For instance, to change the support files to use a local directory, edit CMakeUserPresets.json:
......
{
"name": "my-base-tgz",
"hidden": true,
"inherits": "ci-base",
"cacheVariables": {
"HDF4_ALLOW_EXTERNAL_SUPPORT": {"type": "STRING", "value": "TGZ"},
"TGZPATH": {"type": "PATH", "value": "${sourceParentDir}/temp"}
}
},
{
"name": "my-StdCompression",
"hidden": true,
"inherits": "my-base-tgz",
"cacheVariables": {
......
{
"name": "my-StdShar",
"hidden": true,
"inherits": "my-StdCompression",
"cacheVariables": {
......
{
"name": "my-StdShar-GNUC",
"description": "GNUC Standard Config for x64 (Release)",
"inherits": [
"ci-x64-Release-GNUC",
"ci-Java",
"my-StdShar",
"my-StdExamples"
]
}
......
Then you can change or add options for your specific case.
========================================================================
IX. Using the Library
========================================================================
For information on using HDF4 see the documentation, tutorials and examples
found here:
https://support.hdfgroup.org/documentation/index.html
A summary of the features included in the built HDF4 installation can be found
in the libhdf4.settings file in the same directory as the static and/or
shared HDF5 libraries. However CMake provides a programmable method to
determine the features of the library. The CMake installation will
provide a CMake package configuration file, located in the installation folder,
cmake/hdf4-config.cmake, and can be used to determine the features of the library.
The file is accessed by using the find_package command in your CMakeLists.txt file.
1. Set the HDF5_ROOT CMake variable, -DHDF4_ROOT=<install_path>
or environment variable, set(ENV{HDF4_ROOT} "<install_path>")
to the installed location of HDF4.
On Windows:
HDF4_ROOT=C:/Program Files/HDF_Group/HDF4/z.y.x/
On unix:
HDF4_ROOT=<install root folder>/HDF_Group/HDF4/z.y.x/
If you are using shared libraries, you may need to add to the path
environment variable. Set the path environment variable to the
installed location of the library files for HDF4.
On Windows (*.dll):
PATH=%PATH%;C:/Program Files/HDF_Group/HDF4/z.y.x/bin
On unix (*.so):
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<install root folder>/HDF_Group/HDF4/z.y.x/lib
(Note there are no quote characters used on Windows and all platforms
use forward slashes)
2. Add the following to your CMakeLists.txt file:
find_package (HDF4 NAMES hdf4 COMPONENTS C shared)
The components are optional and can be omitted if not needed. The
components are: shared, static, C, Fortran, Java and Tools.
========================================================================
X. Autotools Configuration and Build
========================================================================
See RELEASE.txt in the release_notes/ directory for the list of platforms
tested for this release.
Instructions for building and testing HDF4 using autotools can be found in the
INSTALL_Auto.txt file found in this folder.
========================================================================
For further assistance, send email to help@hdfgroup.org
========================================================================
|