CMake error on adding package? Any way to fix?

I have been able to add a number of packages to my testserver project with no issues. I would like to also add the H3 package here:

However, when I add that to my dependencies and run iex -S mix phx.server or mix deps.compile h3 I get:

CMake Deprecation Warning at CMakeLists.txt:4 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19044.
CMake Error at cmake/ASan.cmake:8 (set_property):
  set_property could not find CACHE variable CMAKE_BUILD_TYPE.  Perhaps it
  has not yet been created.
Call Stack (most recent call first):
  CMakeLists.txt:10 (include)


-- Configuring incomplete, errors occurred!
===> Hook for compile failed!

** (Mix) Could not compile dependency :h3, "escript.exe "c:/Users/Mike/.mix/elixir/1-14/rebar3" bare compile --paths h:/filePath/testserver/_build/dev/lib/*/ebin" command failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile h3", update it with "mix deps.update h3" or clean it with "mix deps.clean h3"

I have confirmed c:/Users/Mike/.mix/elixir/1-14/rebar3 does in fact exist.

Is there any obvious way to fix this? Or to figure out more precisely the issue? The package is from 2020, so maybe there is just something inside it I might need to update?

Thanks for any help.

If the library hasn’t been updated in a while and it has native dependencies + even deprecation warnings then your chances are not good I am afraid.

What does h3 do? A quick glance didn’t give me an answer. It is an option to replace it I’d reckon.

1 Like

@dimitarvp H3 is Uber’s hexagonal global spatialization library which they made open source:

https://www.uber.com/en-CA/blog/h3/

https://github.com/uber/h3

People have adapted it into many languages. There are easily available working C# versions I have tested and it was formally released with JavaScript support. At some point soon I will need a working Elixir implementation.

If you think I might have to do it myself, any pointers for someone who knows virtually nothing about coding Elixir? :joy: Maybe I will have to pay someone to fix it? I dunno.

Edit: I just looked again and there is another version here: GitHub - helium/erlang-h3: Erlang binding for Uber's H3 spatial coordinate library I will try to build that from the instructions there. Thanks.

Hope you make the alternative work.

Looking at Bindings | H3, I’d just choose one of the Rust libraries and then use rustler to bind to it. Should be a much smoother ride with less surprises.

As for paying people, sure. Maybe there will be takers for a C/C++ project managed by cmake but again, I’d put my chips on Rust if I were you.

1 Like

Oh, only one of them is actually a direct translation without the underlying C/C++ dependency: GitHub - HydroniumLabs/h3o: Rust implementation of the H3 geospatial indexing system.

Then I’d start there.

1 Like

I find it absolutely hilarious (in a good way) that this forum is the complete 100% antithesis of StackOverflow. :joy::beers:

I am so used to just not asking programming questions of any kind and suffering in silence to figure things out because there is no point even asking anything on StackOverflow these days. GitHub discussion pages are usually dead. Rarely, if you can find a Discord server for a particular niche that can be good.

Anyway, thanks for being nice and helpful. Even small answers like, “It’s probably going to be a mess trying to fix that thing,” can save a person a lot of wasted time.

Hey @dimitarvp. I tried building the erlang h3 version here by downloading it, going in the folder and running “make” but I got the same error as the Hex H3 (likely the same build then):

./rebar3 compile
===> Verifying dependencies...
-- Building for: Visual Studio 17 2022
CMake Deprecation Warning at CMakeLists.txt:4 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.38.33130.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at cmake/ASan.cmake:8 (set_property):
  set_property could not find CACHE variable CMAKE_BUILD_TYPE.  Perhaps it
  has not yet been created.
Call Stack (most recent call first):
  CMakeLists.txt:10 (include)


-- Found Erlang: c:/Program Files/Erlang OTP/erts-13.1.2/include
-- Found Git: C:/Program Files/Git/mingw64/bin/git.exe (found version "2.38.1.windows.1")
fatal: not a git repository (or any of the parent directories): .git
CMake Warning at cmake/FindH3.cmake:21 (message):
  could not get erlang-h3 tag, falling back on hard-coded version
Call Stack (most recent call first):
  CMakeLists.txt:92 (find_package)


-- Using upstream h3 tag v3.6.4 based on local tag v3.6.4
-- Configuring incomplete, errors occurred!
===> Hook for compile failed!

make: *** [Makefile:6: compile] Error 1

In terms of the problems, to break this down, it seems only #2 is a true error but to review it all:

1) Deprecation warning

This comes from the line in CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)

Presumably, I can just increase this to 3.5. I did that and the deprecation warning resolved without new issues.

2) Asan.cmake Error

This file Asan.cmake contains only the following, with line 8 being the last one that is throwing the error that seems to be breaking the build:

# This file provides a custom build type, `CMAKE_BUILD_TYPE_ASAN`

set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_RELWITHDEBINFO} -fsanitize=address -fno-omit-frame-pointer -fno-common" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_ASAN "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fsanitize=address -fno-omit-frame-pointer -fno-common" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_ASAN "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} -fsanitize=address" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_ASAN "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} -fsanitize=address" CACHE STRING "" FORCE)

set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" "ASan")

There is obviously a problem with this set_property line. Any idea what it is or how to fix it?

CMakeLists.txt line 10 is the last here:

cmake_minimum_required(VERSION 3.5)
project(ErlangH3 C)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 99)

list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
include(ASan)

3) .git Message

I am not sure if this is meaningful? I am not sure what it is trying to say.

4) Could not get erlang-h3 tag

This derives from FindH3.cmake:

# Use this repo's semantic version as the tag to fetch from up
# upstream uber/h3
find_package(Git REQUIRED)
execute_process(COMMAND
  ${GIT_EXECUTABLE} describe --tags
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  RESULT_VARIABLE GIT_SUCCESS
  OUTPUT_VARIABLE ERLANG_H3_TAG
  )
if(NOT GIT_SUCCESS EQUAL "0")
  message(WARNING "could not get erlang-h3 tag, falling back on hard-coded version")
  set(ERLANG_H3_TAG "v3.6.4")
endif()
string(REGEX REPLACE "\n$" "" ERLANG_H3_TAG "${ERLANG_H3_TAG}")
string(REGEX MATCH "^v[0-9]+\.[0-9]+\.[0-9]+" UPSTREAM_H3_GIT_TAG "${ERLANG_H3_TAG}")
message(STATUS "Using upstream h3 tag ${UPSTREAM_H3_GIT_TAG} based on local tag ${ERLANG_H3_TAG}")

Again is there any likely significance to this?

Any thoughts or ideas on how to solve #2 in particular which is what seems to be breaking it? Thanks.

It has been a very long time since I last dealt with C/C++ and CMake so I can’t help you, I am afraid. Even if I wanted to, it would take time, time that I don’t have much of.

I’d again advise you to just go with the Rust dependency, it’s much easier and transparent to work with Rust + the Elixir<=>Rust bridge called rustler.

I and others can help you with it, but if you really want help with the C/++ and CMake problems then I am not your guy. :zipper_mouth_face: