简体   繁体   中英

CGAL overwrites CMAKE_BUILD_TYPE=Debug

In my CMake C++ project I am using CGAL. It is installed on my Ubuntu system (version 16.04 LTS) via apt (Package libcgal-dev version 4.7-4).

In my CMakeLists.txt, the CGAL library is included as follows:

find_package(CGAL REQUIRED)
if ( CGAL_FOUND )
  include(${CGAL_USE_FILE})
  include( CGAL_CreateSingleSourceCGALProgram )
endif()

This works fine so far.

The problem comes up when I want to compile in debug mode: I call cmake from my build directory:

cmake -DCMAKE_BUILD_TYPE=Debug ..

However, in the output, cmake says

-- Build type: Release

This seems to be set by this line (35) in /usr/lib/x86_64-linux-gnu/cmake/CGAL/CGALConfig.cmake :

set(CGAL_BUILD_TYPE_INIT "Release" )

But I don't know how to overwrite this. The only thing I found out was that debug is enabled when running the above command twice, which doesn't seem to be the right way.

How can I compile with debug options while using CGAL?

The reason it should be run twice is that the first time, cmake will run the find package script but the second time cmake will cache the set variables and wouldn't actually run the script again. If what you are saying is correct and that script overrides the build type (the symptoms seems like it is) maybe there is a reason they did that (i don't know what might be the reason but you should investigate it). Generally The workaround to your situation may be cache the build type yourself and reset it after find package like this: (again, it can be dangerous, first, make sure it is safe)

set (CACHED_BUILD_TYPE ${CMAKE_BUILD_TYPE})
find_package(CGAL REQUIRED)
if ( CGAL_FOUND )
  include(${CGAL_USE_FILE})
  include( CGAL_CreateSingleSourceCGALProgram )
endif()
set (CMAKE_BUILD_TYPE ${CACHED_BUILD_TYPE})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM