diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fe1490b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +sudo: true + +script: + - bash runall.sh diff --git a/PrecompiledHeader.cmake b/PrecompiledHeader.cmake index 1e578d2..d82146c 100644 --- a/PrecompiledHeader.cmake +++ b/PrecompiledHeader.cmake @@ -63,7 +63,14 @@ macro(combine_arguments _variable) set(${_variable} "${_result}") endmacro() -function(export_all_flags _filename) +function(export_all_flags _filename mode) + get_target_property(_target_type ${_target} TYPE) + if(_target_type STREQUAL "EXECUTABLE") + set(_pic "$<$>:-fPIE\n>") + else() + set(_pic "$<$>:-fPIC\n>") + endif() + set(_include_directories "$") set(_compile_definitions "$") set(_compile_flags "$") @@ -72,11 +79,120 @@ function(export_all_flags _filename) set(_compile_definitions "$<$:-D$\n>") set(_compile_flags "$<$:$\n>") set(_compile_options "$<$:$\n>") - file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}${_include_directories}${_compile_flags}${_compile_options}\n") + + set(_standard_check "") + if("${mode}" STREQUAL "CXX") + set(_cxx_standard "$") + set(_cxx_extensions "$") + set(_has_extensions "$,$>") # CXX_EXTENSIONS defaults to true + set(_standard_check "${_standard_check}$<$,$>:${CMAKE_CXX17_STANDARD_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,$>:${CMAKE_CXX14_STANDARD_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,$>:${CMAKE_CXX11_STANDARD_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,$>:${CMAKE_CXX98_STANDARD_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,${_has_extensions}>:${CMAKE_CXX17_EXTENSION_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,${_has_extensions}>:${CMAKE_CXX14_EXTENSION_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,${_has_extensions}>:${CMAKE_CXX11_EXTENSION_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,${_has_extensions}>:${CMAKE_CXX98_EXTENSION_COMPILE_OPTION}>") + endif() + if("${mode}" STREQUAL "C") + set(_c_standard "$") + set(_c_extensions "$") + set(_has_extensions "$,$>") # C_EXTENSIONS defaults to true + set(_standard_check "${_standard_check}$<$,$>:${CMAKE_C11_STANDARD_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,$>:${CMAKE_C99_STANDARD_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,$>:${CMAKE_C90_STANDARD_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,${_has_extensions}>:${CMAKE_C11_EXTENSION_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,${_has_extensions}>:${CMAKE_C99_EXTENSION_COMPILE_OPTION}>") + set(_standard_check "${_standard_check}$<$,${_has_extensions}>:${CMAKE_C90_EXTENSION_COMPILE_OPTION}>") + endif() + set(_standard_check "${_standard_check}\n") + + file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}${_include_directories}${_compile_flags}${_compile_options}${_standard_check}${_pic}\n") +endfunction() + +function (gcc_pch_targets_for_mode _input _pch_path mode) + get_filename_component(_name ${_input} NAME) + set(_pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${_input}") + set(_pch_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/${_target}_${mode}_pch") + set(_pchfile "${_pch_binary_dir}/${_input}") + + string(REGEX MATCH "\.\.[/\\]" _has_parent_access "${_input}") + if( "${_pch_path}" STREQUAL "" AND _has_parent_access) + message(FATAL_ERROR "Precompiled header name contains ../, please specify an outputh path with the PCH_PATH option") + endif() + + if( NOT "${_pch_path}" STREQUAL "" ) + set(_pchfile "${_pch_binary_dir}/${_pch_path}") + endif() + set(_output "${_pch_binary_dir}/${_input}.gch") + if( NOT "${_pch_path}" STREQUAL "" ) + set(_output "${_pch_binary_dir}/${_pch_path}.gch") + endif() + + set(_pch_flags_file "${_pch_binary_dir}/compile_flags.rsp") + export_all_flags("${_pch_flags_file}" ${mode}) + set(_compiler_FLAGS "@${_pch_flags_file}") + add_custom_command( + OUTPUT "${_pchfile}" + COMMAND "${CMAKE_COMMAND}" -E copy "${_pch_header}" "${_pchfile}" + DEPENDS "${_pch_header}" + COMMENT "Updating ${_name} (${mode})") + if("${mode}" STREQUAL "CXX") + add_custom_command( + OUTPUT "${_output}" + COMMAND "${CMAKE_CXX_COMPILER}" ${_compiler_FLAGS} -x c++-header -o "${_output}" "${_pchfile}" + DEPENDS "${_pchfile}" "${_pch_flags_file}" + COMMENT "Precompiling ${_name} for ${_target} (C++)") + endif() + if("${mode}" STREQUAL "C") + add_custom_command( + OUTPUT "${_output}" + COMMAND "${CMAKE_C_COMPILER}" ${_compiler_FLAGS_c} -x c-header -o "${_output}" "${_pchfile}" + DEPENDS "${_pchfile}" "${_pch_flags_file}" + COMMENT "Precompiling ${_name} for ${_target} (C)") + endif() + + set(_extensions "") + if("${mode}" STREQUAL "CXX") + set(_extensions "cc|cxx|cpp") + endif() + if("${mode}" STREQUAL "C") + set(_extensions "c") + endif() + + get_property(_sources TARGET ${_target} PROPERTY SOURCES) + foreach(_source ${_sources}) + set(_pch_compile_flags "") + if(_source MATCHES \\.\(${_extensions}\)$) + get_source_file_property(_pch_compile_flags "${_source}" COMPILE_FLAGS) + if(NOT _pch_compile_flags) + set(_pch_compile_flags) + endif() + separate_arguments(_pch_compile_flags) + list(APPEND _pch_compile_flags -Winvalid-pch) + if(_PCH_FORCEINCLUDE) + list(APPEND _pch_compile_flags -include "${_pchfile}") + else(_PCH_FORCEINCLUDE) + list(APPEND _pch_compile_flags "-I${_pch_binary_dir}") + endif(_PCH_FORCEINCLUDE) + + get_source_file_property(_object_depends "${_source}" OBJECT_DEPENDS) + if(NOT _object_depends) + set(_object_depends) + endif() + list(APPEND _object_depends "${_pchfile}") + list(APPEND _object_depends "${_output}") + + combine_arguments(_pch_compile_flags) + set_source_files_properties(${_source} PROPERTIES + COMPILE_FLAGS "${_pch_compile_flags}" + OBJECT_DEPENDS "${_object_depends}") + endif() + endforeach() endfunction() function(add_precompiled_header _target _input) - cmake_parse_arguments(_PCH "FORCEINCLUDE" "SOURCE_CXX;SOURCE_C" "" ${ARGN}) + cmake_parse_arguments(_PCH "FORCEINCLUDE" "SOURCE_CXX;SOURCE_C;PCH_PATH" "" ${ARGN}) get_filename_component(_input_we ${_input} NAME_WE) if(NOT _PCH_SOURCE_CXX) @@ -147,68 +263,8 @@ function(add_precompiled_header _target _input) endif() endif(MSVC) - if(CMAKE_COMPILER_IS_GNUCXX) - get_filename_component(_name ${_input} NAME) - set(_pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${_input}") - set(_pch_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/${_target}_pch") - set(_pchfile "${_pch_binary_dir}/${_input}") - set(_outdir "${CMAKE_CURRENT_BINARY_DIR}/${_target}_pch/${_name}.gch") - file(MAKE_DIRECTORY "${_outdir}") - set(_output_cxx "${_outdir}/.c++") - set(_output_c "${_outdir}/.c") - - set(_pch_flags_file "${_pch_binary_dir}/compile_flags.rsp") - export_all_flags("${_pch_flags_file}") - set(_compiler_FLAGS "@${_pch_flags_file}") - add_custom_command( - OUTPUT "${_pchfile}" - COMMAND "${CMAKE_COMMAND}" -E copy "${_pch_header}" "${_pchfile}" - DEPENDS "${_pch_header}" - COMMENT "Updating ${_name}") - add_custom_command( - OUTPUT "${_output_cxx}" - COMMAND "${CMAKE_CXX_COMPILER}" ${_compiler_FLAGS} -x c++-header -o "${_output_cxx}" "${_pchfile}" - DEPENDS "${_pchfile}" "${_pch_flags_file}" - COMMENT "Precompiling ${_name} for ${_target} (C++)") - add_custom_command( - OUTPUT "${_output_c}" - COMMAND "${CMAKE_C_COMPILER}" ${_compiler_FLAGS} -x c-header -o "${_output_c}" "${_pchfile}" - DEPENDS "${_pchfile}" "${_pch_flags_file}" - COMMENT "Precompiling ${_name} for ${_target} (C)") - - get_property(_sources TARGET ${_target} PROPERTY SOURCES) - foreach(_source ${_sources}) - set(_pch_compile_flags "") - - if(_source MATCHES \\.\(cc|cxx|cpp|c\)$) - get_source_file_property(_pch_compile_flags "${_source}" COMPILE_FLAGS) - if(NOT _pch_compile_flags) - set(_pch_compile_flags) - endif() - separate_arguments(_pch_compile_flags) - list(APPEND _pch_compile_flags -Winvalid-pch) - if(_PCH_FORCEINCLUDE) - list(APPEND _pch_compile_flags -include "${_pchfile}") - else(_PCH_FORCEINCLUDE) - list(APPEND _pch_compile_flags "-I${_pch_binary_dir}") - endif(_PCH_FORCEINCLUDE) - - get_source_file_property(_object_depends "${_source}" OBJECT_DEPENDS) - if(NOT _object_depends) - set(_object_depends) - endif() - list(APPEND _object_depends "${_pchfile}") - if(_source MATCHES \\.\(cc|cxx|cpp\)$) - list(APPEND _object_depends "${_output_cxx}") - else() - list(APPEND _object_depends "${_output_c}") - endif() - - combine_arguments(_pch_compile_flags) - set_source_files_properties(${_source} PROPERTIES - COMPILE_FLAGS "${_pch_compile_flags}" - OBJECT_DEPENDS "${_object_depends}") - endif() - endforeach() - endif(CMAKE_COMPILER_IS_GNUCXX) + if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU|Clang") + gcc_pch_targets_for_mode("${_input}" "${_PCH_PCH_PATH}" "C") + gcc_pch_targets_for_mode("${_input}" "${_PCH_PCH_PATH}" "CXX") + endif(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU|Clang") endfunction() diff --git a/runall.sh b/runall.sh index b0ea918..c0dc5ad 100755 --- a/runall.sh +++ b/runall.sh @@ -1,4 +1,6 @@ #!/bin/sh -exu +set -e + buildroot=$(dirname $(readlink -f $0))/build generator="Unix Makefiles" mkdir -p "$buildroot" diff --git a/test/c-force/CMakeLists.txt b/test/c-force/CMakeLists.txt index 3fabfb2..0581bee 100644 --- a/test/c-force/CMakeLists.txt +++ b/test/c-force/CMakeLists.txt @@ -7,6 +7,8 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) set(pch_source test-pch.c) endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") add_executable(test-c-force test-c-force.c test-pch.h ${pch_source}) add_precompiled_header(test-c-force test-pch.h FORCEINCLUDE) add_test(test-c-force test-c-force) diff --git a/test/c/CMakeLists.txt b/test/c/CMakeLists.txt index 1641bd1..2adb59c 100644 --- a/test/c/CMakeLists.txt +++ b/test/c/CMakeLists.txt @@ -7,6 +7,8 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) set(pch_source test-pch.c) endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") add_executable(test-c test-c.c test-pch.h ${pch_source}) add_precompiled_header(test-c test-pch.h) add_test(test-c test-c) diff --git a/test/cxx-force/CMakeLists.txt b/test/cxx-force/CMakeLists.txt index 7ba9cb3..028f612 100644 --- a/test/cxx-force/CMakeLists.txt +++ b/test/cxx-force/CMakeLists.txt @@ -7,6 +7,8 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) set(pch_source test-pch.cpp) endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") add_executable(test-cxx-force test-cxx-force.cpp test-pch.h ${pch_source}) add_precompiled_header(test-cxx-force test-pch.h FORCEINCLUDE) add_test(test-cxx-force test-cxx-force) diff --git a/test/cxx-pic-shared/CMakeLists.txt b/test/cxx-pic-shared/CMakeLists.txt new file mode 100644 index 0000000..6cc7d17 --- /dev/null +++ b/test/cxx-pic-shared/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.3) +cmake_policy(SET CMP0058 NEW) +enable_testing() +project(test-cxx-pic-shared) +include(../../PrecompiledHeader.cmake) +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + set(pch_source test-pch.cpp) +endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +add_library(test-cxx-pic-lib SHARED test-cxx-lib.cpp test-pch.h ${pch_source}) +add_precompiled_header(test-cxx-pic-lib test-pch.h FORCEINCLUDE) +add_executable(test-cxx-pic-shared test-cxx.cpp) +target_link_libraries(test-cxx-pic-shared test-cxx-pic-lib) +add_test(test-cxx-pic-shared test-cxx-pic-shared) diff --git a/test/cxx-pic-shared/test-cxx-lib.cpp b/test/cxx-pic-shared/test-cxx-lib.cpp new file mode 100644 index 0000000..f784be2 --- /dev/null +++ b/test/cxx-pic-shared/test-cxx-lib.cpp @@ -0,0 +1,4 @@ +#ifndef PCH +#error Missing precompiled header +#endif +int foo() { return 1; } diff --git a/test/cxx-pic-shared/test-cxx.cpp b/test/cxx-pic-shared/test-cxx.cpp new file mode 100644 index 0000000..40cc7b2 --- /dev/null +++ b/test/cxx-pic-shared/test-cxx.cpp @@ -0,0 +1,5 @@ +#include "test-pch.h" +#ifndef PCH +#error Missing precompiled header +#endif +int main() { return foo() == 1 && !(PCH == atoi(getenv("EXPECTED_PCH"))); } diff --git a/test/cxx-pic-shared/test-pch.cpp b/test/cxx-pic-shared/test-pch.cpp new file mode 100644 index 0000000..220a10f --- /dev/null +++ b/test/cxx-pic-shared/test-pch.cpp @@ -0,0 +1 @@ +#include "test-pch.h" diff --git a/test/cxx-pic-shared/test-pch.h b/test/cxx-pic-shared/test-pch.h new file mode 100644 index 0000000..58199fa --- /dev/null +++ b/test/cxx-pic-shared/test-pch.h @@ -0,0 +1,7 @@ +#define PCH 1 +#ifdef __cplusplus +#include +#else +#include +#endif +int foo(); diff --git a/test/cxx-pic/CMakeLists.txt b/test/cxx-pic/CMakeLists.txt new file mode 100644 index 0000000..70e0ca7 --- /dev/null +++ b/test/cxx-pic/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.3) +cmake_policy(SET CMP0058 NEW) +enable_testing() +project(test-cxx-pic) +include(../../PrecompiledHeader.cmake) +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + set(pch_source test-pch.cpp) +endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +add_library(test-cxx-pic-lib STATIC test-cxx-lib.cpp test-pch.h ${pch_source}) +set_target_properties(test-cxx-pic-lib PROPERTIES POSITION_INDEPENDENT_CODE ON) +add_precompiled_header(test-cxx-pic-lib test-pch.h FORCEINCLUDE) +add_executable(test-cxx-pic test-cxx.cpp) +target_link_libraries(test-cxx-pic test-cxx-pic-lib) +add_test(test-cxx-pic test-cxx-pic) diff --git a/test/cxx-pic/test-cxx-lib.cpp b/test/cxx-pic/test-cxx-lib.cpp new file mode 100644 index 0000000..f784be2 --- /dev/null +++ b/test/cxx-pic/test-cxx-lib.cpp @@ -0,0 +1,4 @@ +#ifndef PCH +#error Missing precompiled header +#endif +int foo() { return 1; } diff --git a/test/cxx-pic/test-cxx.cpp b/test/cxx-pic/test-cxx.cpp new file mode 100644 index 0000000..40cc7b2 --- /dev/null +++ b/test/cxx-pic/test-cxx.cpp @@ -0,0 +1,5 @@ +#include "test-pch.h" +#ifndef PCH +#error Missing precompiled header +#endif +int main() { return foo() == 1 && !(PCH == atoi(getenv("EXPECTED_PCH"))); } diff --git a/test/cxx-pic/test-pch.cpp b/test/cxx-pic/test-pch.cpp new file mode 100644 index 0000000..220a10f --- /dev/null +++ b/test/cxx-pic/test-pch.cpp @@ -0,0 +1 @@ +#include "test-pch.h" diff --git a/test/cxx-pic/test-pch.h b/test/cxx-pic/test-pch.h new file mode 100644 index 0000000..58199fa --- /dev/null +++ b/test/cxx-pic/test-pch.h @@ -0,0 +1,7 @@ +#define PCH 1 +#ifdef __cplusplus +#include +#else +#include +#endif +int foo(); diff --git a/test/cxx-pie/CMakeLists.txt b/test/cxx-pie/CMakeLists.txt new file mode 100644 index 0000000..fe3c94c --- /dev/null +++ b/test/cxx-pie/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.3) +cmake_policy(SET CMP0058 NEW) +enable_testing() +project(test-cxx-pie) +include(../../PrecompiledHeader.cmake) +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + set(pch_source test-pch.cpp) +endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +add_executable(test-cxx-pie test-cxx.cpp test-pch.h ${pch_source}) +set_target_properties(test-cxx-pie PROPERTIES POSITION_INDEPENDENT_CODE ON) +add_precompiled_header(test-cxx-pie test-pch.h FORCEINCLUDE) +add_test(test-cxx-pie test-cxx-pie) diff --git a/test/cxx-pie/test-cxx.cpp b/test/cxx-pie/test-cxx.cpp new file mode 100644 index 0000000..cd4461e --- /dev/null +++ b/test/cxx-pie/test-cxx.cpp @@ -0,0 +1,4 @@ +#ifndef PCH +#error Missing precompiled header +#endif +int main() { return !(PCH == atoi(getenv("EXPECTED_PCH"))); } diff --git a/test/cxx-pie/test-pch.cpp b/test/cxx-pie/test-pch.cpp new file mode 100644 index 0000000..220a10f --- /dev/null +++ b/test/cxx-pie/test-pch.cpp @@ -0,0 +1 @@ +#include "test-pch.h" diff --git a/test/cxx-pie/test-pch.h b/test/cxx-pie/test-pch.h new file mode 100644 index 0000000..bab0e72 --- /dev/null +++ b/test/cxx-pie/test-pch.h @@ -0,0 +1,6 @@ +#define PCH 1 +#ifdef __cplusplus +#include +#else +#include +#endif diff --git a/test/cxx/CMakeLists.txt b/test/cxx/CMakeLists.txt index 775571c..4476c07 100644 --- a/test/cxx/CMakeLists.txt +++ b/test/cxx/CMakeLists.txt @@ -7,6 +7,8 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) set(pch_source test-pch.cpp) endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") add_executable(test-cxx test-cxx.cpp test-pch.h ${pch_source}) add_precompiled_header(test-cxx test-pch.h) add_test(test-cxx test-cxx) diff --git a/test/cxx11/CMakeLists.txt b/test/cxx11/CMakeLists.txt new file mode 100644 index 0000000..a4bcde6 --- /dev/null +++ b/test/cxx11/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.3) +cmake_policy(SET CMP0058 NEW) +enable_testing() +project(test-cxx11) +include(../../PrecompiledHeader.cmake) +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + set(pch_source test-pch.cpp) +endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_CXX_STANDARD 11) +add_executable(test-cxx11 test-cxx.cpp test-pch.h ${pch_source}) +add_precompiled_header(test-cxx11 test-pch.h) +add_test(test-cxx11 test-cxx11) diff --git a/test/cxx11/test-cxx.cpp b/test/cxx11/test-cxx.cpp new file mode 100644 index 0000000..9efee44 --- /dev/null +++ b/test/cxx11/test-cxx.cpp @@ -0,0 +1,5 @@ +#include "test-pch.h" +#ifndef PCH +#error Missing precompiled header +#endif +int main() { return !(PCH == atoi(getenv("EXPECTED_PCH"))); } diff --git a/test/cxx11/test-pch.cpp b/test/cxx11/test-pch.cpp new file mode 100644 index 0000000..220a10f --- /dev/null +++ b/test/cxx11/test-pch.cpp @@ -0,0 +1 @@ +#include "test-pch.h" diff --git a/test/cxx11/test-pch.h b/test/cxx11/test-pch.h new file mode 100644 index 0000000..ec270f0 --- /dev/null +++ b/test/cxx11/test-pch.h @@ -0,0 +1,16 @@ +#define PCH 1 +#ifdef __cplusplus +#include +#include + +#if __cplusplus < 201100L +#error This PCH has to be compiled in C++11 mode +#endif + +#if __cplusplus > 201112L +#error This PCH has to be compiled in C++11 mode +#endif + +#else +#include +#endif diff --git a/test/cxx14_noext/CMakeLists.txt b/test/cxx14_noext/CMakeLists.txt new file mode 100644 index 0000000..f5755e9 --- /dev/null +++ b/test/cxx14_noext/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.3) +cmake_policy(SET CMP0058 NEW) +enable_testing() +project(test-cxx14_noext) +include(../../PrecompiledHeader.cmake) +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + set(pch_source test-pch.cpp) +endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_EXTENSIONS OFF) +add_executable(test-cxx14_noext test-cxx.cpp test-pch.h ${pch_source}) +add_precompiled_header(test-cxx14_noext test-pch.h) +add_test(test-cxx14_noext test-cxx14_noext) diff --git a/test/cxx14_noext/test-cxx.cpp b/test/cxx14_noext/test-cxx.cpp new file mode 100644 index 0000000..9efee44 --- /dev/null +++ b/test/cxx14_noext/test-cxx.cpp @@ -0,0 +1,5 @@ +#include "test-pch.h" +#ifndef PCH +#error Missing precompiled header +#endif +int main() { return !(PCH == atoi(getenv("EXPECTED_PCH"))); } diff --git a/test/cxx14_noext/test-pch.cpp b/test/cxx14_noext/test-pch.cpp new file mode 100644 index 0000000..220a10f --- /dev/null +++ b/test/cxx14_noext/test-pch.cpp @@ -0,0 +1 @@ +#include "test-pch.h" diff --git a/test/cxx14_noext/test-pch.h b/test/cxx14_noext/test-pch.h new file mode 100644 index 0000000..d5a3abd --- /dev/null +++ b/test/cxx14_noext/test-pch.h @@ -0,0 +1,16 @@ +#define PCH 1 +#ifdef __cplusplus +#include +#include + +#if __cplusplus < 201400L +#error This PCH has to be compiled in C++14 mode +#endif + +#if __cplusplus > 201412L +#error This PCH has to be compiled in C++14 mode +#endif + +#else +#include +#endif diff --git a/test/heavy/CMakeLists.txt b/test/heavy/CMakeLists.txt index 3dede3a..e720d3c 100644 --- a/test/heavy/CMakeLists.txt +++ b/test/heavy/CMakeLists.txt @@ -7,6 +7,8 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) set(pch_source test-pch.cpp) endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") add_executable(test-heavy test-heavy.cpp test-pch.h ${pch_source}) add_precompiled_header(test-heavy test-pch.h FORCEINCLUDE) add_test(test-heavy test-heavy) diff --git a/test/mixed-force/CMakeLists.txt b/test/mixed-force/CMakeLists.txt index ce6e919..56677dc 100644 --- a/test/mixed-force/CMakeLists.txt +++ b/test/mixed-force/CMakeLists.txt @@ -7,6 +7,8 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) set(pch_source test-pch.c test-pch.cpp) endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") add_executable(test-mixed-force test-mixed-force.c test-mixed-force.cpp test-pch.h ${pch_source}) add_precompiled_header(test-mixed-force test-pch.h FORCEINCLUDE) add_test(test-mixed-force test-mixed-force) diff --git a/test/mixed-subdirectory/CMakeLists.txt b/test/mixed-subdirectory/CMakeLists.txt new file mode 100644 index 0000000..f121b90 --- /dev/null +++ b/test/mixed-subdirectory/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.3) +cmake_policy(SET CMP0058 NEW) +enable_testing() +project(test-mixed-subdirectory) +include(../../PrecompiledHeader.cmake) +add_subdirectory(src) diff --git a/test/mixed-subdirectory/src/CMakeLists.txt b/test/mixed-subdirectory/src/CMakeLists.txt new file mode 100644 index 0000000..c7c189d --- /dev/null +++ b/test/mixed-subdirectory/src/CMakeLists.txt @@ -0,0 +1,10 @@ +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + set(pch_source test-pch.c test-pch.cpp) +endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +include_directories(${CMAKE_CURRENT_SOURC_DIR}/../) +add_executable(test-mixed-subdirectory test-mixed.c test-mixed.cpp ../test-pch.h ${pch_source}) +add_precompiled_header(test-mixed-subdirectory ../test-pch.h PCH_PATH test-pch.h) +add_test(test-mixed-subdirectory test-mixed-subdirectory) diff --git a/test/mixed-subdirectory/src/test-mixed.c b/test/mixed-subdirectory/src/test-mixed.c new file mode 100644 index 0000000..a5bd4c1 --- /dev/null +++ b/test/mixed-subdirectory/src/test-mixed.c @@ -0,0 +1,5 @@ +#include "test-pch.h" +#ifndef PCH +#error Missing precompiled header +#endif +int c_main(void) { return !(PCH == atoi(getenv("EXPECTED_PCH"))); } diff --git a/test/mixed-subdirectory/src/test-mixed.cpp b/test/mixed-subdirectory/src/test-mixed.cpp new file mode 100644 index 0000000..0279914 --- /dev/null +++ b/test/mixed-subdirectory/src/test-mixed.cpp @@ -0,0 +1,6 @@ +#include "test-pch.h" +#ifndef PCH +#error Missing precompiled header +#endif +extern "C" int c_main(void); +int main() { return !(PCH == atoi(getenv("EXPECTED_PCH"))) + c_main(); } diff --git a/test/mixed-subdirectory/src/test-pch.c b/test/mixed-subdirectory/src/test-pch.c new file mode 100644 index 0000000..220a10f --- /dev/null +++ b/test/mixed-subdirectory/src/test-pch.c @@ -0,0 +1 @@ +#include "test-pch.h" diff --git a/test/mixed-subdirectory/src/test-pch.cpp b/test/mixed-subdirectory/src/test-pch.cpp new file mode 100644 index 0000000..220a10f --- /dev/null +++ b/test/mixed-subdirectory/src/test-pch.cpp @@ -0,0 +1 @@ +#include "test-pch.h" diff --git a/test/mixed-subdirectory/test-pch.h b/test/mixed-subdirectory/test-pch.h new file mode 100644 index 0000000..bab0e72 --- /dev/null +++ b/test/mixed-subdirectory/test-pch.h @@ -0,0 +1,6 @@ +#define PCH 1 +#ifdef __cplusplus +#include +#else +#include +#endif diff --git a/test/mixed/CMakeLists.txt b/test/mixed/CMakeLists.txt index 6e03cb8..d32a4bd 100644 --- a/test/mixed/CMakeLists.txt +++ b/test/mixed/CMakeLists.txt @@ -7,6 +7,8 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) set(pch_source test-pch.c test-pch.cpp) endif() +set(CMAKE_CXX_FLAGS "${CMAKH_CXX_FLAGS} -Werror") +set(CMAKE_C_FLAGS "${CMAKH_CXX_FLAGS} -Werror") add_executable(test-mixed test-mixed.c test-mixed.cpp test-pch.h ${pch_source}) add_precompiled_header(test-mixed test-pch.h) add_test(test-mixed test-mixed)