nanoant / CMakePCHCompiler

CMake precompiled header support via custom PCH compiler extension
MIT License
103 stars 20 forks source link

Setting CMAKE_CXX_STANDARD leads to error #41

Open chronoxor opened 5 years ago

chronoxor commented 5 years ago

Setting CMAKE_CXX_STANDARD leads to error

Minimal CMakeLists.txt example reproducing bug or showing requested feature:

cmake_minimum_required(VERSION 3.0)

# Choose C++ standard
set(CMAKE_CXX_STANDARD 17)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/CMakePCHCompiler)

project(pchtest CXX CXXPCH)

add_library(engine src/engine.cpp src/library.cpp)
target_precompiled_header(engine src/prefix.h)

add_executable(demo src/demo.cpp)
target_link_libraries(demo engine)
target_precompiled_header(demo src/prefix.h REUSE engine)

Leads to error:

CMake Error at /home/user/workspace/CMakePCHCompiler/CMakePCHCompiler.cmake:116 (add_library):
  CXXPCH_STANDARD is set to invalid value '17'
Call Stack (most recent call first):
  CMakeLists.txt:10 (target_precompiled_header)

Additional information

m-7761 commented 5 years ago

There is code that deals with this in the module. I don't know if it neglects 17 exclusively or not off the top of my head. It may hardcode the version numbers. 17 may be newer than CMakePCHCompiler.