ref: b84601cceb904f82135e10094aae3fdb24725801
parent: 03c460a60b1f16b1eb28902e8c95d8807e6d811b
author: Clownacy <[email protected]>
date: Sat Mar 14 18:41:14 EDT 2020
Update DoConfig and bin2h CMake files
--- a/DoConfig/CMakeLists.txt
+++ b/DoConfig/CMakeLists.txt
@@ -1,118 +1,32 @@
-cmake_minimum_required(VERSION 3.7.2)
+cmake_minimum_required(VERSION 3.12)
-if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
- cmake_policy(SET CMP0069 NEW)
-endif()
-
-if((${CMAKE_VERSION} VERSION_EQUAL 3.11) OR (${CMAKE_VERSION} VERSION_GREATER 3.11))
- cmake_policy(SET CMP0072 NEW)
-endif()
-
option(LTO "Enable link-time optimisation" OFF)
-option(NATIVE_OPTIMIZATIONS "Enable processor-specific optimisations (executable might not work on other architectures) (GCC-compatible compilers only)" OFF)
-option(WARNINGS "Enable common compiler warnings (for GCC-compatible compilers and MSVC only)" OFF)
-option(WARNINGS_ALL "Enable ALL compiler warnings (for Clang and MSVC only)" OFF)
-option(WARNINGS_FATAL "Stop compilation on any compiler warning (for GCC-compatible compilers and MSVC only)" OFF)
option(FORCE_LOCAL_LIBS "Compile the built-in version of FLTK instead of using the system-provided one" OFF)
project(DoConfig LANGUAGES CXX)
-message(STATUS "Compiler ID : ${CMAKE_CXX_COMPILER_ID}")
+add_executable(DoConfig WIN32 "DoConfig.cpp" "icon.rc")
-# Has to be placed after "project()"
-if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
- # Using Clang (this is a match so that we also get "AppleClang" which is the Apple-provided Clang
- set(COMPILER_IS_CLANG true)
- message(STATUS "Compiling with Clang")
-endif()
+# Make some tweaks if we're using MSVC
+if(MSVC)
+ # Disable warnings that normally fire up on MSVC when using "unsafe" functions instead of using MSVC's "safe" _s functions
+ target_compile_definitions(CSE2 PRIVATE _CRT_SECURE_NO_WARNINGS)
-if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
- # Using GCC
- set(COMPILER_IS_GCC true)
- message(STATUS "Compiling with GCC")
+ # Make it so source files are recognized as UTF-8 by MSVC
+ target_compile_options(CSE2 PRIVATE "/utf-8")
endif()
-if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
- # Using Intel C++
- set(COMPILER_IS_ICC true)
- message(STATUS "Compiling with ICC")
-endif()
+if(LTO)
+ include(CheckIPOSupported)
-if(COMPILER_IS_CLANG OR COMPILER_IS_GCC OR COMPILER_IS_ICC)
- set(COMPILER_IS_GCC_COMPATIBLE true)
- message(STATUS "Compiling with a GCC-compatible compiler")
-endif()
+ check_ipo_supported(RESULT result)
-add_executable(DoConfig "DoConfig.cpp" "icon.rc")
-
-if(WARNINGS)
- # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
-
- if(MSVC)
- # Force to always compile with /W4 on MSVC
-
- # Can't do this with target_compile_options
- # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
- # string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- # else()
- # target_compile_options(DoConfig PRIVATE /W4)
- # endif()
-
- target_compile_options(DoConfig PRIVATE /W4)
- elseif(COMPILER_IS_GCC_COMPATIBLE)
- target_compile_options(DoConfig PRIVATE -Wall -Wextra -pedantic)
- else()
- message(WARNING "Could not activate warnings ! (Unsupported compiler)")
+ if(result)
+ set_target_properties(CSE2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
-if(WARNINGS_ALL)
- # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
-
- if(MSVC)
- # Force to always compile with /Wall on MSVC
-
- # Can't do this with target_compile_options
- # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
- # string(REGEX REPLACE "/W[0-4]" "/Wall" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- # else()
- # target_compile_options(DoConfig PRIVATE /Wall)
- # endif()
-
- target_compile_options(DoConfig PRIVATE /Wall)
- elseif(COMPILER_IS_CLANG)
- target_compile_options(DoConfig PRIVATE -Weverything)
- else()
- message(WARNING "Could not activate all warnings ! (Unsupported compiler)")
- endif()
-endif()
-
-if(WARNINGS_FATAL)
- # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
-
- if(MSVC)
- target_compile_options(DoConfig PRIVATE /WX)
- elseif(COMPILER_IS_GCC_COMPATIBLE)
- target_compile_options(DoConfig PRIVATE -Werror)
- else()
- message(WARNING "Could not activate fatal warnings ! (Unsupported compiler)")
- endif()
-endif()
-
-# Windows tweak
-if(WIN32)
- set_target_properties(DoConfig PROPERTIES WIN32_EXECUTABLE YES) # Disable the console window
-endif()
-
-# MSVC tweak
-if(MSVC)
- target_compile_definitions(DoConfig PRIVATE _CRT_SECURE_NO_WARNINGS) # Disable warnings that normally fire up on MSVC when using "unsafe" functions instead of using MSVC's "safe" _s functions
-endif()
-
-# Make it so source files are recognized as UTF-8 by MSVC
-add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
-
# Find FLTK
if(NOT FORCE_LOCAL_LIBS)
set(FLTK_SKIP_FLUID ON) # Do not require fltk-fluid (the UI designer)
@@ -140,34 +54,4 @@
get_target_property(DIRS fltk INCLUDE_DIRECTORIES) # FLTK doesn't mark its includes as PUBLIC or INTERFACE, so we have to do this stupidity
target_include_directories(DoConfig PRIVATE ${DIRS})
target_link_libraries(DoConfig PRIVATE fltk)
-endif()
-
-# Enable link-time optimisation if available
-if(LTO)
- if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
- include(CheckIPOSupported)
- check_ipo_supported(RESULT result)
- if(result)
- set_target_properties(DoConfig PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
- endif()
- endif()
-endif()
-
-# Enable -march=native if available
-if(NATIVE_OPTIMIZATIONS)
- include(CheckCXXCompilerFlag)
- CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) # GCC flag
- if(COMPILER_SUPPORTS_MARCH_NATIVE)
- target_compile_options(DoConfig PRIVATE -march=native)
- else()
- CHECK_CXX_COMPILER_FLAG("-xHost" COMPILER_SUPPORTS_XHOST) # ICC (Linux) flag
- CHECK_CXX_COMPILER_FLAG("/QxHost" COMPILER_SUPPORTS_QXHOST) # ICC (Windows) flag
- if(COMPILER_SUPPORTS_XHOST)
- target_compile_options(DoConfig PRIVATE -xHost)
- elseif(COMPILER_SUPPORTS_QXHOST)
- target_compile_options(DoConfig PRIVATE /QxHost)
- else()
- message(WARNING "Couldn't activate native optimizations ! (Unsupported compiler)")
- endif()
- endif()
endif()
--- a/bin2h/CMakeLists.txt
+++ b/bin2h/CMakeLists.txt
@@ -1,16 +1,7 @@
-cmake_minimum_required(VERSION 3.7.2)
+cmake_minimum_required(VERSION 3.12)
-if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
- cmake_policy(SET CMP0069 NEW)
-endif()
-
option(LTO "Enable link-time optimisation" OFF)
-option(NATIVE_OPTIMIZATIONS "Enable processor-specific optimisations (executable might not work on other architectures) (GCC-compatible compilers only)" OFF)
-option(WARNINGS "Enable common compiler warnings (for GCC-compatible compilers and MSVC only)" OFF)
-option(WARNINGS_ALL "Enable ALL compiler warnings (for Clang and MSVC only)" OFF)
-option(WARNINGS_FATAL "Stop compilation on any compiler warning (for GCC-compatible compilers and MSVC only)" OFF)
-
project(bin2h LANGUAGES C)
add_executable(bin2h "bin2h.c")
@@ -21,132 +12,22 @@
C_EXTENSIONS OFF
)
-message(STATUS "Compiler ID : ${CMAKE_C_COMPILER_ID}")
-
-# Has to be placed after "project()"
-if (CMAKE_C_COMPILER_ID MATCHES "Clang")
- # Using Clang (this is a match so that we also get "AppleClang" which is the Apple-provided Clang
- set(COMPILER_IS_CLANG true)
- message(STATUS "Compiling with Clang")
-endif()
-
-if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- # Using GCC
- set(COMPILER_IS_GCC true)
- message(STATUS "Compiling with GCC")
-endif()
-
-if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
- # Using Intel C++
- set(COMPILER_IS_ICC true)
- message(STATUS "Compiling with ICC")
-endif()
-
-if (COMPILER_IS_CLANG OR COMPILER_IS_GCC OR COMPILER_IS_ICC)
- set(COMPILER_IS_GCC_COMPATIBLE true)
- message(STATUS "Compiling with a GCC-compatible compiler")
-endif()
-
-if (WARNINGS)
- # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
-
- if (MSVC)
- # Force to always compile with /W4 on MSVC
-
- # Can't do this with target_compile_options
- # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
- # string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- # else()
- # target_compile_options(bin2h PRIVATE /W4)
- # endif()
-
- target_compile_options(bin2h PRIVATE /W4)
- elseif(COMPILER_IS_GCC_COMPATIBLE)
- target_compile_options(bin2h PRIVATE -Wall -Wextra -pedantic)
- else()
- message(WARNING "Could not activate warnings ! (Unsupported compiler)")
- endif()
-endif()
-
-if (WARNINGS_ALL)
- # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
-
- if (MSVC)
- # Force to always compile with /Wall on MSVC
-
- # Can't do this with target_compile_options
- # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
- # string(REGEX REPLACE "/W[0-4]" "/Wall" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- # else()
- # target_compile_options(bin2h PRIVATE /Wall)
- # endif()
-
- target_compile_options(bin2h PRIVATE /Wall)
- elseif(COMPILER_IS_CLANG)
- target_compile_options(bin2h PRIVATE -Weverything)
- else()
- message(WARNING "Could not activate all warnings ! (Unsupported compiler)")
- endif()
-endif()
-
-if (WARNINGS_FATAL)
- # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
-
- if (MSVC)
- target_compile_options(bin2h PRIVATE /WX)
- elseif(COMPILER_IS_GCC_COMPATIBLE)
- target_compile_options(bin2h PRIVATE -Werror)
- else()
- message(WARNING "Could not activate fatal warnings ! (Unsupported compiler)")
- endif()
-endif()
-
-# MSVC tweak
+# Make some tweaks if we're using MSVC
if(MSVC)
- target_compile_definitions(bin2h PRIVATE _CRT_SECURE_NO_WARNINGS) # Disable warnings that normally fire up on MSVC when using "unsafe" functions instead of using MSVC's "safe" _s functions
-endif()
+ # Disable warnings that normally fire up on MSVC when using "unsafe" functions instead of using MSVC's "safe" _s functions
+ target_compile_definitions(CSE2 PRIVATE _CRT_SECURE_NO_WARNINGS)
-# Make it so source files are recognized as UTF-8 by MSVC
-add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
-
-# Enable link-time optimisation if available
-if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
- if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
- include(CheckIPOSupported)
- check_ipo_supported(RESULT result)
- if(result)
- set_target_properties(bin2h PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
- endif()
- endif()
+ # Make it so source files are recognized as UTF-8 by MSVC
+ target_compile_options(CSE2 PRIVATE "/utf-8")
endif()
-# Enable link-time optimisation if available
if(LTO)
- if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
- include(CheckIPOSupported)
- check_ipo_supported(RESULT result)
- if(result)
- set_target_properties(bin2h PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
- endif()
- endif()
-endif()
+ include(CheckIPOSupported)
-# Enable -march=native if available
-if(NATIVE_OPTIMIZATIONS)
- include(CheckCXXCompilerFlag)
- CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) # GCC flag
- if(COMPILER_SUPPORTS_MARCH_NATIVE)
- target_compile_options(bin2h PRIVATE -march=native)
- else()
- CHECK_CXX_COMPILER_FLAG("-xHost" COMPILER_SUPPORTS_XHOST) # ICC (Linux) flag
- CHECK_CXX_COMPILER_FLAG("/QxHost" COMPILER_SUPPORTS_QXHOST) # ICC (Windows) flag
- if(COMPILER_SUPPORTS_XHOST)
- target_compile_options(bin2h PRIVATE -xHost)
- elseif(COMPILER_SUPPORTS_QXHOST)
- target_compile_options(bin2h PRIVATE /QxHost)
- else()
- message(WARNING "Couldn't activate native optimizations ! (Unsupported compiler)")
- endif()
+ check_ipo_supported(RESULT result)
+
+ if(result)
+ set_target_properties(CSE2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()