From 06db3fb4d2e3f0b981282a9b259997a66825f97c Mon Sep 17 00:00:00 2001 From: Jesse Mapel <jmapel@usgs.gov> Date: Wed, 15 Jul 2020 13:35:55 -0700 Subject: [PATCH] Updating build to allow for building all dependencies (#296) * Testing new build * Now with 100% more lib files * Typo fix * Added ALE artifact to CI --- .appveyor.yml | 4 +++- .gitmodules | 6 +++++ .travis.yml | 7 +++--- CMakeLists.txt | 58 +++++++++++++++++++++++++++++++------------------ ale | 1 + environment.yml | 10 +++++++++ json | 1 + recipe/bld.bat | 4 ++-- recipe/build.sh | 2 +- 9 files changed, 64 insertions(+), 29 deletions(-) create mode 160000 ale create mode 100644 environment.yml create mode 160000 json diff --git a/.appveyor.yml b/.appveyor.yml index 9ceadd9..a41c854 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -22,12 +22,14 @@ before_build: - cd build build_script: - - cmake -G "Visual Studio 15 2017 Win64" -DUSGSCSM_BUILD_TESTS=OFF .. + - cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON -DUSGSCSM_BUILD_TESTS=OFF .. - cmake --build . --target ALL_BUILD --config Release artifacts: - path: build\Release\usgscsm.dll name: usgscsm.dll + - path: build\Release\ale.dll + name: ale.dll on_success: - cd ../ diff --git a/.gitmodules b/.gitmodules index 23bb6ea..a317047 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,9 @@ [submodule "csm"] path = csm url = https://github.com/USGS-Astrogeology/csm +[submodule "ale"] + path = ale + url = https://github.com/USGS-Astrogeology/ale.git +[submodule "json"] + path = json + url = https://github.com/nlohmann/json.git diff --git a/.travis.yml b/.travis.yml index be180a2..258784e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,14 +39,13 @@ install: fi - bash miniconda.sh -b -p $HOME/miniconda - source $HOME/miniconda/etc/profile.d/conda.sh - - conda install -y -c conda-forge cmake ale nlohmann_json + - conda env create -n usgscsm -f environment.yml script: - - conda activate - - ls $CONDA_PREFIX/include/ale + - conda activate usgscsm - mkdir build - cd build - - cmake -DCOVERAGE=ON .. + - cmake -DUSGSCSM_EXTERNAL_DEPS=ON -DCOVERAGE=ON .. - cmake --build . - ctest -VV - cd .. diff --git a/CMakeLists.txt b/CMakeLists.txt index cbc9092..492a290 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,24 +13,43 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) STRING "Choose the type of build." FORCE) endif() -# Optional build or link against CSM -option (BUILD_CSM "Build the CSM library" ON) -if(BUILD_CSM) +# Use external or embedded dependencies +option(USGSCSM_EXTERNAL_DEPS "If the library should be built with external or embedded dependencies" OFF) + +if(USGSCSM_EXTERNAL_DEPS) + # CSM API library + find_path(CSM_INCLUDE_DIR NAMES "csm.h" + PATH_SUFFIXES "csm" + PATHS $ENV{CONDA_PREFIX}/include/) + find_library(CSM_LIBRARY csmapi PATHS $ENV{CONDA_PREFIX}/lib) + message("--Found external CSM Library: ${CSM_LIBRARY}") + message("--Found external CSM Include Directory: ${CSM_INCLUDE_DIR}") + + # Nlohmann JSON + find_package(nlohmann_json REQUIRED) + + # ALE + find_package(ale REQUIRED) + set(ALE_TARGET ale::ale) +else() + # CSM API library add_subdirectory(csm) set(CSM_INCLUDE_DIR /csm) set(CSM_LIBRARY csmapi) -else() - find_path(CSM_INCLUDE_DIR NAMES "csm.h" - PATH_SUFFIXES "csm" - PATHS $ENV{CONDA_PREFIX}/include/) - find_library(CSM_LIBRARY csmapi PATHS $ENV{CONDA_PREFIX}/lib) - message("--Found CSM Library: ${CSM_LIBRARY}") - message("--Found CSM Include Directory: ${CSM_INCLUDE_DIR}") -endif(BUILD_CSM) + # Nlohmann JSON + set(JSON_BuildTests OFF CACHE INTERNAL "") + add_subdirectory(json) + + # ALE + set(ALE_USE_EXTERNAL_EIGEN OFF) + set(ALE_USE_EXTERNAL_JSON ON) + set(ALE_BUILD_LOAD OFF) + set(ALE_BUILD_TESTS OFF) + add_subdirectory(ale) + set(ALE_TARGET ale) +endif(USGSCSM_EXTERNAL_DEPS) -find_package(nlohmann_json REQUIRED) -find_package(ale REQUIRED) add_library(usgscsm SHARED src/UsgsAstroPlugin.cpp @@ -38,7 +57,7 @@ add_library(usgscsm SHARED src/UsgsAstroLsSensorModel.cpp src/UsgsAstroSarSensorModel.cpp src/Distortion.cpp - src/Utilities.cpp) + src/Utilities.cpp) set_target_properties(usgscsm PROPERTIES VERSION ${PROJECT_VERSION} @@ -56,18 +75,15 @@ target_include_directories(usgscsm target_link_libraries(usgscsm ${CSM_LIBRARY} - ale::ale + ${ALE_TARGET} nlohmann_json::nlohmann_json) -if(WIN32) - install(TARGETS usgscsm RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}) -else() - install(TARGETS usgscsm LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) -endif() + +install(TARGETS usgscsm LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(DIRECTORY ${USGSCSM_INCLUDE_DIRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -# Optional build or link against CSM +# Optional build tests option (USGSCSM_BUILD_TESTS "Build tests" ON) if(USGSCSM_BUILD_TESTS) diff --git a/ale b/ale new file mode 160000 index 0000000..37bb560 --- /dev/null +++ b/ale @@ -0,0 +1 @@ +Subproject commit 37bb560ac6a5327063f6c36d8259b3dbb6880bab diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..6709a92 --- /dev/null +++ b/environment.yml @@ -0,0 +1,10 @@ +name: usgscsm +channels: + - conda-forge + - default + +dependencies: + - cmake>=3.12 + - ale + - csm + - nlohmann_json diff --git a/json b/json new file mode 160000 index 0000000..1a521cb --- /dev/null +++ b/json @@ -0,0 +1 @@ +Subproject commit 1a521cbd3657eea6ba90cded2aecca93e3cd78d4 diff --git a/recipe/bld.bat b/recipe/bld.bat index 04c8729..f2eae36 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -1,7 +1,7 @@ mkdir build cd build -cmake -G "Visual Studio 15 2017 Win64" -DBUILD_TESTS=OFF .. +cmake -G "Visual Studio 15 2017 Win64" -DUSGSCSM_EXTERNAL_DEPS=ON -DBUILD_TESTS=OFF .. cmake --build . --target ALL_BUILD --config Release copy Release\usgscsm.dll %LIBRARY_BIN% -if errorlevel 1 exit 1 +if errorlevel 1 exit 1 diff --git a/recipe/build.sh b/recipe/build.sh index 257773c..76ac500 100644 --- a/recipe/build.sh +++ b/recipe/build.sh @@ -1,4 +1,4 @@ #!/bin/sh mkdir build && cd build -cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX -DBUILD_CSM=OFF -DBUILD_TESTS=OFF .. +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX -DUSGSCSM_EXTERNAL_DEPS=ON -DBUILD_TESTS=OFF .. make install -- GitLab