Skip to content
Snippets Groups Projects
Commit 2e6d2c56 authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

Make win32 version build again

parent 20a6a2ee
No related branches found
No related tags found
No related merge requests found
[submodule "dlfcn-win32"]
path = dlfcn-win32
url = https://github.com/dlfcn-win32/dlfcn-win32.git
......@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.19)
project(eisgenerator LANGUAGES C CXX)
set (CMAKE_CXX_STANDARD 20)
set(SRC_FILES
componant.cpp
cap.cpp
......@@ -22,7 +24,7 @@ set(SRC_FILES
strops.cpp
translators.cpp
randomgen.cpp
compile.cpp
compcache.cpp
)
set(API_HEADERS_CPP_DIR eisgenerator/)
......@@ -53,15 +55,37 @@ if(WIN32)
file(GLOB_RECURSE ARGP_SRC ${PROJECT_SOURCE_DIR}/argp/*.*)
set(SRC_FILES ${SRC_FILES} ${ARGP_SRC})
include_directories(./argp)
include_directories(./dlfcn-win32/src/)
set(SRC_FILES ${SRC_FILES}
compile-win.cpp
./dlfcn-win32/src/dlfcn.c
)
set(COMMON_LINK_FLAGS "-flto -dl")
else()
message("Building on UNIX")
set(SRC_FILES ${SRC_FILES}
compile.cpp
)
set(COMMON_LINK_FLAGS "-flto -ltbb -pthread")
endif(WIN32)
add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${API_HEADERS_CPP})
target_link_libraries(${PROJECT_NAME} ${LIBS})
target_include_directories(${PROJECT_NAME} PUBLIC eisgenerator)
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-std=c++2a -Wall -O2 -march=native -g" LINK_FLAGS "-flto -ltbb -pthread")
add_library(${PROJECT_NAME}_obj OBJECT ${SRC_FILES} ${API_HEADERS_CPP})
target_link_libraries(${PROJECT_NAME}_obj ${LIBS})
target_include_directories(${PROJECT_NAME}_obj PUBLIC eisgenerator)
set_target_properties(${PROJECT_NAME}_obj PROPERTIES POSITION_INDEPENDENT_CODE 1)
set_target_properties(${PROJECT_NAME}_obj PROPERTIES COMPILE_FLAGS "-Wall -O2 -march=native -g" LINK_FLAGS ${COMMON_LINK_FLAGS})
add_library(${PROJECT_NAME} SHARED $<TARGET_OBJECTS:${PROJECT_NAME}_obj>)
add_library(${PROJECT_NAME}_static STATIC $<TARGET_OBJECTS:${PROJECT_NAME}_obj>)
if(WIN32)
set(EISGEN_LINK_FLAG ${PROJECT_NAME}_static)
else()
set(EISGEN_LINK_FLAG ${PROJECT_NAME})
endif(WIN32)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE)
......@@ -82,20 +106,20 @@ GROUP_READ GROUP_EXECUTE )
link_directories(${CMAKE_CURRENT_BINARY_DIR})
set(SRC_FILES_TEST_APP test.cpp)
set(LIBS_TEST -L. -l${PROJECT_NAME})
set(LIBS_TEST -L. -l${EISGEN_LINK_FLAG})
add_executable(${PROJECT_NAME}_test ${SRC_FILES_TEST_APP})
add_dependencies(${PROJECT_NAME}_test ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}_test ${LIBS_TEST})
target_include_directories(${PROJECT_NAME}_test PUBLIC eisgenerator)
set_target_properties(${PROJECT_NAME}_test PROPERTIES COMPILE_FLAGS "-std=c++2a -Wall -O2 -march=native -g" LINK_FLAGS "-flto")
set_target_properties(${PROJECT_NAME}_test PROPERTIES COMPILE_FLAGS "-Wall -O2 -march=native -g" LINK_FLAGS ${COMMON_LINK_FLAGS})
install(TARGETS ${PROJECT_NAME}_test DESTINATION bin)
link_directories(${CMAKE_CURRENT_BINARY_DIR})
set(SRC_FILES_TEST_APP main.cpp)
set(LIBS_TEST -L. -l${PROJECT_NAME})
set(LIBS_TEST -L. -l${EISGEN_LINK_FLAG})
add_executable(${PROJECT_NAME}_export ${SRC_FILES_TEST_APP})
add_dependencies(${PROJECT_NAME}_export ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}_export ${LIBS_TEST})
target_include_directories(${PROJECT_NAME}_export PUBLIC eisgenerator)
set_target_properties(${PROJECT_NAME}_export PROPERTIES COMPILE_FLAGS "-std=c++2a -Wall -O2 -march=native -g" LINK_FLAGS "-flto")
set_target_properties(${PROJECT_NAME}_export PROPERTIES COMPILE_FLAGS "-Wall -O2 -march=native -g" LINK_FLAGS ${COMMON_LINK_FLAGS})
install(TARGETS ${PROJECT_NAME}_export DESTINATION bin)
......@@ -7,7 +7,6 @@
#include <errno.h>
#include <stdexcept>
#include <sys/wait.h>
#include <dlfcn.h>
#include "log.h"
......@@ -83,67 +82,3 @@ int eis::compile_code(const std::string& code, const std::string& outputName)
return -1;
}
std::string eis::getTempdir()
{
char* tmpEnv = getenv("TMP");
char* tempEnv = getenv("TEMP");
char* tempDirEnv = getenv("TEMPDIR");
std::filesystem::path path;
if(tmpEnv && std::string(tmpEnv).length() > 1)
path = tmpEnv;
else if(tempEnv && std::string(tempEnv).length() > 1)
path = tempEnv;
else if(tempDirEnv && std::string(tempDirEnv).length() > 1)
path = tempDirEnv;
else
path = "/tmp";
path = path/"eis_models";
if(!std::filesystem::is_directory(path))
{
if(!std::filesystem::create_directory(path))
throw std::runtime_error(path.string() +
"is not a directory and a directory can not be created at this locaion");
}
return path;
}
CompCache* CompCache::getInstance()
{
if(!instance)
instance = new CompCache();
return instance;
}
bool CompCache::addObject(size_t uuid, const CompiledObject& object)
{
CompiledObject* foundobject = getObject(uuid);
if(foundobject)
return false;
objects.insert({uuid, new CompiledObject(object)});
return true;
}
CompiledObject* CompCache::getObject(size_t uuid)
{
auto search = objects.find(uuid);
if(search == objects.end())
return nullptr;
else
return search->second;
}
void CompCache::dropAllObjects()
{
for(std::pair<size_t, CompiledObject*> object : objects)
{
dlclose(object.second->objectCode);
delete object.second;
}
objects.clear();
}
#include <string>
#include <vector>
#include <map>
#include <complex>
#include "eistype.h"
namespace eis
{
int compile_code(const std::string& code, const std::string& outputName);
std::string getTempdir();
struct CompiledObject
{
void* objectCode;
std::vector<std::complex<fvalue>>(*symbol)(const std::vector<fvalue>&, const std::vector<fvalue>&);
};
class CompCache
{
public:
private:
inline static CompCache* instance = nullptr;
std::map<size_t, CompiledObject*> objects;
CompCache() {};
public:
static CompCache* getInstance();
CompCache(const CompCache&) = delete;
CompCache& operator=(const CompCache&) = delete;
bool addObject(size_t uuid, const CompiledObject& object);
CompiledObject* getObject(size_t uuid);
void dropAllObjects();
};
}
......@@ -5,3 +5,4 @@ set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_EXE_LINKER_FLAGS "-static")
Subproject commit 6444294ee354796536c34b54e154c0538a4d1eaf
......@@ -27,6 +27,7 @@
#include "basicmath.h"
#include "randomgen.h"
#include "compile.h"
#include "compcache.h"
using namespace eis;
......@@ -582,7 +583,7 @@ bool Model::compile()
size_t uuid = getUuid();
std::filesystem::path path = tmp/(std::to_string(getUuid())+".so");
int ret = compile_code(getCode(), path);
int ret = compile_code(getCode(), path.string());
if(ret != 0)
{
Log(Log::WARN)<<"Unable to compile model!! expect performance degredation";
......@@ -590,7 +591,7 @@ bool Model::compile()
}
CompiledObject object;
object.objectCode = dlopen(path.c_str(), RTLD_NOW);
object.objectCode = dlopen(path.string().c_str(), RTLD_NOW);
if(!object.objectCode)
throw std::runtime_error("Unable to dlopen compiled model " + std::string(dlerror()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment