shithub: cstory

Download patch

ref: 2bf46dc700265f3a58184746cfe389bd59b80ec3
parent: 014d1283961f87c0cbfc65b8a58b0399dc52967c
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sat Apr 20 01:00:43 EDT 2019

A bunch of CMake file cleanup

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
 cmake_minimum_required(VERSION 3.7.2)
 
-if ((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
+if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
 	cmake_policy(SET CMP0069 NEW)
 endif()
 
@@ -25,6 +25,21 @@
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_EXTENSIONS OFF)
 
+if(MSVC)
+	# Static-link the CRT, so we don't need to lug around 10 different DLLs
+	foreach(FLAG_VAR
+			CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+			CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+		if(${FLAG_VAR} MATCHES "/MD")
+			string(REGEX REPLACE "/MD" "/MT" ${FLAG_VAR} "${${FLAG_VAR}}")
+		endif()
+	endforeach()
+endif()
+
+##
+# CSE2
+##
+
 add_executable(CSE2
 	src/ArmsItem.cpp
 	src/ArmsItem.h
@@ -221,7 +236,7 @@
 )
 
 # Handle options
-if (JAPANESE)
+if(JAPANESE)
 	set(BUILD_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build_jp")
 	list(APPEND RESOURCES "BITMAP/PIXEL_JP.bmp")
 	target_compile_definitions(CSE2 PRIVATE JAPANESE)
@@ -230,20 +245,20 @@
 	list(APPEND RESOURCES "BITMAP/PIXEL.bmp")
 endif()
 
-if (FIX_BUGS)
+if(FIX_BUGS)
 	target_compile_definitions(CSE2 PRIVATE FIX_BUGS)
 endif()
 
-if (EXISTS "/opt/vc/include/bcm_host.h")	# Detect Raspberry Pi
+if(EXISTS "/opt/vc/include/bcm_host.h")	# Detect Raspberry Pi
 	target_compile_definitions(CSE2 PRIVATE RASPBERRY_PI)
 endif()
 
-if (NONPORTABLE)
+if(NONPORTABLE)
 	target_compile_definitions(CSE2 PRIVATE NONPORTABLE)
 endif()
 
 # Make some tweaks if we're targetting Windows
-if (WIN32)
+if(WIN32)
 	target_sources(CSE2 PRIVATE "res/ICON/ICON.rc")
 	target_compile_definitions(CSE2 PRIVATE WINDOWS)
 	set_target_properties(CSE2 PROPERTIES WIN32_EXECUTABLE YES)	# Disable the console window
@@ -251,8 +266,24 @@
 	list(APPEND RESOURCES "ICON/ICON_MINI.bmp")
 endif()
 
+# Make some tweaks if we're using MSVC
+if(MSVC)
+	# Work around MSVC2003's lack of stdint.h
+	include(CheckIncludeFiles)
+	check_include_files(stdint.h STDINT_EXISTS)
+	if(NOT STDINT_EXISTS)
+		target_include_directories(CSE2 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/msvc/msvc2003")
+	endif()
+
+	# Shut up those stupid warnings
+	target_compile_definitions(CSE2 PRIVATE _CRT_SECURE_NO_WARNINGS)
+endif()
+
 # Magic to convert resources to header files
-add_executable(bin2h src/misc/bin2h.c)
+add_executable(bin2h "src/misc/bin2h.c")
+if(MSVC)
+	target_compile_definitions(bin2h PRIVATE _CRT_SECURE_NO_WARNINGS)	# Shut up those stupid warnings
+endif()
 foreach(FILENAME IN LISTS RESOURCES)
 	set(IN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res")
 	set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/Resource")
@@ -266,65 +297,39 @@
 	target_sources(CSE2 PRIVATE "${OUT_DIR}/${FILENAME}.h")
 endforeach()
 
-if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
-	if ((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
-		# Enable link-time optimisation if available
+# 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)
+		if(result)
 			set_target_properties(CSE2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
 		endif()
 	endif()
 endif()
 
-if (MSVC)
-	# Find dependencies
-
+# Find dependencies
+if(MSVC)
 	# In MSVC we just use our own provided copy of SDL2 and FreeType
-	set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/include")
-	set(FREETYPE_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/msvc/freetype/include")
+	target_include_directories(CSE2 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/include" "${CMAKE_CURRENT_SOURCE_DIR}/msvc/freetype/include")
 
-	if (CMAKE_CL_64)
-		set(SDL2_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/lib/x64/SDL2.lib;${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/lib/x64/SDL2main.lib")
-		set(FREETYPE_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/msvc/freetype/win64/freetype.lib")
+	if(CMAKE_CL_64)
+		target_link_libraries(CSE2 "${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/lib/x64/SDL2.lib" "${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/lib/x64/SDL2main.lib" "${CMAKE_CURRENT_SOURCE_DIR}/msvc/freetype/win64/freetype.lib")
 	else()
-		set(SDL2_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/lib/x86/SDL2.lib;${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/lib/x86/SDL2main.lib")
-		set(FREETYPE_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/msvc/freetype/win32/freetype.lib")
+		target_link_libraries(CSE2 "${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/lib/x86/SDL2.lib" "${CMAKE_CURRENT_SOURCE_DIR}/msvc/SDL2/lib/x86/SDL2main.lib" "${CMAKE_CURRENT_SOURCE_DIR}/msvc/freetype/win32/freetype.lib")
 	endif()
+elseif(MSYS)
+	target_link_libraries(CSE2 -static)
 
-	# Static-link the CRT, so we don't need to lug around 10 different DLLs
-	foreach(FLAG_VAR
-			CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
-			CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
-		if(${FLAG_VAR} MATCHES "/MD")
-			string(REGEX REPLACE "/MD" "/MT" ${FLAG_VAR} "${${FLAG_VAR}}")
-		endif()
-	endforeach()
-
-	# Work around MSVC2003's lack of stdint.h
-	include(CheckIncludeFiles)
-	check_include_files(stdint.h STDINT_EXISTS)
-	if (NOT STDINT_EXISTS)
-		target_include_directories(CSE2 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/msvc/msvc2003")
-	endif()
-
-	# Shut up those stupid warnings
-	target_compile_definitions(CSE2 PRIVATE _CRT_SECURE_NO_WARNINGS)
-elseif (MSYS)
 	# Fall back on pkg-config, since cmake's static support sucks
 	find_package(PkgConfig REQUIRED)
 
 	pkg_check_modules(SDL2 REQUIRED sdl2)
-	set(SDL2_INCLUDE_DIRS ${SDL2_STATIC_INCLUDE_DIRS})
-	set(SDL2_CFLAGS_OTHER ${SDL2_STATIC_CFLAGS_OTHER})
-	set(SDL2_LIBRARIES ${SDL2_STATIC_LIBRARIES})
-
 	pkg_check_modules(FREETYPE REQUIRED freetype2)
-	set(FREETYPE_INCLUDE_DIRS ${FREETYPE_STATIC_INCLUDE_DIRS})
-	set(FREETYPE_CFLAGS_OTHER ${FREETYPE_STATIC_CFLAGS_OTHER})
-	set(FREETYPE_LIBRARIES ${FREETYPE_STATIC_LIBRARIES})
 
-	target_link_libraries(CSE2 -static)
+	target_include_directories(CSE2 PRIVATE ${SDL2_STATIC_INCLUDE_DIRS} ${FREETYPE_STATIC_INCLUDE_DIRS})
+	target_compile_options(CSE2 PRIVATE ${SDL2_STATIC_CFLAGS_OTHER} ${FREETYPE_STATIC_CFLAGS_OTHER})
+	target_link_libraries(CSE2 ${SDL2_STATIC_LIBRARIES} ${FREETYPE_STATIC_LIBRARIES})
 else()
 	# SDL2 has no standard way of being used by cmake, so avoid
 	# that mess entirely and just use pkg-config instead
@@ -332,12 +337,13 @@
 	pkg_check_modules(SDL2 REQUIRED sdl2)
 
 	find_package(Freetype REQUIRED)
+
+	target_include_directories(CSE2 PRIVATE ${SDL2_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS})
+	target_compile_options(CSE2 PRIVATE ${SDL2_CFLAGS_OTHER} ${FREETYPE_CFLAGS_OTHER})
+	target_link_libraries(CSE2 ${SDL2_LIBRARIES} ${FREETYPE_LIBRARIES})
 endif()
 
-target_include_directories(CSE2 PRIVATE ${SDL2_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS})
-target_compile_options(CSE2 PRIVATE ${SDL2_CFLAGS_OTHER} ${FREETYPE_CFLAGS_OTHER})
-target_link_libraries(CSE2 ${SDL2_LIBRARIES} ${FREETYPE_LIBRARIES})
-
+# Send executable to the build_en/build_jp directory
 set_target_properties(CSE2 PROPERTIES
 	RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BUILD_DIRECTORY}
 	RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${BUILD_DIRECTORY}
@@ -345,8 +351,9 @@
 	RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BUILD_DIRECTORY}
 )
 
-if (MSVC)
-	if (CMAKE_CL_64)
+# Also send across SDL2.dll if using MSVC
+if(MSVC)
+	if(CMAKE_CL_64)
 		set(SDL2_DLL_ARCH "x64")
 	else()
 		set(SDL2_DLL_ARCH "x86")
@@ -357,31 +364,38 @@
 	)
 endif()
 
-# Now for DoConfig
+##
+# DoConfig
+##
 
 add_executable(DoConfig "DoConfig/DoConfig.cpp" "DoConfig/icon.rc")
 
-set_target_properties(DoConfig PROPERTIES WIN32_EXECUTABLE YES)	# Disable the console window
+# 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)	# Shut up those stupid warnings
+endif()
+
 # Find FLTK
-if (MSVC)
+if(MSVC)
 	# Use local copy
 	target_include_directories(DoConfig PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/msvc/fltk/include")
 
-	if (CMAKE_CL_64)
+	if(CMAKE_CL_64)
 		target_link_libraries(DoConfig "${CMAKE_CURRENT_SOURCE_DIR}/msvc/fltk/lib/x64/fltk.lib")
 	else()
 		target_link_libraries(DoConfig "${CMAKE_CURRENT_SOURCE_DIR}/msvc/fltk/lib/x86/fltk.lib")
 
 		# Since the x86 version was built with MSVC2003, we need to enable backwards compatibility on newer compilers
-		if ((MSVC_VERSION EQUAL 1900) OR (MSVC_VERSION GREATER 1900))
+		if((MSVC_VERSION EQUAL 1900) OR (MSVC_VERSION GREATER 1900))
 			target_link_libraries(DoConfig "legacy_stdio_definitions.lib")
 		endif()
 	endif()
-
-	# Shut up those stupid warnings
-	target_compile_definitions(DoConfig PRIVATE _CRT_SECURE_NO_WARNINGS)
-elseif (MSYS)
+elseif(MSYS)
 	target_link_libraries(DoConfig -static)
 
 	# Do crazy nonsense to link the static version
@@ -388,7 +402,7 @@
 	find_package(FLTK REQUIRED)
 	target_include_directories(DoConfig PRIVATE ${FLTK_INCLUDE_DIRS})
 
-	if (NOT FLTK_CONFIG_SCRIPT)
+	if(NOT FLTK_CONFIG_SCRIPT)
 		find_program(FLTK_CONFIG_SCRIPT fltk-config)
 	endif()
 
@@ -400,6 +414,7 @@
 	target_link_libraries(DoConfig ${FLTK_LIBRARIES})
 endif()
 
+# Send executable to the build_en/build_jp directory
 set_target_properties(DoConfig PROPERTIES
 	RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BUILD_DIRECTORY}
 	RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${BUILD_DIRECTORY}
@@ -407,12 +422,12 @@
 	RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BUILD_DIRECTORY}
 )
 
-if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
-	if ((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
-		# Enable link-time optimisation if available
+# 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)
+		if(result)
 			set_target_properties(DoConfig PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
 		endif()
 	endif()