summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-11-02 14:34:33 +0000
committeriphydf <iphydf@users.noreply.github.com>2016-11-02 18:50:41 +0000
commit96c672aef59ac785f3d351698311bb358820cc3c (patch)
treef862797a5a7f161a5ec727ca1d7df322a6d58c05 /cmake
parente2d63e04979b59698b7e541f2aebb3c74495a2d3 (diff)
Compile as C++ for windows builds.
Compiling as C++ changes nothing semantically, but ensures that we don't break C++ compatibility while also retaining C compatibility. C++ compatibility is useful for tooling and additional diagnostics and analyses.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/ModulePackage.cmake11
1 files changed, 9 insertions, 2 deletions
diff --git a/cmake/ModulePackage.cmake b/cmake/ModulePackage.cmake
index fa3779c3..a556aef0 100644
--- a/cmake/ModulePackage.cmake
+++ b/cmake/ModulePackage.cmake
@@ -4,7 +4,12 @@ option(COMPILE_AS_CXX "Compile all C code as C++ code" OFF)
4 4
5find_package(PkgConfig REQUIRED) 5find_package(PkgConfig REQUIRED)
6 6
7function(set_source_language) 7if(COMPILE_AS_CXX)
8 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS=1")
9 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_LIMIT_MACROS=1")
10endif()
11
12macro(set_source_language)
8 if(COMPILE_AS_CXX) 13 if(COMPILE_AS_CXX)
9 foreach(srcfile ${ARGN}) 14 foreach(srcfile ${ARGN})
10 get_filename_component(srcext ${srcfile} EXT) 15 get_filename_component(srcext ${srcfile} EXT)
@@ -13,10 +18,11 @@ function(set_source_language)
13 endif() 18 endif()
14 endforeach() 19 endforeach()
15 endif() 20 endif()
16endfunction() 21endmacro()
17 22
18function(add_c_executable exec) 23function(add_c_executable exec)
19 set_source_language(${ARGN}) 24 set_source_language(${ARGN})
25
20 add_executable(${exec} ${ARGN}) 26 add_executable(${exec} ${ARGN})
21endfunction() 27endfunction()
22 28
@@ -26,6 +32,7 @@ function(pkg_use_module mod)
26 link_directories(${${mod}_LIBRARY_DIRS}) 32 link_directories(${${mod}_LIBRARY_DIRS})
27 include_directories(${${mod}_INCLUDE_DIRS}) 33 include_directories(${${mod}_INCLUDE_DIRS})
28 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}") 34 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${mod}_CFLAGS_OTHER}")
35 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${mod}_CFLAGS_OTHER}")
29 endif() 36 endif()
30endfunction() 37endfunction()
31 38