Start move to clean CMake.

This commit is contained in:
Mikael CAPELLE
2024-07-11 13:40:59 +02:00
parent 4f32506570
commit 4f7aeaf4f1
7 changed files with 54 additions and 73 deletions
+17 -33
View File
@@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.16)
option(copy_dll_to_binary_dir "Will copy libbsarch DLL to the binary directory. May not work if libbsarch is used as a subproject" ON)
# Project
project(libbsarch CXX)
@@ -11,20 +9,17 @@ add_library(libbsarch SHARED
src/libbsarch.cpp
src/libbsarch.def
)
set_target_properties(libbsarch PROPERTIES DEBUG_POSTFIX "d")
target_include_directories(libbsarch PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/dds)
target_compile_features(libbsarch PRIVATE cxx_std_11)
# Preprocessor definitions
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(MSVC)
target_compile_options(libbsarch PRIVATE /W3 /MDd /Od /EHsc)
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(MSVC)
target_compile_options(libbsarch PRIVATE /W3 /Zi /EHsc)
endif()
# preprocessor definitions
if(MSVC)
target_compile_options(libbsarch PRIVATE
/W3 /EHsc /MP
$<$<CONFIG:DEBUG>:/MDd /Od>
$<$<CONFIG:RELEASE>:/Zi>
)
endif()
target_compile_definitions(libbsarch PRIVATE BSARCH_DLL_EXPORT)
@@ -60,8 +55,15 @@ add_library(libbsarch_OOP STATIC
src/utils/string_convert.cpp
src/utils/string_convert.hpp
)
set_target_properties(libbsarch_OOP PROPERTIES
DEBUG_POSTFIX "d"
CXX_STANDARD 17
)
target_include_directories(libbsarch_OOP PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/dds)
if (MSVC)
target_compile_options(libbsarch_OOP PRIVATE /MP)
endif()
## Copying the corresponding DLL ##
@@ -76,30 +78,12 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
message("libbsarch: using 32bits DLL")
endif()
if(copy_dll_to_binary_dir)
#Finding debug or release
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
set(libbsarch_dll_path "${lib_delphi}/libbsarchd.dll")
else()
set(libbsarch_dll_path "${lib_delphi}/libbsarch.dll")
endif()
#Actually copying the DLL
add_custom_command(TARGET libbsarch POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${libbsarch_dll_path}
${CMAKE_BINARY_DIR}/libbsarch.dll)
message("libbsarch: Copying the DLL to ${CMAKE_BINARY_DIR}/libbsarch.dll")
endif()
#Adding Qt support
if(Qt6_FOUND)
message("libbsarch: Qt6 found, enabling Qt support")
target_link_libraries(libbsarch_OOP PUBLIC Qt::Core)
target_compile_definitions(libbsarch PUBLIC "QT")
target_compile_definitions(libbsarch_OOP PUBLIC "QT")
target_compile_definitions(libbsarch PUBLIC "LIBBSARCH_QT_SUPPORT")
target_compile_definitions(libbsarch_OOP PUBLIC "LIBBSARCH_QT_SUPPORT")
endif()
target_link_libraries(libbsarch_OOP PUBLIC libbsarch)
target_compile_features(libbsarch_OOP PRIVATE cxx_std_17)
target_compile_definitions(libbsarch_OOP PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
+1 -1
View File
@@ -44,7 +44,7 @@ convertible_ostream::operator std::wostream &()
return std::wcout;
}
#ifdef QT
#ifdef LIBBSARCH_QT_SUPPORT
convertible_ostream::operator QDebug()
{
return qDebug();
+1 -1
View File
@@ -29,7 +29,7 @@ public:
operator std::ostream &();
operator std::wostream &();
#ifdef QT
#ifdef LIBBSARCH_QT_SUPPORT
operator QDebug();
convertible_ostream &operator<<(const QString &rh);
#endif
+24 -26
View File
@@ -40,16 +40,6 @@ convertible_string::convertible_string(wchar_t const *wval_array, bool to_native
this->to_native_path();
}
#ifdef QT
convertible_string::convertible_string(const QString &qsvalue, bool to_native_path)
: str_(to_string(qsvalue))
, auto_convert_to_native_path(to_native_path)
{
if (auto_convert_to_native_path)
this->to_native_path();
}
#endif
/* assignment operators */
convertible_string &convertible_string::operator=(const std::string &value)
{
@@ -74,16 +64,6 @@ convertible_string &convertible_string::operator=(const wchar_t *wvalue)
return *this;
}
#ifdef QT
convertible_string &convertible_string::operator=(const QString &qsvalue)
{
str_ = to_string(qsvalue);
if (auto_convert_to_native_path)
this->to_native_path();
return *this;
}
#endif
/* implicit conversion operators */
convertible_string::operator std::string() const
{
@@ -100,12 +80,6 @@ convertible_string::operator const wchar_t *() const
wcscpy_s(wchar_array, wstr.length() + 1, wstr.c_str());
return wchar_array;
}
#ifdef QT
convertible_string::operator QString() const
{
return to_qstring(str_);
}
#endif
/* Util */
bool convertible_string::remove_substring(const convertible_string &sub_str)
@@ -125,4 +99,28 @@ convertible_string &convertible_string::to_native_path()
str_ = path.make_preferred().string();
return *this;
}
#ifdef LIBBSARCH_QT_SUPPORT
convertible_string::convertible_string(const QString &qsvalue, bool to_native_path)
: str_(to_string(qsvalue))
, auto_convert_to_native_path(to_native_path)
{
if (auto_convert_to_native_path)
this->to_native_path();
}
convertible_string &convertible_string::operator=(const QString &qsvalue)
{
str_ = to_string(qsvalue);
if (auto_convert_to_native_path)
this->to_native_path();
return *this;
}
convertible_string::operator QString() const
{
return to_qstring(str_);
}
#endif
} // namespace libbsarch
+7 -9
View File
@@ -6,11 +6,12 @@
//See https://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string
#include "string_convert.hpp"
#ifdef QT
#ifdef LIBBSARCH_QT_SUPPORT
#include <QString>
#endif
#include "string_convert.hpp"
namespace libbsarch {
class convertible_string
{
@@ -23,23 +24,20 @@ public:
convertible_string(const char *const val_array, bool to_native_path = true);
convertible_string(const std::wstring &wvalue, bool to_native_path = true);
convertible_string(const wchar_t *const wval_array, bool to_native_path = true);
#ifdef QT
convertible_string(const QString &qsvalue, bool to_native_path = true);
#endif
/* assignment operators */
convertible_string &operator=(const std::string &value);
convertible_string &operator=(const std::wstring &wvalue);
convertible_string &operator=(const wchar_t *wvalue);
#ifdef QT
convertible_string &operator=(const QString &qsvalue);
#endif
/* implicit conversion operators */
operator std::string() const;
operator std::wstring() const;
operator const wchar_t *() const;
#ifdef QT
#ifdef LIBBSARCH_QT_SUPPORT
convertible_string(const QString &qsvalue, bool to_native_path = true);
convertible_string &operator=(const QString &qsvalue);
operator QString() const;
#endif
+1 -1
View File
@@ -5,7 +5,7 @@
#include "string_convert.hpp"
namespace libbsarch {
#ifdef QT
#ifdef LIBBSARCH_QT_SUPPORT
std::wstring to_wstring(const QString &str)
{
#ifdef _MSC_VER
+3 -2
View File
@@ -4,15 +4,16 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#pragma once
#ifdef QT
#ifdef LIBBSARCH_QT_SUPPORT
#include <QDebug>
#endif
#include <codecvt>
#include <locale>
#include <string>
namespace libbsarch {
#ifdef QT
#ifdef LIBBSARCH_QT_SUPPORT
std::wstring to_wstring(const QString &str);
std::string to_string(const QString &str);
QString to_qstring(const std::string &str);