update build system and netcdf.cpp

This commit is contained in:
张壹 2021-08-01 14:37:01 +08:00
parent 7428b5a6f0
commit 0c6e4bdad7
5 changed files with 53 additions and 16 deletions

View File

@ -4,7 +4,12 @@ cmake_minimum_required(VERSION 3.15.2)
project(NETCDF_CXX)
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
set(CMAKE_INSTALL_PREFIX "D:/Library")
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
#set(CMAKE_C_COMPILER gcc)
#set(CMAKE_CXX_COMPILER g++)
set(CMAKE_INSTALL_PREFIX D:/Library)
endif()
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
#
add_subdirectory(src/)

View File

@ -1,4 +1,4 @@
# netcdfcxx_win
# netcdfcxx_legacy
#### 介绍
一个windows下netcdf c++接口的编译项目注意使用的是4.2版本的老接口。

16
config.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
cmd=${1}
package=netcdfcxx_legacy
address=/opt
if [[ ${cmd} == "configure" && ! -d "build/" ]]; then
mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=${address}/stow/${package} -DCMAKE_BUILD_TYPE=Release
elif [[ ${cmd} == "configure" ]]; then
cd build && rm -rf * && cmake .. -DCMAKE_INSTALL_PREFIX=${address}/stow/${package} -DCMAKE_BUILD_TYPE=Release
elif [[ ${cmd} == "build" ]]; then
cd build && make
elif [[ ${cmd} == "install" ]]; then
cd build && sudo make install
sudo stow --dir=${address}/stow --target=${address} ${package}
fi

View File

@ -1,8 +1,8 @@
#
aux_source_directory(lib/ NETCDF_SRC)
# netcdf c
set(LIB_NETCDF_INC C:/Program\ Files/netCDF\ 4.8.0/include)
set(LIB_NETCDF_LIB C:/Program\ Files/netCDF\ 4.8.0/lib)
set(LIB_NETCDF_INC /opt/homebrew/include)
set(LIB_NETCDF_LIB /opt/homebrew/lib)
# netcdf cmakeVS
# gctl->->->netcdf
#set(LIB_NETCDF_BIN C:/Program\ Files/netCDF\ 4.8.0/bin)
@ -17,24 +17,24 @@ set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
#
#
# libcmake
add_library(netcdf_c++ SHARED ${NETCDF_SRC})
add_library(netcdfcxx_legacy SHARED ${NETCDF_SRC})
#
add_library(netcdf_c++_static STATIC ${NETCDF_SRC})
add_library(netcdfcxx_legacy_static STATIC ${NETCDF_SRC})
#
set_target_properties(netcdf_c++_static PROPERTIES OUTPUT_NAME "netcdf_c++")
set_target_properties(netcdfcxx_legacy_static PROPERTIES OUTPUT_NAME "netcdfcxx_legacy")
#
set_target_properties(netcdf_c++ PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties(netcdf_c++_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties(netcdfcxx_legacy PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties(netcdfcxx_legacy_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
#
set_target_properties(netcdf_c++ PROPERTIES VERSION 1.0 SOVERSION 1.0)
set_target_properties(netcdfcxx_legacy PROPERTIES VERSION 1.0 SOVERSION 1.0)
find_library(NETCDF_LIBRARY netcdf ${LIB_NETCDF_LIB})
target_link_libraries(netcdf_c++ PUBLIC ${NETCDF_LIBRARY})
target_link_libraries(netcdf_c++_static ${NETCDF_LIBRARY})
target_link_libraries(netcdfcxx_legacy PUBLIC ${NETCDF_LIBRARY})
target_link_libraries(netcdfcxx_legacy_static ${NETCDF_LIBRARY})
#
install(TARGETS netcdf_c++ DESTINATION lib)
install(TARGETS netcdf_c++_static DESTINATION lib)
install(TARGETS netcdfcxx_legacy DESTINATION lib)
install(TARGETS netcdfcxx_legacy_static DESTINATION lib)
#
install(FILES lib/netcdfcpp.h DESTINATION include)
install(FILES lib/ncvalues.h DESTINATION include)
@ -48,9 +48,9 @@ macro(add_sample name)
#
add_executable(${name} example/${name}.cpp)
# Windows
set_target_properties(${name} PROPERTIES INSTALL_RPATH D:/Library/lib)
set_target_properties(${name} PROPERTIES INSTALL_RPATH /opt/lib)
#
target_link_libraries(${name} PUBLIC netcdf_c++)
target_link_libraries(${name} PUBLIC netcdfcxx_legacy)
endmacro()
add_sample(pres_temp_4D_rd)

View File

@ -648,6 +648,7 @@ long* NcVar::edges( void ) const // edge lengths (dimension sizes)
int NcVar::num_atts( void ) const // handles variable and global atts
{
/*
int natt = 0;
if (the_file->is_valid())
if (the_id == ncGlobal)
@ -657,6 +658,21 @@ int NcVar::num_atts( void ) const // handles variable and global atts
nc_inq_varnatts(the_file->id(), the_id, &natt)
);
return natt;
*/
int natt = 0;
if (the_file->is_valid())
{
if (the_id == ncGlobal)
{
natt = the_file->num_atts();
}
else
{
NcError::set_err(nc_inq_varnatts(the_file->id(), the_id, &natt));
}
}
return natt;
}
NcAtt* NcVar::get_att( NcToken aname ) const