Skip to content

Commit

Permalink
Fix linking to NetCDF
Browse files Browse the repository at this point in the history
  • Loading branch information
kgerheiser committed Aug 7, 2020
1 parent bd7cf33 commit fd981bc
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions wgrib2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,36 @@ add_subdirectory(gctpc)
# with -DCALLABLE_WGRIB2
add_library(obj_lib OBJECT ${lib_src})
target_compile_definitions(obj_lib PUBLIC ${definitions_list})
target_link_libraries(obj_lib PRIVATE gctpc)

# with -DCALLABLE_WGRIB2 for the lib
add_library(wgrib2_lib $<TARGET_OBJECTS:obj_lib> ${callable_src})
# library and executable have same name (wgrib2) but different target names
set_target_properties(wgrib2_lib PROPERTIES OUTPUT_NAME wgrib2)

target_compile_definitions(wgrib2_lib PRIVATE CALLABLE_WGRIB2)
target_link_libraries(wgrib2_lib PUBLIC gctpc)

# without -DCALLABLE_WGRIB2 for the executable
add_executable(wgrib2_exe $<TARGET_OBJECTS:obj_lib> ${callable_src})
set_target_properties(wgrib2_exe PROPERTIES OUTPUT_NAME wgrib2)
target_link_libraries(wgrib2_exe PRIVATE gctpc)

if(USE_NETCDF4)
target_link_libraries(wgrib2_lib PUBLIC NetCDF::NetCDF_C)
target_link_libraries(wgrib2_exe PUBLIC NetCDF::NetCDF_C)
target_link_libraries(obj_lib PUBLIC NetCDF::NetCDF_C)
target_link_libraries(wgrib2_exe PRIVATE NetCDF::NetCDF_C)
endif()

if(USE_JASPER)
target_include_directories(obj_lib PUBLIC ${JASPER_INCLUDE_DIR})
target_link_libraries(obj_lib PUBLIC ${JASPER_LIBRARIES})
target_link_libraries(wgrib2_exe PRIVATE ${JASPER_LIBRARIES})
target_link_libraries(wgrib2_lib PUBLIC ${JASPER_LIBRARIES})
endif()

if(USE_PNG)
target_link_libraries(obj_lib PUBLIC PNG::PNG)
target_link_libraries(wgrib2_exe PRIVATE PNG::PNG)
target_link_libraries(wgrib2_lib PUBLIC PNG::PNG)
endif()

if(OpenMP_FOUND)
target_link_libraries(obj_lib PUBLIC OpenMP::OpenMP_C)
target_link_libraries(wgrib2_exe PRIVATE OpenMP::OpenMP_C)
endif()

Expand All @@ -56,10 +55,10 @@ endif()

if(USE_IPOLATES EQUAL 3)
target_link_libraries(obj_lib PUBLIC ip2::ip2_d)
target_link_libraries(wgrib2_exe PUBLIC ip2::ip2_d)
target_link_libraries(wgrib2_lib PUBLIC ip2::ip2_d)
endif()

target_link_libraries(obj_lib PUBLIC gctpc)
target_link_libraries(wgrib2_exe PRIVATE gctpc)

install(
TARGETS wgrib2_lib wgrib2_exe
Expand Down

0 comments on commit fd981bc

Please sign in to comment.