From 66a05db0cec2e8a730490d2304c4f1f6541cad9d Mon Sep 17 00:00:00 2001
From: acpaquette <acpaquette@usgs.gov>
Date: Tue, 23 Jan 2024 13:21:05 -0700
Subject: [PATCH] USGSCSM Internal Dependency Building (#445)

* Added proj as an internal dep

* Updated all internal deps

* Updated metal.yaml

* Forced conda builds to use internal deps

* Updated build flags for future releases

* fixed typo in BUILD_TESTS option

* Added sqlite as a dep

* Corrected meta.yml for release

* Change env to minimum dependency set

* Added recursive init for JSON

* Removed unnecessary submodule update

* Initial round to get ALE building directly into USGSCSM

* Fixed external dep build and reverted env file

* Fixed linux builds

* Built proj internal to USGSCSM

* Updated local build system

* Pointed build at this branch

* Updated recipe checksum

* Added submodules

* Added proj submodule

* Updated proj hash

* Turned building docs off

* Placed proj_config.h into correct directory

* Updated where the proj_config.h can be found

* Small changes to get the build working

* Removed commented out deps in meta.yaml

* Removed unnecessary lines in cmakelist file

* Reset git url and version

* Removed commented out ALE header lines
---
 .gitmodules      |   3 +
 CMakeLists.txt   | 647 +++++++++++++++++++++++++++++++++++++++++++++--
 PROJ             |   1 +
 ale              |   2 +-
 csm              |   2 +-
 json             |   2 +-
 recipe/build.sh  |   3 +-
 recipe/meta.yaml |  33 ++-
 8 files changed, 649 insertions(+), 44 deletions(-)
 create mode 160000 PROJ

diff --git a/.gitmodules b/.gitmodules
index fc36b0f..9e0af8e 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -10,3 +10,6 @@
 [submodule "json"]
 	path = json
 	url = https://github.com/nlohmann/json.git
+[submodule "PROJ"]
+	path = PROJ
+	url = https://github.com/OSGeo/PROJ
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 492d7aa..6d1b493 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,10 +19,31 @@ endif()
 
 # Use external or embedded dependencies
 option(USGSCSM_EXTERNAL_DEPS "If the library should be built with external or embedded dependencies" OFF)
+option(ENABLE_CURL "Set to build the curl components of proj" OFF)
+option(ENABLE_TIFF "Set to build the TIFF components of proj" OFF)
+option(BUILD_TESTING "Set to build the proj tests" OFF)
+option(BUILD_APPS "Set to build the proj apps" OFF)
 
 # To find JSON's config file
 set (CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/cmake;${CMAKE_PREFIX_PATH}")
 
+set(USGSCSM_SRC_FILES src/UsgsAstroPlugin.cpp
+                      src/UsgsAstroPluginSupport.cpp
+                      src/UsgsAstroFrameSensorModel.cpp
+                      src/UsgsAstroPushFrameSensorModel.cpp
+                      src/UsgsAstroLsSensorModel.cpp
+                      src/UsgsAstroProjectedSensorModel.cpp
+                      src/UsgsAstroSarSensorModel.cpp
+                      src/Distortion.cpp
+                      src/Utilities.cpp
+                      src/EigenUtilities.cpp
+)
+
+set(USGSCSM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include/usgscsm"
+                         "${CMAKE_CURRENT_SOURCE_DIR}/include"
+                         "${CMAKE_CURRENT_SOURCE_DIR}"
+)
+
 if(USGSCSM_EXTERNAL_DEPS)
   message(STATUS "Using external dependencies")
   # CSM API library
@@ -42,6 +63,11 @@ if(USGSCSM_EXTERNAL_DEPS)
   # ALE
   find_package(ale REQUIRED)
   set(ALE_TARGET ale::ale)
+
+  # Proj
+  find_package(PROJ REQUIRED CONFIG)
+  set(PROJ_TARGET PROJ::proj)
+  add_library(usgscsm SHARED ${USGSCSM_SRC_FILES})
 else()
   message(STATUS "Using embedded dependencies")
   # CSM API library
@@ -49,46 +75,611 @@ else()
   set(CSM_INCLUDE_DIR /csm)
   set(CSM_LIBRARY csmapi)
 
+  # First configure proj library
+  set(BUILD_SHARED_LIBS OFF)
+  set(PROJ_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/PROJ")
+  set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PROJ/cmake ${CMAKE_MODULE_PATH})
+  set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PROJ/src ${CMAKE_MODULE_PATH})
+
+  ################################################################################
+  # Check for sqlite3
+  ################################################################################
+
+  find_program(EXE_SQLITE3 sqlite3)
+  if(NOT EXE_SQLITE3)
+    message(SEND_ERROR "sqlite3 binary not found!")
+  endif()
+
+  find_package(Sqlite3 REQUIRED)
+  if(NOT SQLITE3_FOUND)
+    message(SEND_ERROR "sqlite3 dependency not found!")
+  endif()
+
+  # Would build and run with older versions, but with horrible performance
+  # See https://github.com/OSGeo/PROJ/issues/1718
+  if("${SQLITE3_VERSION}" VERSION_LESS "3.11")
+    message(SEND_ERROR "sqlite3 >= 3.11 required!")
+  endif()
+
+  include(ProjUtilities)
+  include(Ccache)
+  ################################################################################
+  # ProjConfig.cmake - CMake build configuration of PROJ library
+  ################################################################################
+  # Copyright (C) 2010 Mateusz Loskot <mateusz@loskot.net>
+  #
+  # Distributed under the Boost Software License, Version 1.0.
+  # (See accompanying file LICENSE_1_0.txt or copy at
+  # https://www.boost.org/LICENSE_1_0.txt)
+  ################################################################################
+  include(CheckLibraryExists)
+  include(CheckFunctionExists)
+
+  # if C flags have -Werror, temporarily remove these while running some checks
+  string(FIND "${CMAKE_C_FLAGS}" "-Werror" FIND_WERROR)
+  if(FIND_WERROR GREATER_EQUAL 0)
+    # we must be careful about not matching -Werror=something, so let's append
+    # a space at the end of CMAKE_C_FLAGS and match -Werror with a trailing space
+    string(REPLACE "-Werror " " " _tmp_CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
+    set(_prev_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+    set(CMAKE_C_FLAGS "${_tmp_CMAKE_C_FLAGS}")
+  endif()
+
+  # check needed include file
+  check_function_exists(localeconv HAVE_LOCALECONV)
+  check_function_exists(strerror HAVE_STRERROR)
+  if(NOT WIN32)
+    check_library_exists(dl dladdr "" HAVE_LIBDL)
+    check_library_exists(m exp "" HAVE_LIBM)
+  endif()
+
+  # restore CMAKE_C_FLAGS as before
+  if(FIND_WERROR GREATER_EQUAL 0)
+    set(CMAKE_C_FLAGS "${_prev_CMAKE_C_FLAGS}")
+  endif()
+
+  # check if a second proj_config.h exists (created by ./configure)
+  # as this is within CMake's C_INCLUDES / CXX_INCLUDES
+  set(AUTOCONF_PROJ_CONFIG_H "${PROJ_SOURCE_DIR}/src/proj_config.h")
+  if(EXISTS ${AUTOCONF_PROJ_CONFIG_H})
+    message(WARNING
+      "Autoconf's ${AUTOCONF_PROJ_CONFIG_H} may interfere with this "
+      "CMake build. Run 'make distclean' in the source directory "
+      "before CMake's build.")
+  endif()
+
+  message("${CMAKE_CURRENT_SOURCE_DIR}")
+  configure_file(${PROJ_SOURCE_DIR}/cmake/proj_config.cmake.in ${PROJ_SOURCE_DIR}/src/proj_config.h)
+  include(ProjMac)
+  include(policies)
+
+  set(PROJ_DATA_PATH "${CMAKE_INSTALL_FULL_DATADIR}/usgscsm")
+
+  include_directories(${PROJ_SOURCE_DIR}/src)
+  add_subdirectory(PROJ/data)
+
+  message(STATUS "Configuring proj library:")
+
+  ##############################################
+  ### SWITCH BETWEEN STATIC OR SHARED LIBRARY###
+  ##############################################
+
+  # default config is shared
+  option(BUILD_SHARED_LIBS
+    "Build PROJ library shared." ON)
+
+  find_package(Threads QUIET)
+  if(Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
+    add_definitions(-DPROJ_HAS_PTHREADS)
+  endif()
+
+  option(ENABLE_IPO
+    "Build library with interprocedural optimization (if available)." OFF)
+  if(ENABLE_IPO)
+    cmake_policy(SET CMP0069 NEW)
+    include(CheckIPOSupported)
+    check_ipo_supported(RESULT ENABLE_IPO)
+  endif()
+  print_variable(ENABLE_IPO)
+
+
+  ##############################################
+  ###  library source list and include_list  ###
+  ##############################################
+
+  set(SRC_LIBPROJ_PROJECTIONS
+    ${PROJ_SOURCE_DIR}/src/projections/aeqd.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/adams.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/gnom.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/laea.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/mod_ster.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/nsper.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/nzmg.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/ortho.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/stere.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/sterea.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/aea.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/bipc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/bonne.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/eqdc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/isea.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/ccon.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/imw_p.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/krovak.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/lcc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/poly.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/rpoly.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/sconics.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/rouss.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/cass.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/cc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/cea.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/eqc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/gall.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/labrd.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/som.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/merc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/mill.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/ocea.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/omerc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/somerc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/tcc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/tcea.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/times.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/tmerc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/tobmerc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/airy.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/aitoff.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/august.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/bacon.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/bertin1953.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/chamb.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/hammer.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/lagrng.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/larr.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/lask.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/latlong.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/nicol.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/ob_tran.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/oea.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/tpeqd.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/vandg.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/vandg2.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/vandg4.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/wag7.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/lcca.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/geos.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/boggs.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/collg.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/comill.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/crast.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/denoy.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/eck1.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/eck2.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/eck3.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/eck4.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/eck5.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/fahey.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/fouc_s.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/gins8.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/gstmerc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/gn_sinu.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/goode.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/igh.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/igh_o.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/imoll.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/imoll_o.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/hatano.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/loxim.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/mbt_fps.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/mbtfpp.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/mbtfpq.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/moll.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/nell.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/nell_h.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/patterson.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/putp2.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/putp3.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/putp4p.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/putp5.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/putp6.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/qsc.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/robin.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/s2.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/sch.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/sts.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/urm5.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/urmfps.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/wag2.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/wag3.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/wink1.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/wink2.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/healpix.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/natearth.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/natearth2.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/calcofi.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/eqearth.cpp
+    ${PROJ_SOURCE_DIR}/src/projections/col_urban.cpp
+  )
+
+  set(SRC_LIBPROJ_CONVERSIONS
+    ${PROJ_SOURCE_DIR}/src/conversions/axisswap.cpp
+    ${PROJ_SOURCE_DIR}/src/conversions/cart.cpp
+    ${PROJ_SOURCE_DIR}/src/conversions/geoc.cpp
+    ${PROJ_SOURCE_DIR}/src/conversions/geocent.cpp
+    ${PROJ_SOURCE_DIR}/src/conversions/noop.cpp
+    ${PROJ_SOURCE_DIR}/src/conversions/topocentric.cpp
+    ${PROJ_SOURCE_DIR}/src/conversions/set.cpp
+    ${PROJ_SOURCE_DIR}/src/conversions/unitconvert.cpp
+  )
+
+  set(SRC_LIBPROJ_TRANSFORMATIONS
+    ${PROJ_SOURCE_DIR}/src/transformations/affine.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/deformation.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/gridshift.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/helmert.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/hgridshift.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/horner.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/molodensky.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/vgridshift.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/xyzgridshift.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/defmodel.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/tinshift.cpp
+    ${PROJ_SOURCE_DIR}/src/transformations/vertoffset.cpp
+  )
+
+  set(SRC_LIBPROJ_ISO19111
+    ${PROJ_SOURCE_DIR}/src/iso19111/static.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/util.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/metadata.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/common.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/coordinates.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/crs.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/datum.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/coordinatesystem.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/io.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/internal.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/factory.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/c_api.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/concatenatedoperation.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/coordinateoperationfactory.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/conversion.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/esriparammappings.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/oputils.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/parammappings.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/projbasedoperation.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/singleoperation.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/transformation.cpp
+    ${PROJ_SOURCE_DIR}/src/iso19111/operation/vectorofvaluesparams.cpp
+  )
+
+  set(SRC_LIBPROJ_CORE
+    ${PROJ_SOURCE_DIR}/src/4D_api.cpp
+    ${PROJ_SOURCE_DIR}/src/aasincos.cpp
+    ${PROJ_SOURCE_DIR}/src/adjlon.cpp
+    ${PROJ_SOURCE_DIR}/src/auth.cpp
+    ${PROJ_SOURCE_DIR}/src/ctx.cpp
+    ${PROJ_SOURCE_DIR}/src/datum_set.cpp
+    ${PROJ_SOURCE_DIR}/src/datums.cpp
+    ${PROJ_SOURCE_DIR}/src/deriv.cpp
+    ${PROJ_SOURCE_DIR}/src/dmstor.cpp
+    ${PROJ_SOURCE_DIR}/src/ell_set.cpp
+    ${PROJ_SOURCE_DIR}/src/ellps.cpp
+    ${PROJ_SOURCE_DIR}/src/factors.cpp
+    ${PROJ_SOURCE_DIR}/src/fwd.cpp
+    ${PROJ_SOURCE_DIR}/src/gauss.cpp
+    ${PROJ_SOURCE_DIR}/src/generic_inverse.cpp
+    ${PROJ_SOURCE_DIR}/src/geodesic.c
+    ${PROJ_SOURCE_DIR}/src/init.cpp
+    ${PROJ_SOURCE_DIR}/src/initcache.cpp
+    ${PROJ_SOURCE_DIR}/src/internal.cpp
+    ${PROJ_SOURCE_DIR}/src/inv.cpp
+    ${PROJ_SOURCE_DIR}/src/list.cpp
+    ${PROJ_SOURCE_DIR}/src/log.cpp
+    ${PROJ_SOURCE_DIR}/src/malloc.cpp
+    ${PROJ_SOURCE_DIR}/src/mlfn.cpp
+    ${PROJ_SOURCE_DIR}/src/msfn.cpp
+    ${PROJ_SOURCE_DIR}/src/mutex.cpp
+    ${PROJ_SOURCE_DIR}/src/param.cpp
+    ${PROJ_SOURCE_DIR}/src/phi2.cpp
+    ${PROJ_SOURCE_DIR}/src/pipeline.cpp
+    ${PROJ_SOURCE_DIR}/src/pj_list.h
+    ${PROJ_SOURCE_DIR}/src/pr_list.cpp
+    ${PROJ_SOURCE_DIR}/src/proj_internal.h
+    ${PROJ_SOURCE_DIR}/src/proj_mdist.cpp
+    ${PROJ_SOURCE_DIR}/src/qsfn.cpp
+    ${PROJ_SOURCE_DIR}/src/release.cpp
+    ${PROJ_SOURCE_DIR}/src/rtodms.cpp
+    ${PROJ_SOURCE_DIR}/src/strerrno.cpp
+    ${PROJ_SOURCE_DIR}/src/strtod.cpp
+    ${PROJ_SOURCE_DIR}/src/tsfn.cpp
+    ${PROJ_SOURCE_DIR}/src/units.cpp
+    ${PROJ_SOURCE_DIR}/src/wkt1_generated_parser.c
+    ${PROJ_SOURCE_DIR}/src/wkt1_generated_parser.h
+    ${PROJ_SOURCE_DIR}/src/wkt1_parser.cpp
+    ${PROJ_SOURCE_DIR}/src/wkt1_parser.h
+    ${PROJ_SOURCE_DIR}/src/wkt2_generated_parser.c
+    ${PROJ_SOURCE_DIR}/src/wkt2_generated_parser.h
+    ${PROJ_SOURCE_DIR}/src/wkt2_parser.cpp
+    ${PROJ_SOURCE_DIR}/src/wkt2_parser.h
+    ${PROJ_SOURCE_DIR}/src/wkt_parser.cpp
+    ${PROJ_SOURCE_DIR}/src/wkt_parser.hpp
+    ${PROJ_SOURCE_DIR}/src/zpoly1.cpp
+    ${PROJ_SOURCE_DIR}/src/proj_json_streaming_writer.hpp
+    ${PROJ_SOURCE_DIR}/src/proj_json_streaming_writer.cpp
+    ${PROJ_SOURCE_DIR}/src/tracing.cpp
+    ${PROJ_SOURCE_DIR}/src/grids.hpp
+    ${PROJ_SOURCE_DIR}/src/grids.cpp
+    ${PROJ_SOURCE_DIR}/src/filemanager.hpp
+    ${PROJ_SOURCE_DIR}/src/filemanager.cpp
+    ${PROJ_SOURCE_DIR}/src/networkfilemanager.cpp
+    ${PROJ_SOURCE_DIR}/src/sqlite3_utils.hpp
+    ${PROJ_SOURCE_DIR}/src/sqlite3_utils.cpp
+    ${PROJ_SOURCE_DIR}/src/proj_config.h
+  )
+
+  set(HEADERS_LIBPROJ
+    ${PROJ_SOURCE_DIR}/src/proj.h
+    ${PROJ_SOURCE_DIR}/src/proj_experimental.h
+    ${PROJ_SOURCE_DIR}/src/proj_constants.h
+    ${PROJ_SOURCE_DIR}/src/proj_symbol_rename.h
+    ${PROJ_SOURCE_DIR}/src/geodesic.h
+  )
+
+  # Group source files for IDE source explorers (e.g. Visual Studio)
+  source_group("Header Files"
+    FILES ${HEADERS_LIBPROJ})
+  source_group("Source Files\\Core"
+    FILES ${SRC_LIBPROJ_CORE})
+  source_group("Source Files\\Conversions"
+    FILES ${SRC_LIBPROJ_CONVERSIONS})
+  source_group("Source Files\\Projections"
+    FILES ${SRC_LIBPROJ_PROJECTIONS})
+  source_group("Source Files\\Transformations"
+    FILES ${SRC_LIBPROJ_TRANSFORMATIONS})
+  source_group("Source Files\\ISO19111"
+    FILES ${SRC_LIBPROJ_ISO19111})
+
+  include_directories(${PROJ_SOURCE_DIR}/include)
+
+  include_directories(${CMAKE_CURRENT_BINARY_DIR})
+  source_group("CMake Files" FILES CMakeLists.txt)
+
+  # Embed PROJ_DATA data files location
+  add_definitions(-DPROJ_DATA="${PROJ_DATA_PATH}")
+
+
+  ###########################################################
+  # targets to refresh wkt1_parser.cpp and wkt2_parser.cpp
+  ###########################################################
+
+  # Those targets need to be run manually each time wkt1_grammar.y / wkt2_grammar.y
+  # is modified.
+  # We could of course run them automatically, but that would make building
+  # PROJ harder.
+
+  # This target checks that wkt1_grammar.y md5sum has not changed
+  # If it has, then it should be updated and the generate_wkt1_parser target
+  # should be manually run
+  add_custom_target(check_wkt1_grammar_md5 ALL
+                    COMMAND ${CMAKE_COMMAND}
+                        "-DIN_FILE=wkt1_grammar.y"
+                        "-DTARGET=generate_wkt1_parser"
+                        "-DEXPECTED_MD5SUM=5b4495c1ec6d2ae26b7028a9bb5d8819"
+                        -P "${PROJ_SOURCE_DIR}/src/check_md5sum.cmake"
+                    WORKING_DIRECTORY "${PROJ_SOURCE_DIR}/src"
+                    DEPENDS "${PROJ_SOURCE_DIR}/src/wkt1_grammar.y"
+                    VERBATIM)
+
+  add_custom_target(generate_wkt1_parser
+                    COMMAND ${CMAKE_COMMAND}
+                        "-DPREFIX=pj_wkt1_"
+                        "-DIN_FILE=wkt1_grammar.y"
+                        "-DOUT_FILE=wkt1_generated_parser.c"
+                        -P "${PROJ_SOURCE_DIR}/src/generate_wkt_parser.cmake"
+                    WORKING_DIRECTORY "${PROJ_SOURCE_DIR}/src"
+                    VERBATIM)
+
+  # This target checks that wkt2_grammar.y md5sum has not changed
+  # If it has, then it should be updated and the generate_wkt2_parser target
+  # should be manually run
+  add_custom_target(check_wkt2_grammar_md5 ALL
+                    COMMAND ${CMAKE_COMMAND}
+                        "-DIN_FILE=wkt2_grammar.y"
+                        "-DTARGET=generate_wkt2_parser"
+                        "-DEXPECTED_MD5SUM=289572eebe9dab3c7225bd48c445c287"
+                        -P "${PROJ_SOURCE_DIR}/src/check_md5sum.cmake"
+                    WORKING_DIRECTORY "${PROJ_SOURCE_DIR}/src"
+                    DEPENDS "${PROJ_SOURCE_DIR}/src/wkt2_grammar.y"
+                    VERBATIM)
+
+  add_custom_target(generate_wkt2_parser
+                    COMMAND ${CMAKE_COMMAND}
+                        "-DPREFIX=pj_wkt2_"
+                        "-DIN_FILE=wkt2_grammar.y"
+                        "-DOUT_FILE=wkt2_generated_parser.c"
+                        -P "${PROJ_SOURCE_DIR}/src/generate_wkt_parser.cmake"
+                    WORKING_DIRECTORY "${PROJ_SOURCE_DIR}/src"
+                    VERBATIM)
+
+  #################################################
+  ## targets: libproj and proj_config.h
+  #################################################
+  set(ALL_LIBPROJ_SOURCES
+    ${SRC_LIBPROJ_CORE}
+    ${SRC_LIBPROJ_CONVERSIONS}
+    ${SRC_LIBPROJ_PROJECTIONS}
+    ${SRC_LIBPROJ_TRANSFORMATIONS}
+    ${SRC_LIBPROJ_ISO19111}
+  )
+  set(ALL_LIBPROJ_HEADERS ${HEADERS_LIBPROJ})
+
+  # Configuration for the core target "proj"
+  proj_target_output_name(proj PROJ_CORE_TARGET_OUTPUT_NAME)
+
+  add_library(proj OBJECT
+    ${ALL_LIBPROJ_SOURCES}
+    ${ALL_LIBPROJ_HEADERS}
+    ${PROJ_RESOURCES}
+  )
+  add_library(PROJ::proj ALIAS proj)
+
+  if(MSVC OR MINGW)
+      target_compile_definitions(proj PRIVATE -DNOMINMAX)
+  endif()
+
+  # Tell Intel compiler to do arithmetic accurately.  This is needed to stop the
+  # compiler from ignoring parentheses in expressions like (a + b) + c and from
+  # simplifying 0.0 + x to x (which is wrong if x = -0.0).
+  if("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
+    if(MSVC)
+      set(FP_PRECISE "/fp:precise")
+    else()
+      set(FP_PRECISE "-fp-model precise")
+    endif()
+    # Apply to source files that require this option
+    set_source_files_properties(
+      geodesic.c
+      PROPERTIES COMPILE_FLAGS ${FP_PRECISE})
+  endif()
+
+  if(ENABLE_IPO)
+    set_property(TARGET proj
+      PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
+  endif()
+
+  target_include_directories(proj INTERFACE
+    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+    $<BUILD_INTERFACE:${PROJ_SOURCE_DIR}/include>
+    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+
+  if(WIN32)
+    set_target_properties(proj
+      PROPERTIES
+      VERSION "${PROJ_VERSION}"
+      OUTPUT_NAME "${PROJ_CORE_TARGET_OUTPUT_NAME}"
+      ARCHIVE_OUTPUT_NAME proj
+      CLEAN_DIRECT_OUTPUT 1)
+  elseif(BUILD_FRAMEWORKS_AND_BUNDLE)
+    set_target_properties(proj
+      PROPERTIES
+      VERSION "${PROJ_VERSION}"
+      INSTALL_NAME_DIR ${PROJ_INSTALL_NAME_DIR}
+      CLEAN_DIRECT_OUTPUT 1)
+  else()
+    set_target_properties(proj
+      PROPERTIES
+      VERSION "${PROJ_BUILD_VERSION}"
+      SOVERSION "${PROJ_SOVERSION}"
+      CLEAN_DIRECT_OUTPUT 1)
+  endif()
+
+  set_target_properties(proj
+    PROPERTIES
+    LINKER_LANGUAGE CXX)
+
+  ##############################################
+  # Link properties
+  ##############################################
+  set(PROJ_LIBRARIES proj)
+  if(UNIX)
+    find_library(M_LIB m)
+    if(M_LIB)
+      target_link_libraries(proj PRIVATE -lm)
+    endif()
+    find_library(DL_LIB dl)
+    if(DL_LIB)
+      target_link_libraries(proj PRIVATE -ldl)
+    endif()
+  endif()
+  if(Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
+    target_link_libraries(proj PRIVATE ${CMAKE_THREAD_LIBS_INIT})
+  endif()
+
+  target_include_directories(proj PRIVATE ${SQLITE3_INCLUDE_DIR})
+  target_link_libraries(proj PRIVATE ${SQLITE3_LIBRARY})
+
+  if(NLOHMANN_JSON STREQUAL "external")
+    target_compile_definitions(proj PRIVATE EXTERNAL_NLOHMANN_JSON)
+    target_link_libraries(proj
+      PRIVATE $<BUILD_INTERFACE:nlohmann_json::nlohmann_json>)
+  endif()
+
+  if(BUILD_SHARED_LIBS)
+    if(MSVC)
+      target_compile_definitions(proj PRIVATE PROJ_MSVC_DLL_EXPORT=1)
+    endif()
+  else()
+    target_compile_definitions(proj PUBLIC PROJ_DLL=)
+  endif()
+
+  ##############################################
+  # Core configuration summary
+  ##############################################
+  print_variable(PROJ_CORE_TARGET_OUTPUT_NAME)
+  print_variable(BUILD_SHARED_LIBS)
+  print_variable(PROJ_LIBRARIES)
+
+  set(PROJ_TARGET proj)
+  set(PROJ_INCLUDE_DIR /PROJ)
+
   # Nlohmann JSON
-  # Use the Nlohmann JSON version embedded in ALE
+  set(JSON_BuildTests OFF CACHE INTERNAL "")
+  add_subdirectory(json)
 
   # ALE
-  set(ALE_USE_EXTERNAL_EIGEN OFF)
-  set(ALE_USE_EXTERNAL_JSON OFF)
-  set(ALE_BUILD_LOAD OFF)
-  set(ALE_BUILD_TESTS OFF)
-  set(ALE_BUILD_DOCS OFF)
-  add_subdirectory(ale)
-  set(ALE_TARGET ale)
-
   # Use Eigen included with ALE
+  add_library (eigen INTERFACE)
   add_library (Eigen3::Eigen ALIAS eigen)
+  target_include_directories (eigen INTERFACE
+    ${CMAKE_CURRENT_SOURCE_DIR}/ale/eigen)
   set(EIGEN3_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ale/eigen)
-endif(USGSCSM_EXTERNAL_DEPS)
 
-# Proj
-find_package(PROJ REQUIRED CONFIG)
-set(PROJ_TARGET PROJ::proj)
-
-add_library(usgscsm SHARED
-            src/UsgsAstroPlugin.cpp
-            src/UsgsAstroPluginSupport.cpp
-            src/UsgsAstroFrameSensorModel.cpp
-            src/UsgsAstroPushFrameSensorModel.cpp
-            src/UsgsAstroLsSensorModel.cpp
-            src/UsgsAstroProjectedSensorModel.cpp
-            src/UsgsAstroSarSensorModel.cpp
-            src/Distortion.cpp
-            src/Utilities.cpp
-            src/EigenUtilities.cpp)
+  set(ALE_BUILD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ale/include/ale")
+
+  set(ALE_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ale/src/InterpUtils.cpp
+                       ${CMAKE_CURRENT_SOURCE_DIR}/ale/src/Rotation.cpp
+                       ${CMAKE_CURRENT_SOURCE_DIR}/ale/src/Orientations.cpp
+                       ${CMAKE_CURRENT_SOURCE_DIR}/ale/src/States.cpp
+                       ${CMAKE_CURRENT_SOURCE_DIR}/ale/src/Util.cpp
+                       ${CMAKE_CURRENT_SOURCE_DIR}/ale/src/Vectors.cpp)
+
+  add_library(ale OBJECT ${ALE_SOURCE_FILES})
+  set(ALE_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/ale/include/ale/")
+
+  target_include_directories(ale
+                            PUBLIC
+                            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ale/include>
+                            $<INSTALL_INTERFACE:include>
+                            PRIVATE)
+
+  target_include_directories(ale
+                             PRIVATE
+                             ${ALE_INCLUDE_DIRS}
+  )
+  set(ALE_LINKS nlohmann_json::nlohmann_json
+                Eigen3::Eigen
+  )
+  target_link_libraries(ale PRIVATE ${ALE_LINKS})
+  set(ALE_TARGET ale)
+  set(USGSCSM_INCLUDE_DIRS "${USGSCSM_INCLUDE_DIRS}"
+                           "${CMAKE_CURRENT_SOURCE_DIR}/ale/include"
+                           "${CMAKE_CURRENT_SOURCE_DIR}/PROJ/include"
+  )
+  
+  set( CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -fPIC" )
+  set( CMAKE_C_FLAGS  "${CMAKE_C_FLAGS} -fPIC" )
+
+  add_library(usgscsm SHARED ${USGSCSM_SRC_FILES}
+                             $<TARGET_OBJECTS:ale>
+  )
+endif(USGSCSM_EXTERNAL_DEPS)
 
 set_target_properties(usgscsm PROPERTIES
     VERSION ${PROJECT_VERSION}
     SOVERSION 1
 )
-set(USGSCSM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include/usgscsm"
-                         "${CMAKE_CURRENT_SOURCE_DIR}/include"
-                         "${CMAKE_CURRENT_SOURCE_DIR}"
+set(USGSCSM_INCLUDE_DIRS "${USGSCSM_INCLUDE_DIRS}"
                          "${EIGEN3_INCLUDE_DIR}"
                          "${PROJ_INCLUDE_DIR}")
 
diff --git a/PROJ b/PROJ
new file mode 160000
index 0000000..fde3d58
--- /dev/null
+++ b/PROJ
@@ -0,0 +1 @@
+Subproject commit fde3d58e4af51f8e6c9cafeeb2b0299ab1218d91
diff --git a/ale b/ale
index a7d8a14..775ff21 160000
--- a/ale
+++ b/ale
@@ -1 +1 @@
-Subproject commit a7d8a148f54d5141c63ed45a24a71c890ca11de7
+Subproject commit 775ff216791349f44a643a1080818631f6b7b16e
diff --git a/csm b/csm
index c78dbba..cbf62f4 160000
--- a/csm
+++ b/csm
@@ -1 +1 @@
-Subproject commit c78dbba3731432249a75db9fdd7415b292d46715
+Subproject commit cbf62f4f489567ae05ae9c0f373f14f9062cbecb
diff --git a/json b/json
index 1a521cb..5d27543 160000
--- a/json
+++ b/json
@@ -1 +1 @@
-Subproject commit 1a521cbd3657eea6ba90cded2aecca93e3cd78d4
+Subproject commit 5d2754306d67d1e654a1a34e1d2e74439a9d53b3
diff --git a/recipe/build.sh b/recipe/build.sh
index 76ac500..3419082 100644
--- a/recipe/build.sh
+++ b/recipe/build.sh
@@ -1,4 +1,5 @@
 #!/bin/sh
+git submodule update --init
 mkdir build && cd build
-cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX -DUSGSCSM_EXTERNAL_DEPS=ON -DBUILD_TESTS=OFF ..
+cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX -DUSGSCSM_EXTERNAL_DEPS=OFF -DUSGSCSM_BUILD_DOCS=OFF -DUSGSCSM_BUILD_TESTS=OFF ..
 make install
diff --git a/recipe/meta.yaml b/recipe/meta.yaml
index fcc7f2e..fc9858b 100644
--- a/recipe/meta.yaml
+++ b/recipe/meta.yaml
@@ -1,30 +1,39 @@
 
+{% set name = "usgscsm" %}
+{% set version = "main" %}
+
 package:
-  name: usgscsm
-  version: {{ environ.get("GIT_DESCRIBE_TAG", "") }}
+  name: {{ name|lower }}
+  version: {{ version }}
 
 source:
-  git_url: https://github.com/USGS-Astrogeology/CSM-CameraModel.git
+  git_url: 'https://github.com/DOI-USGS/usgscsm.git'
+  git_tag: {{ version }}
+
 build:
-  string: {{ environ.get("GIT_DESCRIBE_HASH", "") }}
+  number: 0
+  skip: true  # [win]
+
 
 requirements:
   build:
-    - {{ compiler('cxx') }}  # [linux]
-    - vc 14  # [win]
+    - {{ compiler('cxx') }}
     - cmake >=3.10
-    - libcsm
-    - vc 14  # [win]
-  run:
+    - make
+    - nlohmann_json
+    - eigen
+  host:
+    - csm
     - vc  # [win]
+  run:
+    - csm
 
 test:
   commands:
-    - test -e $PREFIX/lib/libusgscsm.so  # [linux]
-    - test -e $PREFIX/lib/libusgscsm.dylib  # [osx]
+    - test -e $PREFIX/lib/csmplugins/libusgscsm${SHLIB_EXT}  # [unix]
     - if not exist %LIBRARY_BIN%\usgscsm.dll exit 1  # [win]
 
 about:
-  home: https://github.com/USGS-Astrogeology/CSM-CameraModels
+  home: https://github.com/DOI-USGS/usgscsm
   license: None
 summary: "USGS Astrogeology Community Sensor Model compliant sensor models."
-- 
GitLab