diff --git a/toonz/cmake/util_compiler.cmake b/toonz/cmake/util_compiler.cmake new file mode 100644 index 0000000..7db1913 --- /dev/null +++ b/toonz/cmake/util_compiler.cmake @@ -0,0 +1,33 @@ +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) + +function(ADD_CHECK_C_COMPILER_FLAG + _CFLAGS + _CACHE_VAR + _FLAG + ) + + CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}") + if(${_CACHE_VAR}) + # message(STATUS "Using CFLAG: ${_FLAG}") + set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}" PARENT_SCOPE) + else() + message(STATUS "Unsupported CFLAG: ${_FLAG}") + endif() +endfunction() + +function(ADD_CHECK_CXX_COMPILER_FLAG + _CXXFLAGS + _CACHE_VAR + _FLAG + ) + + CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}") + if(${_CACHE_VAR}) + # message(STATUS "Using CXXFLAG: ${_FLAG}") + set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}" PARENT_SCOPE) + else() + message(STATUS "Unsupported CXXFLAG: ${_FLAG}") + endif() +endfunction() + diff --git a/toonz/sources/CMakeLists.txt b/toonz/sources/CMakeLists.txt index a29c4b2..00567ca 100644 --- a/toonz/sources/CMakeLists.txt +++ b/toonz/sources/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 2.8.11) project(OpenToonz) +include(${CMAKE_SOURCE_DIR}/../cmake/util_compiler.cmake) + get_filename_component(SDKROOT ../../thirdparty/ ABSOLUTE) message("SDK Root:" ${SDKROOT}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake") @@ -309,6 +311,19 @@ elseif(UNIX) pkg_check_modules(SDL_LIB REQUIRED sdl2) endif() + +set(C_WARNINGS) +set(CXX_WARNINGS) + +if(CMAKE_COMPILER_IS_GNUCC) + ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings) + ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef) + + ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings) + ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef) +endif() + + include_directories( BEFORE ${TIFF_INCLUDE_DIR} @@ -394,6 +409,9 @@ function(add_translation module) EXCLUDE_FROM_DEFAULT_BUILD TRUE) endfunction() +set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS}") +set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS}") + add_subdirectory(tnzcore) add_subdirectory(tnzbase) add_subdirectory(tnzext)