-Added support for Release and Debug for CMAKE_BUILD_TYPE
authorkoda
Sun, 28 Jun 2009 16:54:51 +0000
changeset 2203 6bd39d75e0dd
parent 2202 29508a2924c2
child 2204 526f8165acce
-Added support for Release and Debug for CMAKE_BUILD_TYPE -patch to OpenALbridge for invert_endianness
CMakeLists.txt
QTfrontend/CMakeLists.txt
gameServer/CMakeLists.txt
hedgewars/CMakeLists.txt
openalbridge/CMakeLists.txt
openalbridge/endianness.c
openalbridge/endianness.h
--- a/CMakeLists.txt	Sun Jun 28 16:44:04 2009 +0000
+++ b/CMakeLists.txt	Sun Jun 28 16:54:51 2009 +0000
@@ -17,11 +17,14 @@
 if(APPLE)
 set(CMAKE_INSTALL_PREFIX "Hedgewars.app/Contents/MacOS/") 
 set(DATA_INSTALL_DIR "../Resources/")
+set (target_dir ".")
 
 if(CMAKE_OSX_ARCHITECTURES MATCHES "i386;ppc7400" OR CMAKE_OSX_ARCHITECTURES MATCHES "ppc7400;i386" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386;ppc" OR CMAKE_OSX_ARCHITECTURES MATCHES "ppc;i386")
 	set(universal_build "1")
 	message("-- Building a Universal Application")
-endif(CMAKE_OSX_ARCHITECTURES MATCHES "i386;ppc7400" OR CMAKE_OSX_ARCHITECTURES MATCHES "ppc7400;i386" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386;ppc" OR CMAKE_OSX_ARCHITECTURES MATCHES "ppc;i386")
+endif()
+else(APPLE)
+set (target_dir "bin")
 endif(APPLE)
 
 if(DEFINED DATA_INSTALL_DIR)
@@ -47,6 +50,7 @@
 add_subdirectory(hedgewars)
 add_subdirectory(share)
 
+
 # CPack vars
 
 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hedgewars, a turn-based strategy")
--- a/QTfrontend/CMakeLists.txt	Sun Jun 28 16:44:04 2009 +0000
+++ b/QTfrontend/CMakeLists.txt	Sun Jun 28 16:54:51 2009 +0000
@@ -27,7 +27,9 @@
 # Done
 include_directories(.)
 
-set(CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS}")
+set(CMAKE_CXX_FLAGS "-Wall -pipe")
+set(CMAKE_CXX_FLAGS_RELEASE "-w -O2 -fomit-frame-pointer")
+set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
 
 if(WIN32 AND NOT UNIX)
 	set(HEDGEWARS_BINDIR ".")
@@ -207,11 +209,4 @@
 target_link_libraries(hedgewars
 	${HW_LINK_LIBS})
 
-
-if(APPLE)
-	set (target_dir ".")
-else(APPLE)
-	set (target_dir "bin")
-endif(APPLE)
-
 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hedgewars${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir})
--- a/gameServer/CMakeLists.txt	Sun Jun 28 16:44:04 2009 +0000
+++ b/gameServer/CMakeLists.txt	Sun Jun 28 16:54:51 2009 +0000
@@ -29,6 +29,21 @@
 	-odir ${CMAKE_CURRENT_BINARY_DIR}
 	-hidir ${CMAKE_CURRENT_BINARY_DIR})
 
+if( NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES "Release")
+set(ghc_flags
+	-w
+	-O2
+	${ghc_flags}
+)
+else()
+set(ghc_flags
+	-Wall
+	-debug
+	-dcore-lint
+	${ghc_flags}
+)
+endif()
+
 add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hedgewars-server${CMAKE_EXECUTABLE_SUFFIX}"
 		COMMAND "${ghc_executable}"
 		ARGS ${ghc_flags}
@@ -38,11 +53,4 @@
 
 add_custom_target(hedgewars-server ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hedgewars-server${CMAKE_EXECUTABLE_SUFFIX}")
 
-
-if(APPLE)
-	set (target_dir ".")
-else(APPLE)
-	set (target_dir "bin")
-endif(APPLE)
-
 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hedgewars-server${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir})
--- a/hedgewars/CMakeLists.txt	Sun Jun 28 16:44:04 2009 +0000
+++ b/hedgewars/CMakeLists.txt	Sun Jun 28 16:54:51 2009 +0000
@@ -69,6 +69,9 @@
 	FIND_PACKAGE(SDL)
 
 	if (SDL_FOUND)
+		set(CMAKE_C_FLAGS "-Wall -pipe")
+		set(CMAKE_C_FLAGS_RELEASE "-w -O2 -fomit-frame-pointer")
+		set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 
 		set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
 		include_directories(${SDL_INCLUDE_DIR})
@@ -76,14 +79,12 @@
 
 		add_library (SDLmain STATIC SDLMain.m)
 		set(engine_sources SDLmain ${engine_sources})
-
 	else (SDL_FOUND)
 		message(FATAL_ERROR "No SDL framework found!")
 	endif (SDL_FOUND)
 
 ENDIF(APPLE)
 
-
 string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
 if (fpc_version)
 	string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
@@ -94,7 +95,11 @@
 		message("Minimum required version of FreePascal is 2.2.0")
 	else (fpc_ver LESS "020200")
 		set(pascal_compiler ${fpc_executable})
-		set(pascal_compiler_flags ${noexecstack_flags} "-B" "-FE../bin" "-Fl../bin/" "-Fl../openalbridge/" "-Cs2000000" "-vwi" "-O2" ${hwengine_project})
+		if( NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES "Release")
+			set(pascal_compiler_flags ${noexecstack_flags} "-B" "-FE../bin" "-Fl../bin/" "-Cs2000000" "-vwi" "-O2" "-Xs" ${hwengine_project})
+		else()
+			set(pascal_compiler_flags ${noexecstack_flags} "-B" "-FE../bin" "-Fl../bin/" "-Cs2000000" "-vwi" "-O-" "-gl" ${hwengine_project})			
+		endif()
 	endif (fpc_ver LESS "020200")
 endif (fpc_version)
 
@@ -111,43 +116,34 @@
 		MAIN_DEPENDENCY ${hwengine_project}
 		DEPENDS openalbridge ${engine_sources}
 		)
-
-ELSE(NOT APPLE OR NOT universal_build MATCHES "1")
-
+ELSE()
 #these are the two dependencies for building a universal binary on Mac OS X
-add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.386"
+add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.386"
 		COMMAND "ppc386" 
 		ARGS ${pascal_compiler_flags} -ohwengine.386
 		MAIN_DEPENDENCY ${hwengine_project}
 		DEPENDS openalbridge ${engine_sources}
 		)
-add_custom_target(hwengine.386 ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.386")
+add_custom_target(hwengine.386 ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.386")
 
-add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.ppc"
+add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.ppc"
 		COMMAND "ppcppc"
 		ARGS ${pascal_compiler_flags} -ohwengine.ppc
 		MAIN_DEPENDENCY ${hwengine_project}
 		DEPENDS openalbridge ${engine_sources}
 		)
-add_custom_target(hwengine.ppc ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.ppc")
+add_custom_target(hwengine.ppc ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.ppc")
 
 #this is the command that bundles the two executables into one
-add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}"
+add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine"
 		COMMAND "lipo"
-		ARGS ${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.386 ${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.ppc -create -output ${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}
-		DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.386" "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}.ppc"
+		ARGS ${EXECUTABLE_OUTPUT_PATH}/hwengine.386 ${EXECUTABLE_OUTPUT_PATH}/hwengine.ppc -create -output ${EXECUTABLE_OUTPUT_PATH}/hwengine
+		DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.386" "${EXECUTABLE_OUTPUT_PATH}/hwengine.ppc"
 		)
-ENDIF(NOT APPLE OR NOT universal_build MATCHES "1")
+ENDIF()
 
 
 add_custom_target(hwengine ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}")
 
-
-if(APPLE)
-	set (target_dir ".")
-else(APPLE)
-	set (target_dir "bin")
-endif(APPLE)
-
 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hwengine${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir})
 
--- a/openalbridge/CMakeLists.txt	Sun Jun 28 16:44:04 2009 +0000
+++ b/openalbridge/CMakeLists.txt	Sun Jun 28 16:54:51 2009 +0000
@@ -3,8 +3,15 @@
 include_directories(${OPENAL_INCLUDE_DIR})
 include_directories(${OGGVORBIS_INCLUDE_DIRS})
 
+#set flag configuration for build type
+set(CMAKE_C_FLAGS "-Wall -pipe")
+set(CMAKE_C_FLAGS_RELEASE "-w -O2 -fomit-frame-pointer")
+set(CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG")
 
+#set destination directory for library
 set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
+
+#list of source files for libraries
 set(openal_src
 	openalwrap.c loaders.c endianness.c wrappers.c
 )
@@ -12,9 +19,8 @@
 #build a static library for human systems
 set (build_type STATIC)
 
-
 if(WIN32)
-#workaround for visualstudio
+#workaround for visualstudio (wants headers in the source list)
 	set(openal_src
 		openalwrap.h loaders.h endianness.h wrappers.h winstdint.h ${openal_src}
 	)
@@ -27,6 +33,7 @@
 	set (build_type SHARED)
 endif(WIN32)
 
+#compiles and links actual library
 add_library (openalbridge ${build_type} ${openal_src})
 
 if(WIN32)
--- a/openalbridge/endianness.c	Sun Jun 28 16:44:04 2009 +0000
+++ b/openalbridge/endianness.c	Sun Jun 28 16:54:51 2009 +0000
@@ -24,23 +24,7 @@
 	
 	//from big endian to little endian
 	int invert_endianness(int number){
-		uint8_t n1,n2,n3,n4;
-		uint32_t a1,a2,a3,a4;
-		uint32_t done = 0;
-		
-		n1 = number;
-		n2 = number >> 8;
-		n3 = number >> 16;
-		n4 = number >> 24;
-		
-		//printf("%X, %X, %X, %X\n", n1, n2, n3, n4);
-		a1 = (uint32_t) n1 << 24;
-		a2 = (uint32_t) n2 << 16;
-		a3 = (uint32_t) n3 << 8;
-		a4 = (uint32_t) n4;
-		done = a1 + a2 + a3 + a4;
-		//printf("%08X %08X %08X %08X = %08X\n", a1, a2, a3, a4, done);
-		return done;
+		return bswap_32(number);
 	}
 	
 #ifdef __CPLUSPLUS
--- a/openalbridge/endianness.h	Sun Jun 28 16:44:04 2009 +0000
+++ b/openalbridge/endianness.h	Sun Jun 28 16:54:51 2009 +0000
@@ -28,11 +28,27 @@
 #ifdef __CPLUSPLUS
 extern "C" {
 #endif 
-
+	
+#ifdef HAVE_BYTESWAP_H
+	/* use byteswap macros from the host system, hopefully optimized ones ;-) */
+#include <byteswap.h>
+#else
+	/* define our own version, simple, stupid, straight-forward... */
+	
+#define bswap_16(x)	((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
+	
+#define bswap_32(x)	((((x) & 0xFF000000) >> 24) | \
+					(((x) & 0x00FF0000) >> 8)  | \
+					(((x) & 0x0000FF00) << 8)  | \
+					(((x) & 0x000000FF) << 24) )
+	
+#endif
+	
+	
 #pragma once
-
-int invert_endianness(int number);
-
+	
+	int invert_endianness(int number);
+	
 #ifdef __CPLUSPLUS
 }
 #endif
\ No newline at end of file