Skip to content

Commit

Permalink
NMake Makefiles support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Christensen committed Mar 28, 2017
1 parent 160e1da commit 6803af3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vs2010/
mingw/
build/
example-*/
*.orig
15 changes: 3 additions & 12 deletions PrecompiledHeader.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,8 @@ function(add_precompiled_header _target _input)
endif()

if(MSVC)

set(_cxx_path "${CMAKE_CFG_INTDIR}/${_target}_cxx_pch")
set(_c_path "${CMAKE_CFG_INTDIR}/${_target}_c_pch")
set(_pch_cxx_header "${_cxx_path}/${_input}")
set(_pch_cxx_pch "${_cxx_path}/${_input_we}.pch")
set(_pch_c_header "${_c_path}/${_input}")
set(_pch_c_pch "${_c_path}/${_input_we}.pch")
set(_pch_cxx_pch "${CMAKE_CFG_INTDIR}/cxx_${_input_we}.pch")
set(_pch_c_pch "${CMAKE_CFG_INTDIR}/c_${_input_we}.pch")

get_target_property(sources ${_target} SOURCES)
foreach(_source ${sources})
Expand Down Expand Up @@ -135,11 +130,7 @@ function(add_precompiled_header _target _input)
set(_object_depends)
endif()
if(_PCH_FORCEINCLUDE)
if(_source MATCHES \\.\(cc|cxx|cpp\)$)
list(APPEND _object_depends "${_pch_header}")
else()
list(APPEND _object_depends "${_pch_header}")
endif()
list(APPEND _object_depends "${CMAKE_CURRENT_SOURCE_DIR}/${_pch_header}")
endif()

set_source_files_properties(${_source} PROPERTIES
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
Precompiled header setup for CMake. Supported CMake generators:

* Visual Studio
* NMake Makefiles
* Unix Makefiles (GCC)
* MinGW Makefiles
* MSYS Makefiles
* Ninja

# Usage

Create a `pchheader.{c,cpp}` and `pchheader.h` and add then to the CMake target:
Expand Down
4 changes: 2 additions & 2 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.7.2)
include(../PrecompiledHeader.cmake)
project(example)
add_executable(example main.cpp pch.cpp)
add_precompiled_header(example pch.h FORCEINCLUDE)
add_executable(example main.cpp pch.cpp main.h)
add_precompiled_header(example pch.h SOURCE_CXX pch.cpp FORCEINCLUDE)
1 change: 1 addition & 0 deletions example/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <iostream>
9 changes: 9 additions & 0 deletions runtest.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ set buildroot=%~dp0build

call :runtest %1 "Visual Studio 14 2015"
if errorlevel 1 exit /b 1

call :runtest %1 "MinGW Makefiles"
if errorlevel 1 exit /b 1

call :runtest %1 "Ninja"
if errorlevel 1 exit /b 1

setlocal
call "%VS140COMNTOOLS%\vsvars32.bat"
call :runtest %1 "NMake Makefiles"
if errorlevel 1 exit /b 1
endlocal

goto :eof

:runtest
Expand Down

0 comments on commit 6803af3

Please sign in to comment.