diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..307622fe --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,158 @@ +cmake_minimum_required(VERSION 3.17) +project(stanford-cpp-library) + +# This CMake provides an example of how to use CMake to build the +# Stanford cpp library rather than a pro file. This allows the use +# of other IDE's such as CLion, VSC, etc. for development. + +# MinGW compiler lags, be conservative and use C++11 on all platforms +# rather than special case +set(CMAKE_CXX_STANDARD 11) + +set(CS106_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Library") + +find_package(Qt6 COMPONENTS Core REQUIRED) + +message(STATUS "Qt6 version: ${Qt6_VERSION}") + +# We try to make a best guess based on the OS, but you may +# need to manually specify the path to the Qt library. +if (WIN32) + +# find_qt_mingw64(QT_MINGW64_DIR) +# message("${QT_MINGW64_DIR}") + # MinGW is recommended for Windows. Please note that + # Qt is very picky about the MinGW compiler. Be sure + # you are using the most up to date version of MinGW. + set(CMAKE_PREFIX_PATH "C:/Qt/${Qt6_VERSION}/mingw_64") + + # Alternatively MSVC 2019 compiler can be used (Not tested) + # set(CMAKE_PREFIX_PATH "C:/Qt/6.7.2/msvc2019_64") +elseif (APPLE) + # Note that execute_process cannot expand ~/ for the home path. + # We instead find the home directory using the environment variable + set(CMAKE_PREFIX_PATH "$ENV{HOME}/Qt/${Qt6_VERSION}/macos") +else () + # UNIX/Linux case + # Same issue with expanding the home path + set(CMAKE_PREFIX_PATH "$ENV{HOME}/Qt/${Qt6_VERSION}/gcc_64") +endif () + +# Verify CMAKE_PREFIX_PATH exists +if (NOT EXISTS ${CMAKE_PREFIX_PATH}) + message(WARNING "The path ${CMAKE_PREFIX_PATH} does not exist " + "please verify the path to your Qt installation") +endif () + +set(CMAKE_AUTOMOC ON) # Automatic handling of the Qt Meta-Object Compiler (MOC) +set(CMAKE_AUTORCC ON) # Automatic handling of the Qt Resource compiler +set(CMAKE_AUTOUIC ON) # Automatic handling of the Qt UI code generator + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Network Multimedia) + +# Include all the cs106 library folders +include_directories("${CS106_LIB_PATH}") +include_directories("${CS106_LIB_PATH}/collections") +include_directories("${CS106_LIB_PATH}/console") +include_directories("${CS106_LIB_PATH}/graphics") +include_directories("${CS106_LIB_PATH}/io") +include_directories("${CS106_LIB_PATH}/private") +include_directories("${CS106_LIB_PATH}/resources") +include_directories("${CS106_LIB_PATH}/system") +include_directories("${CS106_LIB_PATH}/util") +include_directories("${CS106_LIB_PATH}/testing") + +# Copy resources folder into per-user writable data location from QtStandardPaths +if (WIN32) + set(QTP_EXE "qtpaths6.exe") +else() + set(QTP_EXE "qtpaths6") +endif () + +set (QT_INSTALL_BINS "${CMAKE_PREFIX_PATH}/bin") + +# Find writable data directory +execute_process(COMMAND "${QT_INSTALL_BINS}/${QTP_EXE}" "--writable-path" "GenericDataLocation" + OUTPUT_VARIABLE USER_DATA_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + +# Copy resources folder into data directory +set (SPL_DIR "${USER_DATA_DIR}/cs106") +file(COPY "${CS106_LIB_PATH}/resources" DESTINATION "${SPL_DIR}") + +# Used in build.h.in file to generate build.h file +set (SPL_VERSION "2023.1") +string(TIMESTAMP TODAY "%d/%m/%Y") +set (SPL_BUILD_DATE ${TODAY}) + +# Find user from environment variable +# Environment variable is either USERNAME or USER +if ("$ENV{USER}" STREQUAL "") + set (SPL_BUILD_USER $ENV{USERNAME}) +else () + set (SPL_BUILD_USER "$ENV{USER}") +endif () + +# Generate build.h file +add_compile_definitions(SPL_CMAKE_BUILD) +configure_file( + ${CS106_LIB_PATH}/private/build.h.in + ${CS106_LIB_PATH}/private/build.h + @ONLY +) + +# Create list of source files +file(GLOB LIBRARY_SRC CONFIGURE_DEPENDS + "${CS106_LIB_PATH}/collections/*.cpp" + "${CS106_LIB_PATH}/console/*.cpp" + "${CS106_LIB_PATH}/graphics/*.cpp" + "${CS106_LIB_PATH}/io/*.cpp" + "${CS106_LIB_PATH}/system/*.cpp" + "${CS106_LIB_PATH}/util/*.cpp" + "${CS106_LIB_PATH}/testing/*.cpp" + "${CS106_LIB_PATH}/private/*.cpp" +) + +# Create list of header files +file(GLOB LIBRARY_HEADER CONFIGURE_DEPENDS + "${CS106_LIB_PATH}/collections/*.h" + "${CS106_LIB_PATH}/console/*.h" + "${CS106_LIB_PATH}/graphics/*.h" + "${CS106_LIB_PATH}/io/*.h" + "${CS106_LIB_PATH}/system/*.h" + "${CS106_LIB_PATH}/util/*.h" + "${CS106_LIB_PATH}/testing/*.h" + "${CS106_LIB_PATH}/private/*.h" +) + +file(GLOB QT_RESOURCES ${CS106_LIB_PATH}/images.qrc) + +# We need to say what libraries we need from Qt6 +# Qt is very picky about the compiler version. +# Make sure you check to make sure your compiler +# is up to date. You have been warned! +set(QT_VERSION 6) +set(REQUIRED_LIBS Core Gui Widgets Network Multimedia) +set(REQUIRED_LIBS_QUALIFIED Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Network Qt6::Multimedia) + +qt_add_resources(RCC_SOURCES ${QT_RESOURCES}) + +# https://doc.qt.io/qt-6/cmake-get-started.html +# Create static library +qt_add_library(CS106_library STATIC + ${LIBRARY_SRC} + ${LIBRARY_HEADER} + ${RCC_SOURCES} +) + +# Link CS106 library to required Qt libraries +target_link_libraries(CS106_library PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Network Qt6::Multimedia) + +# Call CMakeLists.txt files of subdirectories +add_subdirectory(Welcome) +add_subdirectory(SPL-unit-tests) +add_subdirectory(SimpleTestGuide) + +# TODO: These need to be fixed/tested +# add_subdirectory(RandomClientTests/BugFixes) +# add_subdirectory(RandomClientTests/CompileFlags) +# add_subdirectory(RandomClientTests/ShadowTest) diff --git a/Library/images.qrc b/Library/images.qrc index 01368cf1..da79acf9 100644 --- a/Library/images.qrc +++ b/Library/images.qrc @@ -1,22 +1,20 @@ - - resources/splicon-large.png - - resources/about.gif - resources/background_color.gif - resources/clear_console.gif - resources/compare_output.gif - resources/copy.gif - resources/cut.gif - resources/font.gif - resources/load_input_script.gif - resources/paste.gif - resources/print.gif - resources/quit.gif - resources/save.gif - resources/save_as.gif - resources/select_all.gif - resources/text_color.gif - - - \ No newline at end of file + + resources/about.png + resources/background_color.png + resources/clear_console.png + resources/compare_output.png + resources/copy.png + resources/cut.png + resources/font.png + resources/load_input_script.png + resources/paste.png + resources/print.png + resources/quit.png + resources/save.png + resources/save_as.png + resources/select_all.png + resources/splicon-large.png + resources/text_color.png + + diff --git a/Library/private/build.h.in b/Library/private/build.h.in index 894476f1..cbeb12c7 100644 --- a/Library/private/build.h.in +++ b/Library/private/build.h.in @@ -1,8 +1,16 @@ #ifndef SPL_BUILD_H #define SPL_BUILD_H -#define SPL_VERSION \"$$SPL_VERSION\" -#define SPL_BUILD_DATE \"$$_DATE_\" -#define SPL_BUILD_USER \"$$(USER)\" +#ifndef SPL_CMAKE_BUILD + // Building from pro file + #define SPL_VERSION \"$$SPL_VERSION\" + #define SPL_BUILD_DATE \"$$_DATE_\" + #define SPL_BUILD_USER \"$$(USER)\" +#else + // Building from CMake + #define SPL_VERSION "@SPL_VERSION@" + #define SPL_BUILD_DATE "@SPL_BUILD_DATE@" + #define SPL_BUILD_USER "@SPL_BUILD_USER@" +#endif #endif \ No newline at end of file diff --git a/Library/private/filelibunix.cpp b/Library/private/filelibunix.cpp index aca94cb2..baaf8b8c 100644 --- a/Library/private/filelibunix.cpp +++ b/Library/private/filelibunix.cpp @@ -33,6 +33,14 @@ #include "strlib.h" namespace platform { + +bool filelib_isDirectory(const std::string& filename) { + struct stat fileInfo; + if (stat(filename.c_str(), &fileInfo) != 0) { + return false; + } + return S_ISDIR(fileInfo.st_mode) != 0; +} void filelib_createDirectory(const std::string& path) { std::string pathStr = path; @@ -132,14 +140,6 @@ std::string filelib_getTempDirectory() { return dir; } -bool filelib_isDirectory(const std::string& filename) { - struct stat fileInfo; - if (stat(filename.c_str(), &fileInfo) != 0) { - return false; - } - return S_ISDIR(fileInfo.st_mode) != 0; -} - bool filelib_isFile(const std::string& filename) { struct stat fileInfo; if (stat(filename.c_str(), &fileInfo) != 0) { diff --git a/Library/private/filelibwindows.cpp b/Library/private/filelibwindows.cpp index e6ecb170..40817f4a 100644 --- a/Library/private/filelibwindows.cpp +++ b/Library/private/filelibwindows.cpp @@ -33,6 +33,11 @@ namespace platform { +bool filelib_isDirectory(const std::string& filename) { + DWORD attr = GetFileAttributesA(filename.c_str()); + return attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY); +} + void filelib_createDirectory(const std::string& path) { std::string pathStr = path; if (endsWith(path, "\\")) { @@ -101,11 +106,6 @@ std::string filelib_getTempDirectory() { return std::string(path, n); } -bool filelib_isDirectory(const std::string& filename) { - DWORD attr = GetFileAttributesA(filename.c_str()); - return attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY); -} - // https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx bool filelib_isFile(const std::string& filename) { DWORD attr = GetFileAttributesA(filename.c_str()); diff --git a/Library/resources/about.png b/Library/resources/about.png new file mode 100644 index 00000000..dd92a95a Binary files /dev/null and b/Library/resources/about.png differ diff --git a/Library/resources/background_color.png b/Library/resources/background_color.png new file mode 100644 index 00000000..ac910f2c Binary files /dev/null and b/Library/resources/background_color.png differ diff --git a/Library/resources/clear_console.png b/Library/resources/clear_console.png new file mode 100644 index 00000000..ff10a317 Binary files /dev/null and b/Library/resources/clear_console.png differ diff --git a/Library/resources/compare_output.png b/Library/resources/compare_output.png new file mode 100644 index 00000000..f99ef89d Binary files /dev/null and b/Library/resources/compare_output.png differ diff --git a/Library/resources/copy.png b/Library/resources/copy.png new file mode 100644 index 00000000..a1a5fa36 Binary files /dev/null and b/Library/resources/copy.png differ diff --git a/Library/resources/cut.png b/Library/resources/cut.png new file mode 100644 index 00000000..7508ebc9 Binary files /dev/null and b/Library/resources/cut.png differ diff --git a/Library/resources/font.png b/Library/resources/font.png new file mode 100644 index 00000000..2a8432c3 Binary files /dev/null and b/Library/resources/font.png differ diff --git a/Library/resources/load_input_script.png b/Library/resources/load_input_script.png new file mode 100644 index 00000000..937f56ee Binary files /dev/null and b/Library/resources/load_input_script.png differ diff --git a/Library/resources/about.gif b/Library/resources/old_gif/about.gif similarity index 100% rename from Library/resources/about.gif rename to Library/resources/old_gif/about.gif diff --git a/Library/resources/background_color.gif b/Library/resources/old_gif/background_color.gif similarity index 100% rename from Library/resources/background_color.gif rename to Library/resources/old_gif/background_color.gif diff --git a/Library/resources/clear_console.gif b/Library/resources/old_gif/clear_console.gif similarity index 100% rename from Library/resources/clear_console.gif rename to Library/resources/old_gif/clear_console.gif diff --git a/Library/resources/compare_output.gif b/Library/resources/old_gif/compare_output.gif similarity index 100% rename from Library/resources/compare_output.gif rename to Library/resources/old_gif/compare_output.gif diff --git a/Library/resources/copy.gif b/Library/resources/old_gif/copy.gif similarity index 100% rename from Library/resources/copy.gif rename to Library/resources/old_gif/copy.gif diff --git a/Library/resources/cut.gif b/Library/resources/old_gif/cut.gif similarity index 100% rename from Library/resources/cut.gif rename to Library/resources/old_gif/cut.gif diff --git a/Library/resources/font.gif b/Library/resources/old_gif/font.gif similarity index 100% rename from Library/resources/font.gif rename to Library/resources/old_gif/font.gif diff --git a/Library/resources/load_input_script.gif b/Library/resources/old_gif/load_input_script.gif similarity index 100% rename from Library/resources/load_input_script.gif rename to Library/resources/old_gif/load_input_script.gif diff --git a/Library/resources/paste.gif b/Library/resources/old_gif/paste.gif similarity index 100% rename from Library/resources/paste.gif rename to Library/resources/old_gif/paste.gif diff --git a/Library/resources/print.gif b/Library/resources/old_gif/print.gif similarity index 100% rename from Library/resources/print.gif rename to Library/resources/old_gif/print.gif diff --git a/Library/resources/quit.gif b/Library/resources/old_gif/quit.gif similarity index 100% rename from Library/resources/quit.gif rename to Library/resources/old_gif/quit.gif diff --git a/Library/resources/save.gif b/Library/resources/old_gif/save.gif similarity index 100% rename from Library/resources/save.gif rename to Library/resources/old_gif/save.gif diff --git a/Library/resources/save_as.gif b/Library/resources/old_gif/save_as.gif similarity index 100% rename from Library/resources/save_as.gif rename to Library/resources/old_gif/save_as.gif diff --git a/Library/resources/select_all.gif b/Library/resources/old_gif/select_all.gif similarity index 100% rename from Library/resources/select_all.gif rename to Library/resources/old_gif/select_all.gif diff --git a/Library/resources/text_color.gif b/Library/resources/old_gif/text_color.gif similarity index 100% rename from Library/resources/text_color.gif rename to Library/resources/old_gif/text_color.gif diff --git a/Library/resources/paste.png b/Library/resources/paste.png new file mode 100644 index 00000000..c12af8d1 Binary files /dev/null and b/Library/resources/paste.png differ diff --git a/Library/resources/print.png b/Library/resources/print.png new file mode 100644 index 00000000..ace6b0c7 Binary files /dev/null and b/Library/resources/print.png differ diff --git a/Library/resources/quit.png b/Library/resources/quit.png new file mode 100644 index 00000000..966fbde7 Binary files /dev/null and b/Library/resources/quit.png differ diff --git a/Library/resources/save.png b/Library/resources/save.png new file mode 100644 index 00000000..0e659cba Binary files /dev/null and b/Library/resources/save.png differ diff --git a/Library/resources/save_as.png b/Library/resources/save_as.png new file mode 100644 index 00000000..0e659cba Binary files /dev/null and b/Library/resources/save_as.png differ diff --git a/Library/resources/select_all.png b/Library/resources/select_all.png new file mode 100644 index 00000000..dcba19c7 Binary files /dev/null and b/Library/resources/select_all.png differ diff --git a/Library/resources/text_color.png b/Library/resources/text_color.png new file mode 100644 index 00000000..ac910f2c Binary files /dev/null and b/Library/resources/text_color.png differ diff --git a/RandomClientTests/BugFixes/CMakeLists.txt b/RandomClientTests/BugFixes/CMakeLists.txt new file mode 100644 index 00000000..94852f8d --- /dev/null +++ b/RandomClientTests/BugFixes/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.17) +project(BugFixes) + +# Need the relative path to Library +set(CS106_LIB_PATH "../../Library") + +# Create the project executable +add_executable(${PROJECT_NAME} + bugfixes.cpp +) + +# link exe to CS106 library +target_link_libraries(${PROJECT_NAME} CS106_library) + +# student writes ordinary main() function, but it must be called within a +# wrapper main() that handles library setup/teardown. Rename student's +# to distinguish between the two main() functions and avoid symbol clash +# Ask Julie if you are curious why main->qMain->studentMain +target_compile_definitions(${PROJECT_NAME} PRIVATE main=qMain) +target_compile_definitions(${PROJECT_NAME} PRIVATE qMain=studentMain) + +find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED) +target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED}) + +if (WIN32) + if (CMAKE_BUILD_TYPE MATCHES "Debug") + set(EXTENSION "debug") + else () + set(EXTENSION "dll") + endif () + set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + endif () + endif () + if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows.dll") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/plugins/platforms/") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/plugins/platforms/qwindows.${EXTENSION}" + "$/plugins/platforms/") + endif () + foreach (QT_LIB ${REQUIRED_LIBS}) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION}" + "$") + endforeach (QT_LIB) +endif () \ No newline at end of file diff --git a/RandomClientTests/CompileFlags/CMakeLists.txt b/RandomClientTests/CompileFlags/CMakeLists.txt new file mode 100644 index 00000000..819cafb8 --- /dev/null +++ b/RandomClientTests/CompileFlags/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.17) +project(CompileFlags) + +# Need the relative path to Library +set(CS106_LIB_PATH "../../Library") + +# Create the project executable +add_executable(${PROJECT_NAME} + compile.cpp +) + +# link exe to CS106 library +target_link_libraries(${PROJECT_NAME} CS106_library) + +# student writes ordinary main() function, but it must be called within a +# wrapper main() that handles library setup/teardown. Rename student's +# to distinguish between the two main() functions and avoid symbol clash +# Ask Julie if you are curious why main->qMain->studentMain +target_compile_definitions(${PROJECT_NAME} PRIVATE main=qMain) +target_compile_definitions(${PROJECT_NAME} PRIVATE qMain=studentMain) + +find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED) +target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED}) + +if (WIN32) + if (CMAKE_BUILD_TYPE MATCHES "Debug") + set(EXTENSION "debug") + else () + set(EXTENSION "dll") + endif () + set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + endif () + endif () + if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows.dll") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/plugins/platforms/") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/plugins/platforms/qwindows.${EXTENSION}" + "$/plugins/platforms/") + endif () + foreach (QT_LIB ${REQUIRED_LIBS}) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION}" + "$") + endforeach (QT_LIB) +endif () \ No newline at end of file diff --git a/RandomClientTests/ShadowTest/CMakeLists.txt b/RandomClientTests/ShadowTest/CMakeLists.txt new file mode 100644 index 00000000..58573420 --- /dev/null +++ b/RandomClientTests/ShadowTest/CMakeLists.txt @@ -0,0 +1,55 @@ +cmake_minimum_required(VERSION 3.17) +project(ShadowTest) + +# Need the relative path to Library +set(CS106_LIB_PATH "../../Library") + +# Create the project executable +add_executable(${PROJECT_NAME} + main.cpp + strlib.cpp + strlib.h +) + +# link exe to CS106 library +target_link_libraries(${PROJECT_NAME} CS106_library) + +# student writes ordinary main() function, but it must be called within a +# wrapper main() that handles library setup/teardown. Rename student's +# to distinguish between the two main() functions and avoid symbol clash +# Ask Julie if you are curious why main->qMain->studentMain +target_compile_definitions(${PROJECT_NAME} PRIVATE main=qMain) +target_compile_definitions(${PROJECT_NAME} PRIVATE qMain=studentMain) + +find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED) +target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED}) + +if (WIN32) + if (CMAKE_BUILD_TYPE MATCHES "Debug") + set(EXTENSION "debug") + else () + set(EXTENSION "dll") + endif () + set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + endif () + endif () + if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows.dll") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/plugins/platforms/") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/plugins/platforms/qwindows.${EXTENSION}" + "$/plugins/platforms/") + endif () + foreach (QT_LIB ${REQUIRED_LIBS}) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION}" + "$") + endforeach (QT_LIB) +endif () \ No newline at end of file diff --git a/SPL-unit-tests/CMakeLists.txt b/SPL-unit-tests/CMakeLists.txt new file mode 100644 index 00000000..6dc4ceed --- /dev/null +++ b/SPL-unit-tests/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.17) +project(SPL-unit-tests) + +# Need the relative path to Library +set(CS106_LIB_PATH "../Library") + +file(GLOB TEST_SRC CONFIGURE_DEPENDS + "*.cpp" +) + +# Create the project executable +add_executable(${PROJECT_NAME} + ${TEST_SRC} +) + +# link exe to CS106 library +target_link_libraries(${PROJECT_NAME} CS106_library) + +# student writes ordinary main() function, but it must be called within a +# wrapper main() that handles library setup/teardown. Rename student's +# to distinguish between the two main() functions and avoid symbol clash +# Ask Julie if you are curious why main->qMain->studentMain +target_compile_definitions(${PROJECT_NAME} PRIVATE main=qMain) +target_compile_definitions(${PROJECT_NAME} PRIVATE qMain=studentMain) + +find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED) +target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED}) + +if (WIN32) + + # If the debug library versions do not exist, + # consider using the dll library version instead + set(EXTENSION "dll") + # set(EXTENSION "debug") + set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + endif () + endif () + if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows.dll") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/plugins/platforms/") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/plugins/platforms/qwindows.dll" + "$/plugins/platforms/") + endif () + foreach (QT_LIB ${REQUIRED_LIBS}) + if (NOT EXISTS "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION}") + message("${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION} does not exist") + endif () + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION}" + "$") + endforeach (QT_LIB) +endif () \ No newline at end of file diff --git a/SimpleTestGuide/CMakeLists.txt b/SimpleTestGuide/CMakeLists.txt new file mode 100644 index 00000000..5fc1a458 --- /dev/null +++ b/SimpleTestGuide/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.17) +project(SimpleTestGuide) + +# Need the relative path to Library +set(CS106_LIB_PATH "../Library") + +# Create the project executable +add_executable(${PROJECT_NAME} + main.cpp + simpletestguide.cpp + unittest.cpp +) + +# link exe to CS106 library +target_link_libraries(${PROJECT_NAME} CS106_library) + +# student writes ordinary main() function, but it must be called within a +# wrapper main() that handles library setup/teardown. Rename student's +# to distinguish between the two main() functions and avoid symbol clash +# Ask Julie if you are curious why main->qMain->studentMain +target_compile_definitions(${PROJECT_NAME} PRIVATE main=qMain) +target_compile_definitions(${PROJECT_NAME} PRIVATE qMain=studentMain) + +find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED) +target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED}) + +if (WIN32) + + # If the debug library versions do not exist, + # consider using the dll library version instead + set(EXTENSION "dll") + # set(EXTENSION "debug") + set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + endif () + endif () + if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows.dll") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/plugins/platforms/") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/plugins/platforms/qwindows.dll" + "$/plugins/platforms/") + endif () + foreach (QT_LIB ${REQUIRED_LIBS}) + if (NOT EXISTS "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION}") + message("${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION} does not exist") + endif () + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION}" + "$") + endforeach (QT_LIB) +endif () \ No newline at end of file diff --git a/Welcome/CMakeLists.txt b/Welcome/CMakeLists.txt new file mode 100644 index 00000000..cb94a58e --- /dev/null +++ b/Welcome/CMakeLists.txt @@ -0,0 +1,59 @@ +cmake_minimum_required(VERSION 3.17) +project(Welcome) + +# Need the relative path to Library +set(CS106_LIB_PATH "../Library") + +# Link CS106 library to required Qt libraries +target_link_libraries(CS106_library PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Network) + +# Create the project executable +add_executable(${PROJECT_NAME} + welcome.cpp +) + +# link exe to CS106 library +target_link_libraries(${PROJECT_NAME} CS106_library) + +# student writes ordinary main() function, but it must be called within a +# wrapper main() that handles library setup/teardown. Rename student's +# to distinguish between the two main() functions and avoid symbol clash +# Ask Julie if you are curious why main->qMain->studentMain +target_compile_definitions(${PROJECT_NAME} PRIVATE main=qMain) +target_compile_definitions(${PROJECT_NAME} PRIVATE qMain=studentMain) + +find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED) +target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED}) + +if (WIN32) + + # If the debug library versions do not exist, + # consider using the dll library version instead + set(EXTENSION "dll") + # set(EXTENSION "debug") + set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + endif () + endif () + if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows.dll") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/plugins/platforms/") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/plugins/platforms/qwindows.dll" + "$/plugins/platforms/") + endif () + foreach (QT_LIB ${REQUIRED_LIBS}) + if (NOT EXISTS "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION}") + message("${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION} does not exist") + endif () + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}.${EXTENSION}" + "$") + endforeach (QT_LIB) +endif () \ No newline at end of file