Skip to content

Commit

Permalink
fs and thread ok
Browse files Browse the repository at this point in the history
  • Loading branch information
bha-evs committed Jan 9, 2024
1 parent d2f7cc3 commit 59320df
Show file tree
Hide file tree
Showing 21 changed files with 309 additions and 1,943 deletions.
96 changes: 75 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
#
# History: 05 June 2004: BHA: Initial version
#compile with emscripten:
#cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=C:/pro/emsdk/upstream/emscripten/cmake/Modules/Platform/emscripten.cmake -DCMAKE_TOOLCHAIN_FILE=C:/pro/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=wasm32-emscripten -DBUILD_SHARED_LIBS=OFF -DCMAKE_GENERATOR=Ninja -DCMAKE_BUILD_TYPE=Debug -SC:/pro/github/bofstd -BC:/bld/bofstd-web -DCMAKE_CROSSCOMPILING_EMULATOR=C:/pro/emsdk/node/16.20.0_64bit/bin/node.exe -G Ninja
#cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=C:/pro/emsdk/upstream/emscripten/cmake/Modules/Platform/emscripten-pthread.cmake -DCMAKE_TOOLCHAIN_FILE=C:/pro/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=wasm32-emscripten -DBUILD_SHARED_LIBS=OFF -DCMAKE_GENERATOR=Ninja -DCMAKE_BUILD_TYPE=Debug -SC:/pro/github/bofstd -BC:/bld/bofstd-web -DCMAKE_CROSSCOMPILING_EMULATOR=C:/pro/emsdk/node/16.20.0_64bit/bin/node.exe -G Ninja
#run
#cd C:\bld\bofstd-web\binaries\bin
#node AppBofStd.js
#RUN: launch http server
#emrun --browser chrome --port 8080 --serve_after_close --serve_after_exit C:\bld\bofstd-web\binaries\bin
#select .html file
#compil windows:
#cmake -DCMAKE_TOOLCHAIN_FILE=C:/pro/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DVCPKG_HOST_TRIPLET=x64-windows-static -DBUILD_SHARED_LIBS=OFF -DVCPKG_OVERLAY_PORTS=C:/pro/github/onbings-vcpkg-registry/ports -DCMAKE_INSTALL_PREFIX=C:\tmp\bofstd -B C:/bld/bofstd -S C:/pro/github/bofstd
#cmake -DCMAKE_TOOLCHAIN_FILE=C:/pro/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DVCPKG_HOST_TRIPLET=x64-windows-static -DBUILD_SHARED_LIBS=OFF -DVCPKG_OVERLAY_PORTS=C:/pro/github/onbings-vcpkg-registry/ports -DCMAKE_INSTALL_PREFIX=C:\tmp\bofstd -SC:/pro/github/bofstd -BC:/bld/bofstd-win
#cmake --build . --config Release -- -j 16
#cmake --install . --config Debug
cmake_minimum_required(VERSION 3.25)
Expand All @@ -29,8 +29,9 @@ if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "You cannot generate your binary solution into your source directory !")
endif()

include(vcpkg/fixup_vs_crt.cmake)
include(vcpkg/vcpkg_install.cmake)
include(cmake/fixup_vs_crt.cmake)
include(cmake/vcpkg_install.cmake)
include(cmake/fetch_content.cmake)

# Programs used for integration testing should not be included
# in code coverage computation as they are test programs themselves.
Expand All @@ -47,15 +48,22 @@ string(REPLACE "-" "_" PROJECT_NAME_LOWER_UNDERSCORE ${PROJECT_NAME_LOWER})
string(REPLACE "-" "_" PROJECT_NAME_UPPER_UNDERSCORE ${PROJECT_NAME_UPPER})

option(BOFSTD_BUILD_EXAMPLES "Build example of BofStd project" ON)
if (EMSCRIPTEN)
option(BOFSTD_BUILD_TESTS "Build units tests of BofStd project" OFF)
else()
option(BOFSTD_BUILD_TESTS "Build units tests of BofStd project" ON)
endif()
option(BOFSTD_BUILD_TOOLS "Build tools of BofStd project" OFF)
option(BOFSTD_ENABLE_VERSIONING "Enable library versioning naming scheme for BofStd libraries" ON)
option(BOFSTD_FORCE_EXPORT_ALL "Force exporting all symbols of BofStd libraries (for shared library)" OFF)

#EMSCRIPTEN
option(BOFSTD_EMSCRIPTEN_HTML "EMSCRIPTEN generateq .wasm and .js file. If you set this option to ON we also generate an html container" OFF)
set(BOFSTD_EMSCRIPTEN_MEMORY 256MB CACHE STRING "Specify emscripten default memory size")
message("emscripten default memory size: ${BOFSTD_EMSCRIPTEN_MEMORY}")
set(BOFSTD_EMSCRIPTEN_STACK 8MB CACHE STRING "Specify emscripten default stack size")
message("emscripten default stack size: ${BOFSTD_EMSCRIPTEN_STACK}")
set(BOFSTD_EMSCRIPTEN_THREAD_POOL 4 CACHE STRING "Specify emscripten default thread pool size")
message("emscripten default thread pool size: ${BOFSTD_EMSCRIPTEN_THREAD_POOL}")
set(BOFSTD_EMSCRIPTEN_FS_ROOT_DIR ${CMAKE_BINARY_DIR}/binaries/bin/data CACHE STRING "Specify emscripten preload file dir")
#set(BOFSTD_EMSCRIPTEN_FS_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/tests/data CACHE STRING "Specify emscripten preload file dir")
message("emscripten preload file directory: ${BOFSTD_EMSCRIPTEN_FS_ROOT_DIR}")
#em++: error: 'C:\pro\emsdk\upstream\emscripten\tools\file_packager.bat binaries\bin\app_bofstd.data --from-emcc --preload C:/bld/bofstd-web/binaries/bin/data' failed (returned 1)
# ===============================
# == NON TRANSITIVE PROPERTIES ==
# ===============================
Expand All @@ -69,27 +77,65 @@ option(BOFSTD_FORCE_EXPORT_ALL "Force exporting all symbols of BofStd libraries
# Disable compiler extension to maximize portability
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_COLOR_MAKEFILE ON)
SET(CMAKE_VERBOSE_MAKEFILE ON)
# set(CMAKE_DEBUG_POSTFIX _d)
if (EMSCRIPTEN)
message("===EMSCRIPTEN==============")
#comment the following if you just use node to test as the html gen takes time
# set(CMAKE_EXECUTABLE_SUFFIX ".html") #to generate .html in addition to .js and .wasm
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s NO_DISABLE_EXCEPTION_CATCHING -s ALLOW_MEMORY_GROWTH -s TOTAL_STACK=8388608")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_DISABLE_EXCEPTION_CATCHING -s ALLOW_MEMORY_GROWTH -s TOTAL_STACK=8388608")

# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -sPTHREAD_POOL_SIZE=4") #-sPTHREAD_POOL_SIZE=4") # -sPROXY_TO_PTHREAD -sASYNCIFY") # -sUSE_PTHREADS=1) # -sSHARED_MEMORY=1")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -sPTHREAD_POOL_SIZE=4") #-sUSE_PTHREADS=1") #-sPTHREAD_POOL_SIZE=4") # -sPROXY_TO_PTHREAD -sASYNCIFY") # -sUSE_PTHREADS=1) # -sSHARED_MEMORY=1")
#FS layout:
#Root: /tmp
#Root: /home
#Root: /dev
#Root: /proc
#Root: /C:
#home: '/home/web_user/' Sz 4096 Ft 2
#dev: '/dev/shm/tmp/' Sz 4096 Ft 2
#dev: '/dev/shm/' Sz 4096 Ft 2
#proc: '/proc/self/' Sz 4096 Ft 2
#file: '/C:/bld/bofstd-web/binaries/bin/data/colorbar.jpg' Sz 9830 Ft 1
#file: '/C:/bld/bofstd-web/binaries/bin/data/colorbar.png' Sz 1483 Ft 1
#...
#file: '/C:/bld/bofstd-web/binaries/bin/data/' Sz 4096 Ft 2
#file: '/C:/bld/bofstd-web/binaries/bin/' Sz 4096 Ft 2
#file: '/C:/bld/bofstd-web/binaries/' Sz 4096 Ft 2
#file: '/C:/bld/bofstd-web/' Sz 4096 Ft 2
#file: '/C:/bld/' Sz 4096 Ft 2
#
# with TEST(Fs_Test, FileLayout)
# pwd is /TstRoot/
# file: '/TstRoot/SubDir_0/Level1/Level2/File_000000.2.ren' Sz 2000 Ft 1
# file: '/TstRoot/SubDir_0/Level1/Level2/File_000000.2' Sz 2000 Ft 1
# file: '/TstRoot/SubDir_0/Level1/Level2/' Sz 4096 Ft 2
# file: '/TstRoot/SubDir_0/Level1/' Sz 4096 Ft 2
# file: '/TstRoot/SubDir_0/' Sz 4096 Ft 2
#
#sometime it cannot find pthread. If i force it in C:\Program Files\CMake\share\cmake-3.28\Modules\FindThreads.cmake it works...
#macro(_threads_check_libc)
# set(CMAKE_THREAD_LIBS_INIT "")
# set(Threads_FOUND TRUE)
if(BOFSTD_BUILD_TOOLS)
message("===EMSCRIPTEN=== Add .html to .wasm and .js files")
set(CMAKE_EXECUTABLE_SUFFIX ".html") #to generate .html in addition to .js and .wasm
else()
message("===EMSCRIPTEN=== Generate .wasm and .js files")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -s NO_DISABLE_EXCEPTION_CATCHING")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -s NO_DISABLE_EXCEPTION_CATCHING")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s TOTAL_STACK=${BOFSTD_EMSCRIPTEN_STACK} -s TOTAL_MEMORY=${BOFSTD_EMSCRIPTEN_MEMORY} -s PTHREAD_POOL_SIZE=${BOFSTD_EMSCRIPTEN_THREAD_POOL} -s PROXY_TO_PTHREAD --preload-file ${BOFSTD_EMSCRIPTEN_FS_ROOT_DIR}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s TOTAL_STACK=${BOFSTD_EMSCRIPTEN_STACK} -s TOTAL_MEMORY=${BOFSTD_EMSCRIPTEN_MEMORY} -s PTHREAD_POOL_SIZE=${BOFSTD_EMSCRIPTEN_THREAD_POOL} --embed-file ${BOFSTD_EMSCRIPTEN_FS_ROOT_DIR}")
#-sPROXY_TO_PTHREAD -s ASYNCIFY
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s TOTAL_STACK=${BOFSTD_EMSCRIPTEN_STACK} -s TOTAL_MEMORY=${BOFSTD_EMSCRIPTEN_MEMORY} -s PTHREAD_POOL_SIZE=${BOFSTD_EMSCRIPTEN_THREAD_POOL} -s ASYNCIFY --preload-file ${BOFSTD_EMSCRIPTEN_FS_ROOT_DIR}")
message("===EMSCRIPTEN=== CMAKE_EXE_LINKER_FLAGS is ${CMAKE_EXE_LINKER_FLAGS}")
#ici ca bloque qq part dans imgui car je pense qu'on est dans un autre thread entre imgui et le main...
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -sPROXY_TO_PTHREAD") #-sPTHREAD_POOL_SIZE=4") # -sPROXY_TO_PTHREAD -sASYNCIFY") # -sUSE_PTHREADS=1) # -sSHARED_MEMORY=1")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -sPROXY_TO_PTHREAD") #-sUSE_PTHREADS=1") #-sPTHREAD_POOL_SIZE=4") # -sPROXY_TO_PTHREAD -sASYNCIFY") # -sUSE_PTHREADS=1) # -sSHARED_MEMORY=1")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif ()
endif()
message("===EMSCRIPTEN=== CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}")
endif()

# For shared libraries we need to compile with "-fPIC"
# But for static libraries user can choose
Expand Down Expand Up @@ -209,6 +255,15 @@ else()
set(CMAKE_BUILD_RPATH "${VCPKG_RELEASE_LIB_DIR};${VCPKG_DEBUG_LIB_DIR}")
endif()

# To avoid problem with EMSCRIPTEN compilation we only get third party libs which dont
# depend on pthread lib. These one are get using the fetch_vcpkg_library function as
# they must be built with a strict control of options which is not possible with vcpkg
# build in manifest mode
message("==============================================start fetch=========================")
fetch_external_library_add(googletest "${LIST_OF_LIB}" https://github.com/google/googletest release-1.12.1)
fetch_external_library_add(spdlog "${LIST_OF_LIB}" https://github.com/gabime/spdlog v1.12.0)
make_external_library_available("${LIST_OF_LIB}")
message("==============================================END fetch=========================")
include(Dependencies.cmake)

find_package(Doxygen)
Expand Down Expand Up @@ -302,5 +357,4 @@ install(FILES
COMPONENT bofstd-devel
)



#list_cmake_vars_containing("")
4 changes: 2 additions & 2 deletions Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ endmacro()
# ===========================

if(BOFSTD_BUILD_TESTS)
find_package(GTest REQUIRED)
#### find_package(GTest REQUIRED)
endif()

# ===========================
Expand All @@ -41,7 +41,7 @@ endif()

#just above find_package_dependency(jsoncpp REQUIRED)

find_package_dependency(spdlog REQUIRED)
####find_package_dependency(spdlog REQUIRED)
find_package_dependency(fmt REQUIRED)
find_package_dependency(date REQUIRED)

18 changes: 9 additions & 9 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ set(SOURCES
# ===========

# Create target
add_executable(AppBofStd
add_executable(app_bofstd
${SOURCES}
)

# Includes
target_include_directories(AppBofStd
target_include_directories(app_bofstd
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/>
)

# Link
target_link_libraries(AppBofStd
target_link_libraries(app_bofstd
PRIVATE
ONBINGS::bofstd
# Qt5::Core
Expand All @@ -34,12 +34,12 @@ message("================CMAKE_CURRENT_BINARY_DIR==========>" ${CMAKE_CURRENT_BI
message("================COMPILED_BINARIES_DIR==========>" ${COMPILED_BINARIES_DIR})

# Defines
target_compile_definitions(AppBofStd
target_compile_definitions(app_bofstd
PRIVATE
)

# Properties
#set_target_properties(AppBofStd
#set_target_properties(app_bofstd
# PROPERTIES
# AUTOMOC ON
# AUTORCC ON
Expand All @@ -54,17 +54,17 @@ if(NOT APPLE)
# Fix RPATH upon installation by replacing
# the absolute RPATH generated by the compiler
# to where libraries were really installed
set_target_properties(AppBofStd PROPERTIES
set_target_properties(app_bofstd PROPERTIES
INSTALL_RPATH ${RELATIVE_PATH_BIN_TO_LIB}
)

endif()

# Install the target runtime
install(
TARGETS AppBofStd
EXPORT AppBofStd
TARGETS app_bofstd
EXPORT app_bofstd
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # For binaries and dll
COMPONENT AppBofStd-app
COMPONENT app_bofstd-app
)

59 changes: 59 additions & 0 deletions cmake/fetch_content.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
include(FetchContent)

#first call this one for each lib AND AFTER cal ONCE fetch_external_library_generate
function(fetch_external_library_add LIB_NAME LIST_OF_LIB GIT_URL GIT_TAG)
message(STATUS "Start of fetch external library '${LIB_NAME}' from ${GIT_URL} at tag ${GIT_TAG}:")
set(FETCHCONTENT_QUIET OFF)
FetchContent_Declare(
${LIB_NAME}
GIT_REPOSITORY ${GIT_URL}
GIT_TAG ${GIT_TAG}
)
list(APPEND LIST_OF_LIB ${LIB_NAME}) # Append library name to the provided list
set(LIST_OF_LIB "${LIST_OF_LIB}" PARENT_SCOPE)
message(STATUS "End of of fetch external library add '${LIB_NAME}'")
endfunction()

function(make_external_library_available LIST_OF_LIB)
message(STATUS "make_external_library_available for the following lib:")
foreach(_lib ${LIST_OF_LIB})
message("${_lib}")
endforeach()
FetchContent_MakeAvailable("${LIST_OF_LIB}")
endfunction()

# Function to list CMake variables with a given prefix
# list_cmake_vars_with_prefix("CMAKE_")
# list_cmake_vars_with_prefix("CXX_")
function(list_cmake_vars_with_prefix _prefix)
message(STATUS "Listing CMake variables with prefix '${_prefix}':")
get_cmake_property(_variable_names VARIABLES)
foreach(_variable_name IN LISTS _variable_names)
string(FIND "${_variable_name}" "${_prefix}" _prefix_length)
if (_prefix_length EQUAL 0)
message(STATUS "${_variable_name} = ${${_variable_name}}")
endif()
endforeach()
message(STATUS "End of listing")
endfunction()

function(list_cmake_vars_containing _str)
message(STATUS "Listing CMake variables which contains '${_str}':")
string(TOLOWER "${_str}" _str_lower)
get_cmake_property(_variable_names VARIABLES)
foreach(_variable_name IN LISTS _variable_names)
string(TOLOWER "${_variable_name}" _variable_lower)
string(FIND "${_variable_lower}" "$_str_lower}" pos)
string(FIND "${_variable_name}" "${_str}" pos)
if (NOT pos EQUAL -1)
message(STATUS "${_variable_name} = ${${_variable_name}}")
endif()
endforeach()
message(STATUS "End of listing")
endfunction()


#get_cmake_property(_variable_names VARIABLES)
#foreach(_variable_name IN LISTS _variable_names)
# message(STATUS "${_variable_name} = ${${_variable_name}}")
#endforeach()
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ target_link_libraries(bofstd

PRIVATE
jsoncpp::jsoncpp
spdlog::spdlog
#spdlog::spdlog
$<BUILD_INTERFACE:spdlog::spdlog> #https://discourse.cmake.org/t/using-a-header-only-library-with-fetchcontents-while-build-a-static-lib/2711/2
)
if(WIN32)
target_link_libraries(bofstd
Expand Down Expand Up @@ -486,3 +487,6 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/help/html/. DESTINATION doc COMPON

#set_target_properties(bofstd PROPERTIES FOLDER Lib)




6 changes: 2 additions & 4 deletions lib/src/boffs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ BOFERR Bof_DirectoryParser(const BofPath &_rPath, const std::string &_rPattern_S
#endif

// printf("==>Enter %s\n", _rPath.FullPathName(true).c_str());

if (_rPath.IsDirectory())
{
#if defined(_WIN32)
Expand Down Expand Up @@ -473,8 +472,7 @@ BOFERR Bof_DirectoryParser(const BofPath &_rPath, const std::string &_rPattern_S
}
else
{
// printf("--> %s\n", FileFound_X.Path.FullPathName(true).c_str());

// printf("-FS-> %s\n", FileFound_X.Path.FullPathName(true).c_str());
if (!_rDirectoryParserCallback(FileFound_X))
{
Finish_B = true;
Expand Down Expand Up @@ -1115,7 +1113,7 @@ BOFERR Bof_CopyFile(bool _OverwriteIfExists_B, const BofPath &_rSrcPath, const B
if (CreateOut_B)
{
Rts_E = BOF_ERR_CREATE;
std::ofstream Ofs(_rDstPath.FullPathName(false).c_str(), std::ios::trunc| std::ios_base::binary);
std::ofstream Ofs(_rDstPath.FullPathName(false).c_str(), std::ios::trunc | std::ios_base::binary);
if (Ofs)
{
Ofs << Ifs.rdbuf();
Expand Down
17 changes: 16 additions & 1 deletion lib/src/bofpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,22 @@ bool BofPath::IsWindowsDiskPath(const std::string &_rPath_S)

bool BofPath::IsForbiddenChar(const std::string &_rPath_S)
{
return (Bof_StringIsPresent(_rPath_S, mForbiddenCharacter_S));
bool Rts_B;

#if defined(__EMSCRIPTEN__)
//During file packaging under emscripten windows we can have path like /C:/pro/...
if ((_rPath_S[0] == '/') && (_rPath_S[2] == ':') && (_rPath_S[3] == '/'))
{
Rts_B = Bof_StringIsPresent(_rPath_S.substr(3), mForbiddenCharacter_S);
}
else
{
Rts_B = Bof_StringIsPresent(_rPath_S, mForbiddenCharacter_S);
}
#else
Rts_B=Bof_StringIsPresent(_rPath_S, mForbiddenCharacter_S);
#endif
return Rts_B;
}

BOFERR BofPath::Normalize(bool _PureFilename_B, const std::string &_rRawPath_S, std::string &_rNormalizedPath_S, std::string &_rDiskName_S)
Expand Down
Loading

0 comments on commit 59320df

Please sign in to comment.