Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows compilation #231

Merged
merged 39 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7a31d7e
framework is now able to be compiled on windows
nkx111 May 27, 2022
cb30612
fix compilation
nkx111 May 27, 2022
e3ad301
class TRestDBEntryLogger removed
nkx111 May 27, 2022
64cfe46
rename dllimport preprocessors
nkx111 May 28, 2022
6cb0dee
Merge branch 'master' into windows-compile
nkx111 May 28, 2022
ee3b713
TRestTools methods recovered
nkx111 May 28, 2022
96c72be
update
nkx111 May 28, 2022
ffc8052
updated library compilation
May 28, 2022
9123105
tmp path are treated differently on different OS
May 28, 2022
6328b8e
continue fixing windows running issues
May 28, 2022
a0b4088
string output for windows is not normal
May 28, 2022
e0d9f4b
console width/height is also available on windows
May 29, 2022
40f1226
REST string converter now uses typeid hash to identify classes
May 29, 2022
43641f6
root dict: add relative include path ../include in case source file i…
May 29, 2022
8a1939e
startup.cpp fix headers
May 29, 2022
81b7479
revert changes in tinyxml
nkx111 May 29, 2022
50160ee
revert changes in tinyxml
nkx111 May 29, 2022
f7c23e6
fix line endings
nkx111 May 29, 2022
685bb25
fix line endings
nkx111 May 29, 2022
b8a7c6b
Update startup.cpp
nkx111 May 29, 2022
1d9eb60
TRestTools: removed a warning
nkx111 May 29, 2022
b781aec
fix pipeling PCM warnings
nkx111 May 29, 2022
809f96b
update startup.cpp
nkx111 May 30, 2022
6169bb9
Merge branch 'windows-compile' of github.com:rest-for-physics/framewo…
nkx111 May 30, 2022
2bc4879
fixing TRestTools::SearchFileInPath
nkx111 May 30, 2022
285f8dc
fixing TRestTools::SearchFileInPath
nkx111 May 30, 2022
8e12379
revert pipeline change
nkx111 May 30, 2022
734db13
Update .gitlab-ci.yml
nkx111 May 30, 2022
0d894f5
Merge remote-tracking branch 'origin/master' into windows-compile
nkx111 Jun 4, 2022
1cbb867
update tinyxml.h to avoid including assert.h
nkx111 Jun 4, 2022
4b57f35
implemented file name pattern matching for windows
nkx111 Jun 6, 2022
3cc924b
added description for REST_StringHelper::MatchString
nkx111 Jun 6, 2022
a343179
CMakeLists.txt - Added back `FATAL_ERROR` when ROOT is not compiled w…
lobis Jun 7, 2022
3eba683
Merge branch 'master' into windows-compile
lobis Jun 7, 2022
dd3c629
cmake root cxx flags check is not performed on windows
nkx111 Jun 7, 2022
5c35746
Merge branch 'windows-compile' of github.com:rest-for-physics/framewo…
nkx111 Jun 7, 2022
514c93b
startup.cpp can also get REST_PATH from /proc/pid
nkx111 Jun 7, 2022
cf4243b
update startup.cpp
nkx111 Jun 7, 2022
ad1523c
update startup.cpp
nkx111 Jun 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 59 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-stdlib=libc++")
endif (CMAKE_SYSTEM_NAME MATCHES "Darwin")

if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_CXX_STANDARD 17)
add_definitions(-D_HAS_STD_BYTE=0)
endif (CMAKE_SYSTEM_NAME MATCHES "Windows")

# https://github.com/rest-for-physics/framework/issues/162
if (${CMAKE_VERSION} VERSION_LESS "3.21")
cmake_policy(SET CMP0082 OLD)
Expand Down Expand Up @@ -71,7 +76,7 @@ endif ()
if (${REST_EVE} MATCHES "ON")
add_definitions(-DUSE_Eve)
list(APPEND rest_features "Eve")
set(ROOT_REQUIRED_LIBRARIES ${ROOT_REQUIRED_LIBRARIES} Eve RGL)
set(ROOT_REQUIRED_LIBRARIES ${ROOT_REQUIRED_LIBRARIES} Eve RGL Gui)
else ()
set(excludes ${excludes} TRestEveEventViewer)
endif (${REST_EVE} MATCHES "ON")
Expand All @@ -80,7 +85,13 @@ find_package(ROOT REQUIRED COMPONENTS ${ROOT_REQUIRED_LIBRARIES})

message(STATUS "ROOT LIBRARIES: ${ROOT_LIBRARIES}")

set(external_libs "${external_libs};${ROOT_LIBRARIES};stdc++fs")
set(external_libs "${external_libs};${ROOT_LIBRARIES}")

if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(external_libs "${external_libs};Ws2_32")
else()
set(external_libs "${external_libs};stdc++fs")
endif ()

set(ROOTCINT_EXECUTABLE ${ROOT_rootcint_CMD})

Expand All @@ -98,7 +109,7 @@ if (${HASCXX20} MATCHES "yes")
elseif (${HASCXX17} MATCHES "yes")
set(CMAKE_CXX_STANDARD 17)
else ()
message(FATAL_ERROR "Minimum C++ standard version is 17,
message("Minimum C++ standard version is 17,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the error removed here? I think we should stop execution if C++ std is not 17.

Update: I added it back on a343179, since I think its a must have, we should not allow to compile REST with a ROOT compiled with C++11 or C++14

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out. I agree to force using c++17-compiled ROOT. I removed this error because on windows we cannot use root-config to collect HASCXX17, which makes cmake failed on this line. I have excluded this check for windows.

while the root version is compiled with an older
C++ standard, check root-config --cflags ${ROOT_CFLAGS}"
)
Expand Down Expand Up @@ -143,7 +154,7 @@ add_subdirectory(source)

message("")
message(STATUS "rest Libraries: " ${rest_libraries_regular})
message(STATUS "rest executables: " ${rest_exes})
message(STATUS "rest executables: " ${rest_exes_str})
message(STATUS "rest macros: " ${rest_macros_str})
message("")

Expand Down Expand Up @@ -194,17 +205,49 @@ file(GLOB cmake_scripts
"cmake/scripts/*"
)
install(FILES ${cmake_scripts} DESTINATION cmake)
# Copy pcm files
install(CODE
"
file(GLOB PCMFiles \"\${CMAKE_CURRENT_SOURCE_DIR}/rootdict/*.pcm\")
file(COPY \${PCMFiles} DESTINATION \${CMAKE_INSTALL_PREFIX}/lib)
"
)

# Create thisREST.sh
include(thisREST)

# Add permissions
install(CODE "execute_process(COMMAND chmod 755 ${CMAKE_INSTALL_PREFIX}/bin/rest-config)")
install(CODE "execute_process(COMMAND chmod 755 ${CMAKE_INSTALL_PREFIX})")



if (CMAKE_SYSTEM_NAME MATCHES "Windows") # we must call library install here in windows
foreach(lib ${rest_libraries})
install(TARGETS ${lib}
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
ARCHIVE DESTINATION lib)
endforeach()

foreach(exe ${rest_exes})
install(TARGETS ${exe}
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
ARCHIVE DESTINATION lib)
endforeach()

# Copy pcm files to bin
install(CODE
"
file(GLOB PCMFiles \"\${CMAKE_CURRENT_SOURCE_DIR}/rootdict/*.pcm\")
file(COPY \${PCMFiles} DESTINATION \${CMAKE_INSTALL_PREFIX}/bin)
"
)

else()

# Copy pcm files to lib
install(CODE
"
file(GLOB PCMFiles \"\${CMAKE_CURRENT_SOURCE_DIR}/rootdict/*.pcm\")
file(COPY \${PCMFiles} DESTINATION \${CMAKE_INSTALL_PREFIX}/lib)
"
)

# Create thisREST.sh
include(thisREST)

# Add permissions
install(CODE "execute_process(COMMAND chmod 755 ${CMAKE_INSTALL_PREFIX}/bin/rest-config)")
install(CODE "execute_process(COMMAND chmod 755 ${CMAKE_INSTALL_PREFIX})")

endif()
26 changes: 12 additions & 14 deletions cmake/MacroRootDict.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SET(LD_LIBRARY_PATH_CONTENTS $ENV{${LD_LIBRARY_PATH_VAR}})
SET(ROOT_CINT_WRAPPER ${LD_LIBRARY_PATH_VAR}=${ROOT_LIBRARY_DIR}:${LD_LIBRARY_PATH_CONTENTS} ${ROOTCINT_EXECUTABLE})

if (CMAKE_SYSTEM_NAME MATCHES "Windows")
SET(ROOT_CINT_WRAPPER ${ROOTCINT_EXECUTABLE})
SET(ROOT_CINT_WRAPPER ${ROOTCINT_EXECUTABLE} -D_HAS_STD_BYTE=0)
endif ()

IF (NOT DEFINED ROOT_DICT_OUTPUT_DIR)
Expand Down Expand Up @@ -112,7 +112,7 @@ MACRO(GEN_ROOT_DICT_SOURCE _dict_src_filename)
# TODO check for ROOT_CINT_EXECUTABLE
file(MAKE_DIRECTORY ${ROOT_DICT_OUTPUT_DIR})
# need to prefix all include dirs with -I
set(_dict_includes)
set(_dict_includes "-I../include")
FOREACH (_inc ${ROOT_DICT_INCLUDE_DIRS})
SET(_dict_includes "${_dict_includes}\t-I${_inc}") #fg: the \t fixes a wired string expansion
ENDFOREACH ()
Expand Down Expand Up @@ -315,17 +315,11 @@ MACRO(COMPILEDIR libname)

include_directories(${local_include_dirs})
add_library(${libname} SHARED ${contentfiles} ${addon_src})


target_link_libraries(${libname} ${local_libraries} ${external_libs})
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set_target_properties(${libname} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
target_link_libraries(${libname} ${local_libraries} ${external_libs})
install(TARGETS ${libname}
RUNTIME DESTINATION bin
LIBRARY DESTINATION bin
ARCHIVE DESTINATION lib)
else ()
target_link_libraries(${libname} ${local_libraries} ${external_libs})
install(TARGETS ${libname}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
Expand Down Expand Up @@ -508,10 +502,14 @@ MACRO(COMPILELIB dependency)
target_link_libraries(${libname} ${libs_to_link} ${external_libs})

# install
install(TARGETS ${libname}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set_target_properties(${libname} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
else ()
install(TARGETS ${libname}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
endif ()

file(GLOB_RECURSE Headers "${CMAKE_CURRENT_SOURCE_DIR}/inc/*.h")
INSTALL(FILES ${Headers} DESTINATION include)
Expand Down
9 changes: 9 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,22 @@ set(rest_libraries ${rest_libraries} PARENT_SCOPE)
set(rest_packages ${rest_packages} PARENT_SCOPE)
set(rest_features ${rest_features} PARENT_SCOPE)

# construct REST library regulat string(-L/home/xxx/REST/lib -lxxx)
set(rest_libraries_regular "-L${CMAKE_INSTALL_PREFIX}/lib ")
foreach (lib ${rest_libraries})
set(rest_libraries_regular "${rest_libraries_regular} -l${lib} ")
endforeach (lib)
set(rest_libraries_regular ${rest_libraries_regular} PARENT_SCOPE)

set(rest_exes ${rest_exes} PARENT_SCOPE)
# construct REST exes string(separate with blank)
set(rest_exes_str)
foreach (exe ${rest_exes})
set(rest_exes_str "${rest_exes_str}${exe} ")
endforeach (exe ${rest_exes})
set(rest_exes_str ${rest_exes_str} PARENT_SCOPE)


set(rest_macros ${rest_macros} PARENT_SCOPE)
# construct REST macros string(separate with blank)
set(rest_macros_str)
Expand Down
2 changes: 1 addition & 1 deletion source/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ foreach (file ${files})
ADD_EXECUTABLE(${name} ${file})
TARGET_LINK_LIBRARIES(${name} ${rest_libraries} ${external_libs})
install(TARGETS ${name} RUNTIME DESTINATION bin)
set(rest_exes "${rest_exes}${name} ")
set(rest_exes ${rest_exes} ${name})

endforeach (file)

Expand Down
16 changes: 8 additions & 8 deletions source/bin/restManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ char iFile[256];

const int maxForksAllowed = 32;

#ifdef WIN32
void setenv(const char* __name, const char* __value, int __replace) {
_putenv(((string)__name + "=" + (string)__value).c_str());
}
#endif

int fork_n_execute(string command) {
#ifdef WIN32
return -1;
#else
int status;
pid_t pid;

Expand All @@ -45,6 +43,7 @@ int fork_n_execute(string command) {
status = -1;
*/
return status;
#endif // !WIN32
}

void PrintHelp() {
Expand Down Expand Up @@ -129,6 +128,7 @@ int main(int argc, char* argv[]) {
for (int i = 1; i < args.size(); i++) {
if (args[i] == "--batch") {
RESTcout << "you are in batch mode, all graphical displays off" << RESTendl;
REST_Display_CompatibilityMode = true;
argCApp = 2;
args.erase(args.begin() + i);
}
Expand All @@ -139,9 +139,9 @@ int main(int argc, char* argv[]) {
doFork = true;
}
}
if (Console::CompatibilityMode) {
RESTcout << "you are in compatibility mode, all graphical displays off" << RESTendl;
argCApp = 2;
if (REST_Display_CompatibilityMode) {
RESTcout << "display under compatibility mode" << RESTendl;
//argCApp = 2;
}
}
TApplication app("app", &argCApp, argVApp);
Expand Down
21 changes: 15 additions & 6 deletions source/bin/restRoot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

using namespace std;

#ifdef WIN32
// in windows the pointer address from string conversion is without "0x", we must add
// the prefix so that ROOT can correctly initialize run/metadata objects
#define PTR_ADDR_PREFIX "0x"
#else
#define PTR_ADDR_PREFIX ""
#endif // WIN32

// Note!
// Don't use cout in the main function!
// This will make cout un-usable in the command line!
Expand Down Expand Up @@ -89,15 +97,16 @@ int main(int argc, char* argv[]) {
printf("\nAttaching file %s as run%i...\n", opt.c_str(), Nfile);

TRestRun* runTmp = new TRestRun(opt);
string runcmd = Form("TRestRun* run%i = (TRestRun*)%s;", Nfile, ToString(runTmp).c_str());
string runcmd =
Form("TRestRun* run%i = (TRestRun*)%s;", Nfile, (PTR_ADDR_PREFIX + ToString(runTmp)).c_str());
if (debug) printf("%s\n", runcmd.c_str());
gROOT->ProcessLine(runcmd.c_str());
if (runTmp->GetInputEvent() != nullptr) {
string eventType = runTmp->GetInputEvent()->ClassName();

printf("Attaching event %s as ev%i...\n", eventType.c_str(), Nfile);
string evcmd = Form("%s* ev%i = (%s*)%s;", eventType.c_str(), Nfile, eventType.c_str(),
ToString(runTmp->GetInputEvent()).c_str());
(PTR_ADDR_PREFIX + ToString(runTmp->GetInputEvent())).c_str());
if (debug) printf("%s\n", evcmd.c_str());
gROOT->ProcessLine(evcmd.c_str());
runTmp->GetEntry(0);
Expand All @@ -116,7 +125,7 @@ int main(int argc, char* argv[]) {
//{
printf("Attaching ana_tree%i...\n", Nfile);
string evcmd = Form("TRestAnalysisTree* ana_tree%i = (TRestAnalysisTree*)%s;", Nfile,
ToString(runTmp->GetAnalysisTree()).c_str());
(PTR_ADDR_PREFIX + ToString(runTmp->GetAnalysisTree())).c_str());
if (debug) printf("%s\n", evcmd.c_str());
gROOT->ProcessLine(evcmd.c_str());
// runTmp->GetEntry(0);
Expand All @@ -126,8 +135,8 @@ int main(int argc, char* argv[]) {
// command line EventTree object
if (runTmp->GetEventTree() != nullptr) {
printf("Attaching ev_tree%i...\n", Nfile);
string evcmd =
Form("TTree* ev_tree%i = (TTree*)%s;", Nfile, ToString(runTmp->GetEventTree()).c_str());
string evcmd = Form("TTree* ev_tree%i = (TTree*)%s;", Nfile,
(PTR_ADDR_PREFIX + ToString(runTmp->GetEventTree())).c_str());
if (debug) printf("%s\n", evcmd.c_str());
gROOT->ProcessLine(evcmd.c_str());
}
Expand All @@ -153,7 +162,7 @@ int main(int argc, char* argv[]) {
printf("- %s (%s)\n", metaFixed.c_str(), metaType.c_str());

string mdcmd = Form("%s* %s = (%s*)%s;", metaType.c_str(), metaFixed.c_str(),
metaType.c_str(), ToString(md).c_str());
metaType.c_str(), (PTR_ADDR_PREFIX + ToString(md)).c_str());

if (debug) printf("%s\n", mdcmd.c_str());

Expand Down
4 changes: 4 additions & 0 deletions source/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ if (NOT ${REST_EVE} MATCHES "ON")
set(excludes TRestEveEventViewer)
endif (NOT ${REST_EVE} MATCHES "ON")

if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(excludes TRestBenchMarkProcess TRestRealTimeAddInputFileProcess TRestRealTimeDrawingProcess TRestMessenger ${excludes})
endif (CMAKE_SYSTEM_NAME MATCHES "Windows")

find_library(CURL_LIB curl)
if (NOT ${CURL_LIB} STREQUAL "CURL_LIB-NOTFOUND")
add_compile_definitions(USE_Curl)
Expand Down
66 changes: 0 additions & 66 deletions source/framework/core/inc/TRestDBEntryLogger.h

This file was deleted.