samedi 28 janvier 2017

Activating C++ 11 in CMake introduces error for swig

I can't find what is going on. There are two versions of a CMakeLists.txt

(1)

cmake_minimum_required (VERSION 2.8)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
project (libplump)

find_package(Boost 1.35.0 REQUIRED COMPONENTS program_options serialization iostreams filesystem system)

find_package(GSL REQUIRED)

include_directories ("${PROJECT_SOURCE_DIR}/src")
include_directories ("${PROJECT_SOURCE_DIR}/src/utils")
add_subdirectory(src/libplump)
add_subdirectory(bindings)

add_executable(score_file src/utils/score_file.cc)
target_link_libraries(score_file plump ${Boost_LIBRARIES} ${GSL_LIBRARIES})

(2)

cmake_minimum_required (VERSION 2.8)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

project (libplump CXX)

if (CMAKE_VERSION VERSION_LESS "3.1")
  if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    set (CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}")
  endif ()
else ()
  set (CMAKE_CXX_STANDARD 11)
endif ()

find_package(Boost 1.35.0 REQUIRED COMPONENTS program_options serialization iostreams filesystem system)
find_package(GSL REQUIRED)

include_directories ("${PROJECT_SOURCE_DIR}/external/")
include_directories ("${PROJECT_SOURCE_DIR}/src")
include_directories ("${PROJECT_SOURCE_DIR}/src/utils")
add_subdirectory(src/libplump)
add_subdirectory(bindings)

add_executable(score_file src/utils/score_file.cc)
target_link_libraries(score_file plump pthread ${Boost_LIBRARIES} ${GSL_LIBRARIES})

I needed to refine (1) and make it into (2) to add c++11 support to it, as I am linking a header file in the external directory. The code relies on SWIG, and when I make it using (1) it builds fine, but via (2) it gives the following error and stops:

[ 83%] Building CXX object CMakeFiles/score_file.dir/src/utils/score_file.cc.o
Linking CXX executable score_file
[ 83%] Built target score_file
[ 91%] Swig source
/home/PLUMP/src/libplump/context_tree.h:68: Warning 362: operator= ignored
/home/PLUMP/src/libplump/hpyp_parameters.h:223: Error: Syntax error in input(3).
make[2]: *** [bindings/libplumpPYTHON_wrap.cxx] Error 1
make[1]: *** [bindings/CMakeFiles/_libplump.dir/all] Error 2
make: *** [all] Error 2

I assume there must be an issue when setting CXX in the project(libplump CXX) which introduces some sort of incompatibility.

Reproducibility: The original codebase is here, and I want to add this header in the code to measure memory usage. The header file relies in c++11, hence all this trouble!

Aucun commentaire:

Enregistrer un commentaire