From 4ce57da5873e13076f2473710f7facbb3be3e1e2 Mon Sep 17 00:00:00 2001 From: Sqeaky Date: Thu, 28 Apr 2016 17:51:35 -0500 Subject: [PATCH 1/9] Added CMakeLists.txt and with that this builds correctly with GCC on Ubuntu. Though in source builds are not a good idea, I added the common CMake files and files to the .gitignore. --- .gitignore | 6 +- CMakeLists.txt | 226 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index 9cc9556..ae26667 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,8 @@ ipch/ *.suo *.opensdf .DS_STORE -Binaries/ \ No newline at end of file +Binaries/ +*~ +CMakeFiles/ +cmake_install.cmake +CMakeCache.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1ec39cf --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,226 @@ +################################################################################ +## -------------------------------------------------------------------------- ## +## ## +## (C) 2010-2016 Robot Developers ## +## See LICENSE for licensing info ## +## ## +## -------------------------------------------------------------------------- ## +################################################################################ + +################################################################################ +# Project Setup + +cmake_minimum_required(VERSION 2.8) +project(Robot) + +################################################################################ +# Tools + +# A tool for Troubleshooting, to make sure we got all the files +function(DisplayList Header ListToShow) + message(STATUS "\t${Header}") + foreach(ListItem ${ListToShow}) + message(STATUS "\t\t${ListItem}") + endforeach(ListItem ${ListToShow}) +endfunction(DisplayList) + +# Variables to allow us to change these things in the future +set(ProjectRootDir ${${PROJECT_NAME}_SOURCE_DIR}/) +set(ProjectBinaryDir ${${PROJECT_NAME}_BINARY_DIR}/) + +set(SourceDir "${ProjectRootDir}Source/") +set(HeaderDir "${ProjectRootDir}Source/") +set(TestSourceDir "${ProjectRootDir}Test/") +set(TestHeaderDir "${ProjectRootDir}Test/") + +################################################################################ +# Define Source Files + +# We could use a globbing expression, but is generally poor form, because +# eventually someone accidentally adds an incorrect file to their build and +# something hard to fix breaks. + +#file(GLOB SourceFileList ${SourceDir}*.cc) +#DisplayList("Source Files" "${SourceFileList}") + +#file(GLOB HeaderFileList ${HeaderDir}*.h) +#DisplayList("Header Files" "${HeaderFileList}") + +#file(GLOB TestSourceFileList ${TestSourceDir}*.cc) +#DisplayList("Test Source Files" "${TestSourceFileList}") + +#file(GLOB TestHeaderFileList ${TestHeaderDir}*.h) +#DisplayList("Test Header Files" "${TestHeaderFileList}") + +# +# When there is only one place to update file list it is not that painful: + +set(SourceFileList + "${SourceDir}Bounds.cc" + "${SourceDir}Clipboard.cc" + "${SourceDir}Color.cc" + "${SourceDir}Hash.cc" + "${SourceDir}Image.cc" + "${SourceDir}Keyboard.cc" + "${SourceDir}Memory.cc" + "${SourceDir}Module.cc" + "${SourceDir}Mouse.cc" + "${SourceDir}Point.cc" + "${SourceDir}Process.cc" + "${SourceDir}Range.cc" + "${SourceDir}Screen.cc" + "${SourceDir}Size.cc" + "${SourceDir}Timer.cc" + "${SourceDir}Window.cc" +) +DisplayList("Source Files" "${SourceFileList}") + +set(HeaderFileList + "${HeaderDir}Bounds.h" + "${HeaderDir}Bounds.h" + "${HeaderDir}Clipboard.h" + "${HeaderDir}Color.h" + "${HeaderDir}Enum.h" + "${HeaderDir}Global.h" + "${HeaderDir}Hash.h" + "${HeaderDir}Image.h" + "${HeaderDir}Keyboard.h" + "${HeaderDir}Memory.h" + "${HeaderDir}Module.h" + "${HeaderDir}Mouse.h" + "${HeaderDir}Point.h" + "${HeaderDir}Process.h" + "${HeaderDir}Range.h" + "${HeaderDir}Robot.h" + "${HeaderDir}Screen.h" + "${HeaderDir}Size.h" + "${HeaderDir}Timer.h" + "${HeaderDir}Types.h" + "${HeaderDir}Window.h" + +) +DisplayList("Header Files" "${HeaderFileList}") + +set(TestSourceFileList + "${TestSourceDir}Clipboard.cc" + "${TestSourceDir}Keyboard.cc" + "${TestSourceDir}Main.cc" + "${TestSourceDir}Memory.cc" + "${TestSourceDir}Mouse.cc" +# "${TestSourceDir}Peon.cc" + "${TestSourceDir}Process.cc" + "${TestSourceDir}Screen.cc" + "${TestSourceDir}Targa.cc" + "${TestSourceDir}Timer.cc" + "${TestSourceDir}Types.cc" + "${TestSourceDir}Window.cc" +) +DisplayList("Test Source Files" "${TestSourceFileList}") + +set(TestHeaderFileList + "${TestHeaderDir}Targa.h" + "${TestHeaderDir}Test.h" +) +DisplayList("Test Header Files" "${TestHeaderFileList}") + +################################################################################ +# Detect Platform + +set(SystemIsLinux OFF) +set(SystemIsWindows OFF) +set(SystemIsMacOSX OFF) + +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + message(STATUS "\t\tDetected OS as 'Linux'.") + set(SystemIsLinux ON) +endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") + message(STATUS "\t\tDetected OS as 'Windows'.") + set(SystemIsWindows ON) +endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") + +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + message(STATUS "\t\tDetected OS as 'Mac OS X'.") + set(SystemIsMacOSX ON) +endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + +################################################################################ +# Detect Compiler + +set(CompilerIsGCC OFF) +set(CompilerIsClang OFF) +set(CompilerIsIntel OFF) +set(CompilerIsMsvc OFF) + +set(CompilerDesignNix OFF) +set(CompilerDesignMS OFF) + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + message(STATUS "\t\tDetected compiler as 'GCC'.") + set(CompilerIsGCC ON) + set(CompilerDesignNix ON) +endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + message(STATUS "\t\tDetected compiler as 'Clang'.") + set(CompilerIsClang ON) + set(CompilerDesignNix ON) +endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + message(STATUS "\t\tDetected compiler as 'Intel'.") + set(CompilerIsIntel ON) + set(CompilerDesignNix ON) +endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + message(STATUS "\t\tDetected compiler as 'MSVC'.") + set(CompilerIsMsvc ON) + set(CompilerDesignMS ON) +endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + +################################################################################ +# Set up build + +option(BuildStatic "Set for Static library, unset for Dynamic library." ON) +if(BuildStatic) + set(BuildType "STATIC") +else(BuildStatic) + set(BuildType "SHARED") +endif(BuildStatic) + +include_directories( + "${HeaderDir}" + "${TestHeaderDir}" +) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") + +add_library(Robot "${BuildType}" "${TestSourceFileList}") +target_link_libraries(Robot rt X11 Xtst Xinerama) + +add_executable(Test "${SourceFileList}") +target_link_libraries(Test Robot) + +# TODO + +# install process +# d in debug build +# -DSHARED +# objective C++ +# pthreads +# Windows Linking +# All of Peon +# .BIN in the names +# Figure out any special VS specific logic. + + + + + + + + + + From d8a196e42993c1457a179d2cc711481da92472dc Mon Sep 17 00:00:00 2001 From: Sqeaky Date: Fri, 29 Apr 2016 12:00:26 -0500 Subject: [PATCH 2/9] Using CMake this builds on Ubuntu with GCC and windows with vs community 2015. --- CMakeLists.txt | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ec39cf..ca356b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,13 +10,14 @@ ################################################################################ # Project Setup -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.2) project(Robot) ################################################################################ # Tools -# A tool for Troubleshooting, to make sure we got all the files +# A tool for troubleshooting, to make sure we got all the files +# can be removed without affecting built binaries function(DisplayList Header ListToShow) message(STATUS "\t${Header}") foreach(ListItem ${ListToShow}) @@ -38,7 +39,10 @@ set(TestHeaderDir "${ProjectRootDir}Test/") # We could use a globbing expression, but is generally poor form, because # eventually someone accidentally adds an incorrect file to their build and -# something hard to fix breaks. +# something hard to fix breaks. When there is only one place to update file list +# it is not that painful. +# +# Here are four globbing expressions that appear to work. #file(GLOB SourceFileList ${SourceDir}*.cc) #DisplayList("Source Files" "${SourceFileList}") @@ -52,9 +56,6 @@ set(TestHeaderDir "${ProjectRootDir}Test/") #file(GLOB TestHeaderFileList ${TestHeaderDir}*.h) #DisplayList("Test Header Files" "${TestHeaderFileList}") -# -# When there is only one place to update file list it is not that painful: - set(SourceFileList "${SourceDir}Bounds.cc" "${SourceDir}Clipboard.cc" @@ -121,6 +122,7 @@ set(TestHeaderFileList "${TestHeaderDir}Targa.h" "${TestHeaderDir}Test.h" ) + DisplayList("Test Header Files" "${TestHeaderFileList}") ################################################################################ @@ -183,6 +185,7 @@ endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") ################################################################################ # Set up build +# When using the CMake-gui this creates a checkbox option(BuildStatic "Set for Static library, unset for Dynamic library." ON) if(BuildStatic) set(BuildType "STATIC") @@ -195,10 +198,22 @@ include_directories( "${TestHeaderDir}" ) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") +if(CompilerDesignNix) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") +endif(CompilerDesignNix) + +if(CompilerIsMsvc) + # Put msvc compiler flags here. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3") +endif(CompilerIsMsvc) + +set(LinkLibraries "") +if(SystemIsLinux) + set(LinkLibraries rt X11 Xtst Xinerama) +endif(SystemIsLinux) add_library(Robot "${BuildType}" "${TestSourceFileList}") -target_link_libraries(Robot rt X11 Xtst Xinerama) +target_link_libraries(Robot "${LinkLibraries}") add_executable(Test "${SourceFileList}") target_link_libraries(Test Robot) @@ -209,7 +224,7 @@ target_link_libraries(Test Robot) # d in debug build # -DSHARED # objective C++ -# pthreads + # Windows Linking # All of Peon # .BIN in the names From 3ed66866a8aa83d274f9b32053eb3692b0ea9bd0 Mon Sep 17 00:00:00 2001 From: Sqeaky Date: Fri, 29 Apr 2016 13:45:04 -0500 Subject: [PATCH 3/9] Adjusted CMakeLists.txt to allow building shared libraries on Linux and adjusted cmake output to make it easier to read. Building with shared libraries fails in visual studio with linker errors (probably easily resolved) build with static still works. --- CMakeLists.txt | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca356b5..16b3bff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,17 +133,17 @@ set(SystemIsWindows OFF) set(SystemIsMacOSX OFF) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - message(STATUS "\t\tDetected OS as 'Linux'.") + message(STATUS "\tDetected OS as 'Linux'.") set(SystemIsLinux ON) endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") - message(STATUS "\t\tDetected OS as 'Windows'.") + message(STATUS "\tDetected OS as 'Windows'.") set(SystemIsWindows ON) endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") - message(STATUS "\t\tDetected OS as 'Mac OS X'.") + message(STATUS "\tDetected OS as 'Mac OS X'.") set(SystemIsMacOSX ON) endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") @@ -159,25 +159,25 @@ set(CompilerDesignNix OFF) set(CompilerDesignMS OFF) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - message(STATUS "\t\tDetected compiler as 'GCC'.") + message(STATUS "\tDetected compiler as 'GCC'.") set(CompilerIsGCC ON) set(CompilerDesignNix ON) endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - message(STATUS "\t\tDetected compiler as 'Clang'.") + message(STATUS "\tDetected compiler as 'Clang'.") set(CompilerIsClang ON) set(CompilerDesignNix ON) endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") - message(STATUS "\t\tDetected compiler as 'Intel'.") + message(STATUS "\tDetected compiler as 'Intel'.") set(CompilerIsIntel ON) set(CompilerDesignNix ON) endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - message(STATUS "\t\tDetected compiler as 'MSVC'.") + message(STATUS "\tDetected compiler as 'MSVC'.") set(CompilerIsMsvc ON) set(CompilerDesignMS ON) endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") @@ -191,7 +191,9 @@ if(BuildStatic) set(BuildType "STATIC") else(BuildStatic) set(BuildType "SHARED") + add_definitions(-DBUILDING_ROBOT_SHARED) endif(BuildStatic) +message(STATUS "\tLibrary Build type '${BuildType}'.") include_directories( "${HeaderDir}" @@ -212,6 +214,10 @@ if(SystemIsLinux) set(LinkLibraries rt X11 Xtst Xinerama) endif(SystemIsLinux) +if(SystemIsLinux) + set(LinkLibraries rt X11 Xtst Xinerama) +endif(SystemIsLinux) + add_library(Robot "${BuildType}" "${TestSourceFileList}") target_link_libraries(Robot "${LinkLibraries}") @@ -224,7 +230,6 @@ target_link_libraries(Test Robot) # d in debug build # -DSHARED # objective C++ - # Windows Linking # All of Peon # .BIN in the names From d19296331fc8798dc3157322c382abebaf800409 Mon Sep 17 00:00:00 2001 From: Sqeaky Date: Fri, 29 Apr 2016 15:30:20 -0500 Subject: [PATCH 4/9] Fixed windows linking error, I accidentally was feeding tests the wrong list of source files, I corrected this and added target dependent preprocessor defintions. --- CMakeLists.txt | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16b3bff..ebe5bda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,7 +191,6 @@ if(BuildStatic) set(BuildType "STATIC") else(BuildStatic) set(BuildType "SHARED") - add_definitions(-DBUILDING_ROBOT_SHARED) endif(BuildStatic) message(STATUS "\tLibrary Build type '${BuildType}'.") @@ -209,6 +208,12 @@ if(CompilerIsMsvc) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3") endif(CompilerIsMsvc) +if(SystemIsWindows AND CompilerIsGCC) + # Put mingw compiler flags here. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ") +endif(SystemIsWindows AND CompilerIsGCC) + + set(LinkLibraries "") if(SystemIsLinux) set(LinkLibraries rt X11 Xtst Xinerama) @@ -218,22 +223,44 @@ if(SystemIsLinux) set(LinkLibraries rt X11 Xtst Xinerama) endif(SystemIsLinux) -add_library(Robot "${BuildType}" "${TestSourceFileList}") -target_link_libraries(Robot "${LinkLibraries}") +################################################################################ +# Make build targets + +# For those unfamiliar with CMake. When it spits out build files, like make +# files, ninja scripts or vs solutions, these are the top level objects +# presented to the developer. +# +# So a dev can type "make Robot" to build the library or can type "ninja Test" +# to build Test and everything it requires. +# +# If used to create files for IDEs like Code::Blocks, visual studio, or +# QtCreator these will show up appropriately as different projects or build +# targets. -add_executable(Test "${SourceFileList}") +add_library(Robot "${BuildType}" "${HeaderFileList}" "${SourceFileList}") +add_executable(Test "${TestHeaderFileList}" "${TestSourceFileList}") + +################################################################################ +# Link Build Targets + +target_link_libraries(Robot "${LinkLibraries}") target_link_libraries(Test Robot) -# TODO +if(NOT BuildStatic) + # Adds the definition when building robot + target_compile_definitions(Robot PRIVATE -DBUILDING_ROBOT_SHARED) + # Adds the definition when something else links against Robot + target_compile_definitions(Robot INTERFACE -DUSING_ROBOT_SHARED) +endif(NOT BuildStatic) + +# TODO # install process # d in debug build -# -DSHARED -# objective C++ -# Windows Linking +# objective C++ and other mac stuff # All of Peon # .BIN in the names -# Figure out any special VS specific logic. +# Figure out any special VS specific logic. I don't think is any beyound /W3 From 1da6c15061f42f58ac72c835dc269aac196d08ca Mon Sep 17 00:00:00 2001 From: Sqeaky Date: Fri, 29 Apr 2016 16:32:14 -0500 Subject: [PATCH 5/9] Added Preprocessor to distinguish MinGW from other windows compilers. --- Source/Global.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/Global.h b/Source/Global.h index 78667f5..d609a57 100644 --- a/Source/Global.h +++ b/Source/Global.h @@ -70,6 +70,19 @@ #endif +//----------------------------------------------------------------------------// +// Platforms // +//----------------------------------------------------------------------------// + +#if(_MSC_VER) + + #define VS_COMPILER + +#else + + #define _COMPILER + +#endif //----------------------------------------------------------------------------// // Export // From 5210aa6923b648410879c77ae5f3463eb9c3a973 Mon Sep 17 00:00:00 2001 From: Sqeaky Date: Fri, 29 Apr 2016 17:03:06 -0500 Subject: [PATCH 6/9] Fix ordering issues with headers during system header lookup --- CMakeLists.txt | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebe5bda..bee705c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,10 +194,15 @@ else(BuildStatic) endif(BuildStatic) message(STATUS "\tLibrary Build type '${BuildType}'.") -include_directories( - "${HeaderDir}" - "${TestHeaderDir}" -) +if(CompilerIsGCC) + add_definitions("-iquote${HeaderDir}" "-iquote${TestHeaderDir}") +else(CompilerIsGCC) + include_directories("${HeaderDir}" "${TestHeaderDir}") +endif(CompilerIsGCC) + +################################################################################ +# System Specific Settings + if(CompilerDesignNix) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") @@ -209,20 +214,11 @@ if(CompilerIsMsvc) endif(CompilerIsMsvc) if(SystemIsWindows AND CompilerIsGCC) - # Put mingw compiler flags here. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ") + # Put mingw compiler flags here. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif(SystemIsWindows AND CompilerIsGCC) -set(LinkLibraries "") -if(SystemIsLinux) - set(LinkLibraries rt X11 Xtst Xinerama) -endif(SystemIsLinux) - -if(SystemIsLinux) - set(LinkLibraries rt X11 Xtst Xinerama) -endif(SystemIsLinux) - ################################################################################ # Make build targets @@ -243,6 +239,15 @@ add_executable(Test "${TestHeaderFileList}" "${TestSourceFileList}") ################################################################################ # Link Build Targets +set(LinkLibraries "") +if(SystemIsLinux) + set(LinkLibraries rt X11 Xtst Xinerama) +endif(SystemIsLinux) + +if(SystemIsLinux) + set(LinkLibraries rt X11 Xtst Xinerama) +endif(SystemIsLinux) + target_link_libraries(Robot "${LinkLibraries}") target_link_libraries(Test Robot) From e3f5b4f807bd8f1eb450e4865621ccb540107ac2 Mon Sep 17 00:00:00 2001 From: Sqeaky Date: Fri, 29 Apr 2016 18:15:20 -0500 Subject: [PATCH 7/9] Swapped out custom int types with some some cstdint, This removed some compiler warnings and provides stronger guarantees going forward and in the event of platform changes. --- Source/Global.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Source/Global.h b/Source/Global.h index d609a57..bfe606d 100644 --- a/Source/Global.h +++ b/Source/Global.h @@ -80,7 +80,7 @@ #else - #define _COMPILER + #define NIX_COMPILER #endif @@ -158,17 +158,20 @@ // Types // //----------------------------------------------------------------------------// + +#include + ROBOT_NS_BEGIN -typedef signed char int8; // Signed 8-Bit integer -typedef signed short int16; // Signed 16-Bit integer -typedef signed int int32; // Signed 32-Bit integer -typedef signed long long int64; // Signed 64-Bit integer +typedef std::int8_t int8; // Signed 8-Bit integer +typedef std::int16_t int16; // Signed 16-Bit integer +typedef std::int32_t int32; // Signed 32-Bit integer +typedef std::int64_t int64; // Signed 64-Bit integer -typedef unsigned char uint8; // Unsigned 8-Bit integer -typedef unsigned short uint16; // Unsigned 16-Bit integer -typedef unsigned int uint32; // Unsigned 32-Bit integer -typedef unsigned long long uint64; // Unsigned 64-Bit integer +typedef std::uint8_t uint8; // Unsigned 8-Bit integer +typedef std::uint16_t uint16; // Unsigned 16-Bit integer +typedef std::uint32_t uint32; // Unsigned 32-Bit integer +typedef std::uint64_t uint64; // Unsigned 64-Bit integer typedef float real32; // 32-Bit float value typedef double real64; // 64-Bit float value From 9a04885a7a9170b2586ee4d17d787bda5450de7d Mon Sep 17 00:00:00 2001 From: Sqeaky Date: Fri, 29 Apr 2016 18:21:11 -0500 Subject: [PATCH 8/9] MinGW on Windows now links correctly - Fixed many double defintions of NOMINMAX, Replacing ROBOT_OS_WIN with a comiler checks where appropriate, Added linking details to CMakeLists.txt and fixed a few unique items. --- CMakeLists.txt | 13 +++--- Source/Clipboard.cc | 5 ++- Source/Enum.h | 4 +- Source/Keyboard.cc | 6 ++- Source/Memory.cc | 5 ++- Source/Mouse.cc | 11 ++++- Source/Process.cc | 99 +++++++++++++++++++++++++-------------------- Source/Process.h | 2 +- Source/Screen.cc | 5 ++- Source/Screen.h | 4 +- Source/Timer.cc | 13 ++++-- Source/Window.cc | 5 ++- Source/Window.h | 4 +- 13 files changed, 111 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bee705c..9555f2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,7 +215,7 @@ endif(CompilerIsMsvc) if(SystemIsWindows AND CompilerIsGCC) # Put mingw compiler flags here. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif(SystemIsWindows AND CompilerIsGCC) @@ -240,14 +240,15 @@ add_executable(Test "${TestHeaderFileList}" "${TestSourceFileList}") # Link Build Targets set(LinkLibraries "") -if(SystemIsLinux) - set(LinkLibraries rt X11 Xtst Xinerama) -endif(SystemIsLinux) if(SystemIsLinux) - set(LinkLibraries rt X11 Xtst Xinerama) + set(LinkLibraries ${LinkLibraries} rt X11 Xtst Xinerama) endif(SystemIsLinux) +if(SystemIsWindows AND CompilerIsGCC) + set(LinkLibraries ${LinkLibraries} Shlwapi psapi) +endif(SystemIsWindows AND CompilerIsGCC) + target_link_libraries(Robot "${LinkLibraries}") target_link_libraries(Test Robot) @@ -259,6 +260,8 @@ if(NOT BuildStatic) endif(NOT BuildStatic) + + # TODO # install process # d in debug build diff --git a/Source/Clipboard.cc b/Source/Clipboard.cc index fd50f5a..da43ce9 100644 --- a/Source/Clipboard.cc +++ b/Source/Clipboard.cc @@ -21,7 +21,10 @@ using std::string; #endif #ifdef ROBOT_OS_WIN - #define NOMINMAX + #ifndef NOMINMAX + #define NOMINMAX + #endif + #define WIN32_LEAN_AND_MEAN #include using std::wstring; diff --git a/Source/Enum.h b/Source/Enum.h index b0f835c..cf10126 100644 --- a/Source/Enum.h +++ b/Source/Enum.h @@ -18,7 +18,7 @@ #include ROBOT_NS_BEGIN -#ifdef ROBOT_OS_WIN +#ifdef VS_COMPILER #pragma warning (push) // Ignore the VS C4251 warning #pragma warning (disable:4251) @@ -148,7 +148,7 @@ template class Enum static ValueMap mMap; }; -#ifdef ROBOT_OS_WIN +#ifdef VS_COMPILER #pragma warning (pop) #endif diff --git a/Source/Keyboard.cc b/Source/Keyboard.cc index 035a757..7d36a97 100644 --- a/Source/Keyboard.cc +++ b/Source/Keyboard.cc @@ -34,8 +34,10 @@ using std::string; #endif #ifdef ROBOT_OS_WIN - #define NOMINMAX - #define WIN32_LEAN_AND_MEAN + #ifndef NOMINMAX + #define NOMINMAX + #endif + #include #endif diff --git a/Source/Memory.cc b/Source/Memory.cc index 86d9a5a..f87252f 100644 --- a/Source/Memory.cc +++ b/Source/Memory.cc @@ -55,7 +55,10 @@ using std::unordered_map; #endif #ifdef ROBOT_OS_WIN - #define NOMINMAX + #ifndef NOMINMAX + #define NOMINMAX + #endif + #define WIN32_LEAN_AND_MEAN #include diff --git a/Source/Mouse.cc b/Source/Mouse.cc index 1210c08..39f5bfc 100644 --- a/Source/Mouse.cc +++ b/Source/Mouse.cc @@ -30,10 +30,19 @@ #endif #ifdef ROBOT_OS_WIN - #define NOMINMAX + #ifndef NOMINMAX + #define NOMINMAX + #endif + #define WIN32_LEAN_AND_MEAN #include + #ifdef NIX_COMPILER + // To make up for MinGW's winuser.h being incomplete + // Do MinGW not have horizontal mouse wheels? + #define MOUSEEVENTF_HWHEEL 0x01000 + #endif + #endif ROBOT_NS_BEGIN diff --git a/Source/Process.cc b/Source/Process.cc index e0f982d..60202f7 100644 --- a/Source/Process.cc +++ b/Source/Process.cc @@ -62,7 +62,10 @@ using std::regex_match; #endif #ifdef ROBOT_OS_WIN - #define NOMINMAX + #ifndef NOMINMAX + #define NOMINMAX + #endif + #define WIN32_LEAN_AND_MEAN #include @@ -369,58 +372,68 @@ bool Process::Open (int32 pid) #endif #ifdef ROBOT_OS_WIN + #ifdef NIX_COMPILER + + // This could be implemented, but will require some work and + // linking to at least one extra library. + // http://stackoverflow.com/questions/15554380/mingw-with-old-winbase-h-file + return false; + + #endif + #ifdef VS_COMPILER + + mData->Handle = OpenProcess (PROCESS_VM_OPERATION | + PROCESS_VM_READ | PROCESS_QUERY_INFORMATION | + PROCESS_VM_WRITE | PROCESS_TERMINATE, FALSE, pid); + + // Check if handle is valid + if (mData->Handle != nullptr) + { + // Store the ProcID + mData->ProcID = pid; - mData->Handle = OpenProcess (PROCESS_VM_OPERATION | - PROCESS_VM_READ | PROCESS_QUERY_INFORMATION | - PROCESS_VM_WRITE | PROCESS_TERMINATE, FALSE, pid); + // Check if system 64-Bit + if (Process::IsSys64Bit()) + { + BOOL is32Bit = TRUE; + // Set whether process is 64-Bit + mData->Is64Bit = IsWow64Process + (mData->Handle, &is32Bit) && + is32Bit == FALSE; + } - // Check if handle is valid - if (mData->Handle != nullptr) - { - // Store the ProcID - mData->ProcID = pid; + #ifdef ROBOT_ARCH_32 + // Don't attach to x64 processes from x86 apps + if (mData->Is64Bit) { Close(); return false; } + #endif - // Check if system 64-Bit - if (Process::IsSys64Bit()) - { - BOOL is32Bit = TRUE; - // Set whether process is 64-Bit - mData->Is64Bit = IsWow64Process - (mData->Handle, &is32Bit) && - is32Bit == FALSE; - } + DWORD size = MAX_PATH; + TCHAR link [MAX_PATH]; + string name, path; - #ifdef ROBOT_ARCH_32 - // Don't attach to x64 processes from x86 apps - if (mData->Is64Bit) { Close(); return false; } - #endif + if (QueryFullProcessImageName + // Try and get process path name + (mData->Handle, 0, link, &size)) + { + path = _UTF8Encode (link); + // Convert any backslashes to normal slashes + replace (path.begin(), path.end(), '\\', '/'); - DWORD size = MAX_PATH; - TCHAR link [MAX_PATH]; - string name, path; + // Retrieve the file part of the path + auto last = path.find_last_of ('/'); + if (last == string::npos) name = path; + else name = path.substr (last + 1); - if (QueryFullProcessImageName - // Try and get process path name - (mData->Handle, 0, link, &size)) - { - path = _UTF8Encode (link); - // Convert any backslashes to normal slashes - replace (path.begin(), path.end(), '\\', '/'); - - // Retrieve the file part of the path - auto last = path.find_last_of ('/'); - if (last == string::npos) name = path; - else name = path.substr (last + 1); + // Store both the name and path values + mData->Name = name; mData->Path = path; + } - // Store both the name and path values - mData->Name = name; mData->Path = path; + return true; } - return true; - } - - return false; + return false; + #endif #endif } diff --git a/Source/Process.h b/Source/Process.h index 67a86e8..a6d01b9 100644 --- a/Source/Process.h +++ b/Source/Process.h @@ -24,7 +24,7 @@ ROBOT_NS_BEGIN class Module; class Window; -#ifdef ROBOT_OS_WIN +#ifdef VS_COMPILER #pragma warning (push) // Ignore the VS C4251 warning #pragma warning (disable:4251) diff --git a/Source/Screen.cc b/Source/Screen.cc index 031b9e5..803e250 100644 --- a/Source/Screen.cc +++ b/Source/Screen.cc @@ -31,7 +31,10 @@ #endif #ifdef ROBOT_OS_WIN - #define NOMINMAX + #ifndef NOMINMAX + #define NOMINMAX + #endif + #define WIN32_LEAN_AND_MEAN #include diff --git a/Source/Screen.h b/Source/Screen.h index ecb1c4e..01b3169 100644 --- a/Source/Screen.h +++ b/Source/Screen.h @@ -20,7 +20,7 @@ ROBOT_NS_BEGIN class Screen; -#ifdef ROBOT_OS_WIN +#ifdef VS_COMPILER #pragma warning (push) // Ignore the VS C4251 warning #pragma warning (disable:4251) @@ -89,7 +89,7 @@ class ROBOT_EXPORT Screen static ScreenList mScreens; // System screens deque }; -#ifdef ROBOT_OS_WIN +#ifdef VS_COMPILER #pragma warning (pop) #endif diff --git a/Source/Timer.cc b/Source/Timer.cc index aff484b..963c0a7 100644 --- a/Source/Timer.cc +++ b/Source/Timer.cc @@ -26,7 +26,10 @@ #endif #ifdef ROBOT_OS_WIN - #define NOMINMAX + #ifndef NOMINMAX + #define NOMINMAX + #endif + #define WIN32_LEAN_AND_MEAN #include @@ -218,8 +221,12 @@ uint64 Timer::GetCpuTime (void) return (time * 1000) / frequency; } - // Should never happen - return GetTickCount64(); + // Should never happen + #ifdef NIX_COMPILER + return GetTickCount(); + #else + return GetTickCount64(); + #endif #endif } diff --git a/Source/Window.cc b/Source/Window.cc index 204f146..28a5259 100644 --- a/Source/Window.cc +++ b/Source/Window.cc @@ -49,7 +49,10 @@ using std::regex_match; #endif #ifdef ROBOT_OS_WIN - #define NOMINMAX + #ifndef NOMINMAX + #define NOMINMAX + #endif + #define WIN32_LEAN_AND_MEAN #include using std::wstring; diff --git a/Source/Window.h b/Source/Window.h index e029c49..7cc6244 100644 --- a/Source/Window.h +++ b/Source/Window.h @@ -22,7 +22,7 @@ ROBOT_NS_BEGIN class Process; class Window; -#ifdef ROBOT_OS_WIN +#ifdef VS_COMPILER #pragma warning (push) // Ignore the VS C4251 warning #pragma warning (disable:4251) @@ -114,7 +114,7 @@ class ROBOT_EXPORT Window std::shared_ptr mData; // Shared information }; -#ifdef ROBOT_OS_WIN +#ifdef VS_COMPILER #pragma warning (pop) #endif From 45708058eaeb2693d9b91fc375afcf9145250785 Mon Sep 17 00:00:00 2001 From: Sqeaky Date: Mon, 2 May 2016 12:10:48 -0500 Subject: [PATCH 9/9] Cleaned up previous preprocessor for compiler detection and add support for detecting the 4 supported versions of msvc, Clang, GCC and MinGW. --- Source/Enum.h | 4 +- Source/Global.h | 31 ++++++++++++-- Source/Mouse.cc | 2 +- Source/Process.cc | 4 +- Source/Process.h | 2 +- Source/Screen.h | 4 +- Source/Timer.cc | 2 +- Source/Window.h | 4 +- Test/Process.cc | 102 ++++++++++++++++++++++++++++++++++++++++++++-- Test/Test.h | 11 ++++- 10 files changed, 147 insertions(+), 19 deletions(-) diff --git a/Source/Enum.h b/Source/Enum.h index cf10126..16274d1 100644 --- a/Source/Enum.h +++ b/Source/Enum.h @@ -18,7 +18,7 @@ #include ROBOT_NS_BEGIN -#ifdef VS_COMPILER +#ifdef ROBOT_VS_COMPILER_GROUP #pragma warning (push) // Ignore the VS C4251 warning #pragma warning (disable:4251) @@ -148,7 +148,7 @@ template class Enum static ValueMap mMap; }; -#ifdef VS_COMPILER +#ifdef ROBOT_VS_COMPILER_GROUP #pragma warning (pop) #endif diff --git a/Source/Global.h b/Source/Global.h index bfe606d..0e3847e 100644 --- a/Source/Global.h +++ b/Source/Global.h @@ -65,22 +65,45 @@ #else - #error Your operating system is not supported + #error Your operating system is not supported. #endif //----------------------------------------------------------------------------// -// Platforms // +// Compilers // //----------------------------------------------------------------------------// #if(_MSC_VER) - #define VS_COMPILER + #define ROBOT_VS_COMPILER_GROUP + + #if (_MSC_VER == 1900) + #define ROBOT_VS_COMPILER_2015_14 + #elif (_MSC_VER == 1800) + #define ROBOT_VS_COMPILER_2013_12 + #elif (_MSC_VER == 1700) + #define ROBOT_VS_COMPILER_2011_11 + #elif (_MSC_VER == 1600) + #define ROBOT_VS_COMPILER_2010_10 + #else + #error Your version of microsoft visual C++ is not supported. + #endif #else - #define NIX_COMPILER + #define ROBOT_NIX_COMPILER_GROUP + + #if defined(__clang__) + #define ROBOT_CLANG_COMPILER + #elif defined(__MINGW32__) + #define ROBOT_MINGW_COMPILER + #elif defined(__GNUC__) || defined(__GNUG__) + // Must be last because Clange will report as an old Version of GCC and + // who knows what MinGW will do that seems crazy but makes only on deep + // inspection of GCC interactions with windows. + #define ROBOT_GCC_COMPILER + #endif #endif diff --git a/Source/Mouse.cc b/Source/Mouse.cc index 39f5bfc..1051106 100644 --- a/Source/Mouse.cc +++ b/Source/Mouse.cc @@ -37,7 +37,7 @@ #define WIN32_LEAN_AND_MEAN #include - #ifdef NIX_COMPILER + #ifdef ROBOT_NIX_COMPILER_GROUP // To make up for MinGW's winuser.h being incomplete // Do MinGW not have horizontal mouse wheels? #define MOUSEEVENTF_HWHEEL 0x01000 diff --git a/Source/Process.cc b/Source/Process.cc index 60202f7..1bd498d 100644 --- a/Source/Process.cc +++ b/Source/Process.cc @@ -372,7 +372,7 @@ bool Process::Open (int32 pid) #endif #ifdef ROBOT_OS_WIN - #ifdef NIX_COMPILER + #ifdef ROBOT_NIX_COMPILER_GROUP // This could be implemented, but will require some work and // linking to at least one extra library. @@ -380,7 +380,7 @@ bool Process::Open (int32 pid) return false; #endif - #ifdef VS_COMPILER + #ifdef ROBOT_VS_COMPILER_GROUP mData->Handle = OpenProcess (PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_QUERY_INFORMATION | diff --git a/Source/Process.h b/Source/Process.h index a6d01b9..d495b53 100644 --- a/Source/Process.h +++ b/Source/Process.h @@ -24,7 +24,7 @@ ROBOT_NS_BEGIN class Module; class Window; -#ifdef VS_COMPILER +#ifdef ROBOT_VS_COMPILER_GROUP #pragma warning (push) // Ignore the VS C4251 warning #pragma warning (disable:4251) diff --git a/Source/Screen.h b/Source/Screen.h index 01b3169..e8ba1ea 100644 --- a/Source/Screen.h +++ b/Source/Screen.h @@ -20,7 +20,7 @@ ROBOT_NS_BEGIN class Screen; -#ifdef VS_COMPILER +#ifdef ROBOT_VS_COMPILER_GROUP #pragma warning (push) // Ignore the VS C4251 warning #pragma warning (disable:4251) @@ -89,7 +89,7 @@ class ROBOT_EXPORT Screen static ScreenList mScreens; // System screens deque }; -#ifdef VS_COMPILER +#ifdef ROBOT_VS_COMPILER_GROUP #pragma warning (pop) #endif diff --git a/Source/Timer.cc b/Source/Timer.cc index 963c0a7..e0964b4 100644 --- a/Source/Timer.cc +++ b/Source/Timer.cc @@ -222,7 +222,7 @@ uint64 Timer::GetCpuTime (void) } // Should never happen - #ifdef NIX_COMPILER + #ifdef ROBOT_NIX_COMPILER_GROUP return GetTickCount(); #else return GetTickCount64(); diff --git a/Source/Window.h b/Source/Window.h index 7cc6244..290db27 100644 --- a/Source/Window.h +++ b/Source/Window.h @@ -22,7 +22,7 @@ ROBOT_NS_BEGIN class Process; class Window; -#ifdef VS_COMPILER +#ifdef ROBOT_VS_COMPILER_GROUP #pragma warning (push) // Ignore the VS C4251 warning #pragma warning (disable:4251) @@ -114,7 +114,7 @@ class ROBOT_EXPORT Window std::shared_ptr mData; // Shared information }; -#ifdef VS_COMPILER +#ifdef ROBOT_VS_COMPILER_GROUP #pragma warning (pop) #endif diff --git a/Test/Process.cc b/Test/Process.cc index ec14a12..65e31a5 100644 --- a/Test/Process.cc +++ b/Test/Process.cc @@ -43,6 +43,101 @@ //////////////////////////////////////////////////////////////////////////////// +static bool TestPreproc (void) +{ + cout << "Warning: The next set of tests cannot be automated\n" + << " Please validate your platform and compiler\n\n"; + + // Platform + bool platform_linux = false; + bool platform_mac = false; + bool platform_windows = false; + +#ifdef ROBOT_OS_LINUX + platform_linux = true; +#endif +#ifdef ROBOT_OS_MAC + platform_mac = true; +#endif +#ifdef ROBOT_OS_WIN + platform_windows = true; +#endif + + cout << "Check Platform:" << boolalpha + << "\n\tLinux - " << platform_linux + << "\n\tMac OS X - " << platform_mac + << "\n\tWindows - " << platform_windows; + + // Compiler group + bool compiler_nix = false; + bool compiler_vc = false; + +#ifdef ROBOT_NIX_COMPILER_GROUP + compiler_nix = true; +#endif +#ifdef ROBOT_VS_COMPILER_GROUP + compiler_vc = true; +#endif + + cout << "\n\nCheck Compiler Group (type of args and pragmas accepted):" << boolalpha + << "\n\tUnix like - " << compiler_nix + << "\n\tMsvc like - " << compiler_vc << endl; + + + // Unixy compiler detection + bool compiler_clang = false; + bool compiler_mingw = false; + bool compiler_gcc = false; + +#ifdef ROBOT_CLANG_COMPILER + compiler_clang = true; +#endif +#ifdef ROBOT_MINGW_COMPILER + compiler_mingw = true; +#endif +#ifdef ROBOT_GCC_COMPILER + compiler_gcc = true; +#endif + + cout << "\n\nSpecific compiler:" << boolalpha + << "\n\tClang - " << compiler_clang + << "\n\tMinGW - " << compiler_mingw + << "\n\tGCC - " << compiler_gcc << endl; + + + // microsoft compiler detection + bool compiler_vc10 = false; + bool compiler_vc11 = false; + bool compiler_vc12 = false; + bool compiler_vc14 = false; + +#ifdef ROBOT_VS_COMPILER_2010_10 + compiler_vc10 = true; +#endif +#ifdef ROBOT_VS_COMPILER_2011_11 + compiler_vc11 = true; +#endif +#ifdef ROBOT_VS_COMPILER_2013_12 + compiler_vc12 = true; +#endif +#ifdef ROBOT_VS_COMPILER_2015_14 + compiler_vc14 = true; +#endif + + cout << "\n\nMsvc versions:" << boolalpha + << "\n\tMsvc 2010 - " << compiler_vc10 + << "\n\tMsvc 2011 - " << compiler_vc11 + << "\n\tMsvc 2012 - " << compiler_vc12 + << "\n\tMsvc 2014 - " << compiler_vc14 << endl; + + + WaitForEnter(); + + return true; + +} + + static bool TestInvalid (void) { Process p1; @@ -348,9 +443,10 @@ static bool TestGetList (void) bool TestProcess (void) { cout << "BEGIN PROCESS TESTING\n------------------------------\n"; - if (!TestInvalid()) { cout << ">> Invalid Failed\n\n"; return false; } + if (!TestPreproc()) { cout << ">> Preproc Failed\n\n"; return false; } + if (!TestInvalid()) { cout << ">> Invalid Failed\n\n"; return false; } if (!TestSelect ()) { cout << ">> Select Failed \n\n"; return false; } - if (!TestCurrent()) { cout << ">> Current Failed\n\n"; return false; } - if (!TestGetList()) { cout << ">> GetList Failed\n\n"; return false; } + if (!TestCurrent()) { cout << ">> Current Failed\n\n"; return false; } + if (!TestGetList()) { cout << ">> GetList Failed\n\n"; return false; } cout << ">> Success\n\n"; return true; } diff --git a/Test/Test.h b/Test/Test.h index b5e5827..b468713 100644 --- a/Test/Test.h +++ b/Test/Test.h @@ -23,9 +23,12 @@ using std::endl; using std::ostream; using std::istream; -using std:: uppercase; +using std::uppercase; using std::nouppercase; +#include +using std::boolalpha; + #include using std::setw; using std::setfill; @@ -171,7 +174,13 @@ inline ostream& operator << (ostream& out, const Bounds& bounds) return out; } +//////////////////////////////////////////////////////////////////////////////// +inline void WaitForEnter(const string& message = string("Press enter to continue.")) +{ + cout << endl << message << endl; + getchar(); +} //----------------------------------------------------------------------------// // Functions //