0

I'm trying to add a CMakeLists.txt for this project: https://github.com/gdelugre/literal_ipaddr which is very simple.

This is what I did:

cmake_minimum_required(VERSION 3.5)
project(literal_ipaddr)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_library (literal_ipaddr ipaddr.cc)
set_property(TARGET literal_ipaddr PROPERTY CXX_STANDARD 17)

but I mainly get errors in constexpr token:

/home/user/libopenvpn/literal_ipaddr/ipaddr.h:100:21: error: expected ‘(’ before ‘constexpr’
             else if constexpr ( base == 16 )
                     ^~~~~~~~~
/home/user/libopenvpn/literal_ipaddr/ipaddr.h: In lambda function:
/home/user/libopenvpn/literal_ipaddr/ipaddr.h:327:51: error: expected ‘{’ before ‘constexpr’
             auto remaining_chars = [](size_t pos) constexpr { return N - 1 - pos; };
                                                   ^~~~~~~~~
/home/user/libopenvpn/literal_ipaddr/ipaddr.h: In function ‘constexpr int IPAddr::details::inet6_aton(const char (&)[N], in6_addr&)’:
/home/user/libopenvpn/literal_ipaddr/ipaddr.h:327:51: error: expected ‘,’ or ‘;’ before ‘constexpr’
/home/user/libopenvpn/literal_ipaddr/ipaddr.h: In function ‘constexpr auto IPAddr::inet_pton(const char (&)[N])’:
/home/user/libopenvpn/literal_ipaddr/ipaddr.h:430:12: error: expected ‘(’ before ‘constexpr’
         if constexpr (AddressF == AF_INET ) {

Take a look at the project's Makefile: https://github.com/gdelugre/literal_ipaddr/blob/master/Makefile. The only thing missing is the -Wno-missing-field-initializers. Is it necessary and if so, how to do it in cmake?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • Please try to create a [mcve] of the failing code to show us in the question itself (to make it self-contained). Also, what compiler are you using? What version of it? – Some programmer dude Dec 17 '19 at 18:18
  • 3
    Very likely a compiler version issue. – cplusplusrat Dec 17 '19 at 18:19
  • If your Makefile actually works with that compiler, you can try adding `target_compile_options(literal_ipaddr PUBLIC -Wno-missing-field-initializers)` at the end of your CMake file. – Kevin Dec 17 '19 at 18:20
  • Where's the actual code? I can think of situations where this might occur but only in combination with other things. That's why the site requires an actual (minimal,complete,verifiable) code sample. – Spencer Dec 17 '19 at 18:20
  • 2
    For `set(CMAKE_CXX_STANDARD 17)` and VS2017 you might need a newer version than CMake 3.5. (So, `cmake_minimum_required(VERSION 3.5)` seems over-optimistic to me.) AFAIK, it's CMake 3.10: [SO: How to enable /std:c++17 in VS2017 with CMake](https://stackoverflow.com/a/44964919/7478597) – Scheff's Cat Dec 17 '19 at 18:30
  • 1
    Have you checked [this question](https://stackoverflow.com/questions/51291617/errors-when-using-constexpr-if-expected-before-constexpr) about the similar error message? What version of `gcc` do you use? – Tsyvarev Dec 17 '19 at 23:29

0 Answers0