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

Msvc compliance #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.6.2)

project(eakmeans)

option(STATIC_LIBRARY "Build static library instead of shared library" OFF)
if(STATIC_LIBRARY)
set(LIB_TYPE "STATIC")
else()
set(LIB_TYPE "SHARED")
endif()
add_subdirectory(src)

option(BUILD_MAIN "Build test executable" ON)
if(BUILD_MAIN)
set(EXE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
link_directories("${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" "${BLAS_FOLDER}/dll")
add_executable(${PROJECT_NAME} ${EXE_SRC})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIB_EAKMEANS} ${BLAS})
add_dependencies(${PROJECT_NAME} libeakmeans)
if(WIN32)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/WHOLEARCHIVE:libeakmeans")
endif()
endif()

option(PYTHON_KMEANS "Build Python integration of eakmeans." OFF)
if(PYTHON_KMEANS)
execute_process(
COMMAND python "${PROJECT_SOURCE_DIR}/setup.py" build_ext -b lib
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE py_result
)
endif()
34 changes: 34 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.6.2)

project(libeakmeans)

# We enable C++11
set(CMAKE_CXX_STANDARD 11)

set(TARGET_ARCHI "x64")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${TARGET_ARCHI}" CACHE PATH "Output library (lib) directory")
set(LIBEAKMEANS_OUTPUT_DIR ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})

option(USEBLAS "Use external BLAS library" OFF)
if(USEBLAS)
set(BLAS_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/../../OpenBLAS/build" CACHE PATH "Folder where to find BLAS distribution")
set(BLAS_NAME "libopenblas" CACHE STRING "Name of BLAS implementation")
endif()

file(GLOB LIB_SRC *.cpp *.hpp *.h)
get_filename_component(main_cpp ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ABSOLUTE)
list(REMOVE_ITEM LIB_SRC "${main_cpp}")

if(USEBLAS)
include_directories("${BLAS_FOLDER}/include")
find_library(BLAS ${BLAS_NAME} PATHS "${BLAS_FOLDER}" PATH_SUFFIXES lib;dll)
endif()

add_library(${PROJECT_NAME} ${LIB_TYPE} ${LIB_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories (${PROJECT_NAME} PUBLIC {CMAKE_CURRENT_SOURCE_DIR}/src)

if(USEBLAS)
target_link_libraries(${PROJECT_NAME} PRIVATE ${BLAS})
target_compile_definitions(${PROJECT_NAME} PUBLIC "WITHBLAS")
endif()
14 changes: 14 additions & 0 deletions src/arrutilv2l0.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,19 @@ COPYING for more details.
#include "arrutilv2l0blasless.h"
#endif

#ifdef _MSC_VER
// add setenv under Windows
int setenv(const char *name, const char *value, int overwrite)
{
int errcode = 0;
if (!overwrite) {
size_t envsize = 0;
errcode = getenv_s(&envsize, NULL, 0, name);
if (errcode || envsize) return errcode;
}
return _putenv_s(name, value);
}
#endif // _MSC_VER

#endif

1 change: 1 addition & 0 deletions src/barrierutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ COPYING for more details.

#include "barrierutil.h"
#include <iostream>
#include <algorithm>

namespace stdthreadutil{

Expand Down
6 changes: 5 additions & 1 deletion src/initialise2.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ std::tuple<std::unique_ptr<TFloat []>, std::unique_ptr<TFloat []>, std::unique_p
std::unique_ptr<TFloat [] >,
std::unique_ptr<TInt [] >,
TFloat >
(std::move(C_uptr), std::move(C_l22s_uptr), std::move(ind0), TFloat(mse2));
#ifdef _MSC_VER
(std::move(C_uptr), std::move(C_l22s_uptr), std::move(ind0), std::move(TFloat(mse2))); //force forwarding
#else
(std::move(C_uptr), std::move(C_l22s_uptr), std::move(ind0), TFloat(mse2));
#endif
}


Expand Down
25 changes: 13 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ COPYING for more details.
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>

#include "optionsutil.h"
#include "pllkmeansfuncs_void.h"
Expand Down Expand Up @@ -611,7 +612,7 @@ int main(int argc, char* argv[]){
return 1;
}

if (!(cout_verbosity > 1) and !(file_verbosity > 0)){
if (!(cout_verbosity > 1) && !(file_verbosity > 0)){
std::cerr << "problem with options : cmse not requested, thus : valinfn has been set to " << valinfn << " but verbosity is not compatible : cout_verbosity is " << cout_verbosity << " and file_verbosity is " << file_verbosity << " . It is required that cout_verbosity > 1 or file_verbosirt > 0" << std::endl;
return 1;
}
Expand All @@ -628,48 +629,48 @@ int main(int argc, char* argv[]){
return 1;
}

if (uopts.options["cinfn"].isset and uopts.options["ioutfn"].isset){
if (uopts.options["cinfn"].isset && uopts.options["ioutfn"].isset){
std::cerr << "problem with options : cannot set both cinfn and ioutfn" << std::endl;
return 1;
}

if ((uopts.options["soutfn"].isset and (file_verbosity != 2 and file_verbosity != 3) )){
if ((uopts.options["soutfn"].isset && (file_verbosity != 2 && file_verbosity != 3) )){
std::cerr << "problem with options : soutfn is set, but file_verbosity is set to " << file_verbosity << ", either unset soutfn or set file_verbosity to 2 (or 3, but then include voutfn as well)" << std::endl;
return 1;
}

if ((uopts.options["voutfn"].isset and file_verbosity != 3)){
if ((uopts.options["voutfn"].isset && file_verbosity != 3)){
std::cerr << "problem with options : voutfn is set, but file_verbosity is set to " << file_verbosity << ", either unset voutfn or set file_verbosity to 3" << std::endl;
return 1;
}

if ((uopts.options["moutfn"].isset and nruns == 1)){
if ((uopts.options["moutfn"].isset && nruns == 1)){
std::cerr << "problem with options : moutfn is set, nruns is 1, either unset moutfn or set nruns to be greater than 1" << std::endl;
return 1;
}

if ((uopts.options["moutdir"].isset and nruns == 1)){
if ((uopts.options["moutdir"].isset && nruns == 1)){
std::cerr << "problem with options : moutdir is set, nruns is 1, either unset moutdir or set nruns to be greater than 1" << std::endl;
return 1;
}

if ((uopts.options["voutfn"].isset and nruns != 1)){
if ((uopts.options["voutfn"].isset && nruns != 1)){
std::cerr << "problem with options : voutfn is set, nruns is " << nruns << ", either unset voutfn or set nruns to 1" << std::endl;
return 1;
}

if ((uopts.options["soutfn"].isset and nruns != 1)){
if ((uopts.options["soutfn"].isset && nruns != 1)){
std::cerr << "problem with options : soutfn is set, nruns is " << nruns << ", this combination is currently not supported, either unset soutfn or set nruns to 1" << std::endl;
return 1;
}


if ((uopts.options["voutfn"].isset == false and file_verbosity == 3)){
if ((uopts.options["voutfn"].isset == false && file_verbosity == 3)){
std::cerr << "problem with options : voutfn is not set, but file_verbosity is set to 3, either lower file_verbosity to 0 or 2, or set voutfn" << std::endl;
return 1;
}

if (nruns != 1 and (uopts.options["cinfn"].isset || uopts.options["ind0fn"].isset )){
if (nruns != 1 && (uopts.options["cinfn"].isset || uopts.options["ind0fn"].isset )){
std::cerr << "problem with options : nruns is set to " << nruns << ", but either cinfn or ind0fn is set. For nruns > 1, it is currently not possible to initialise from prespecified centroids or indices. Either reduce nruns to 1, or make sure neither cinfn nor indofn are set. With nruns > 1, init0 may be set. " << std::endl;
return 1;
}
Expand All @@ -682,8 +683,8 @@ int main(int argc, char* argv[]){


if (
(uopts.options["cmsewritefn"].isset and !(uopts.options["cmserate"].isset)) ||
(!(uopts.options["cmsewritefn"].isset) and uopts.options["cmserate"].isset))
(uopts.options["cmsewritefn"].isset && !(uopts.options["cmserate"].isset)) ||
(!(uopts.options["cmsewritefn"].isset) && uopts.options["cmserate"].isset))
{
std::cerr << "problem with options : either 0 or 2 of cmsewritefn and cmserate need to be set\n";
return 1;
Expand Down
6 changes: 4 additions & 2 deletions src/stringutilbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ COPYING for more details.
#include "stringutilbase.h"
#include <stdexcept>
#include <iostream>
#include <algorithm>

namespace stringutil{
//split the string tosplit by delim. With x appearances of delim in tosplit, the returned vector will have length x + 1 (even if appearances at the start, end, contiguous.
std::vector<std::string> split(const std::string & tosplit, const std::string & delim){
Expand Down Expand Up @@ -63,12 +65,12 @@ std::vector<std::string> split(const std::string & tosplit){
unsigned it = 0;

while (it != tosplit.size()){
while (isws(tosplit[it]) and it != tosplit.size()){
while (isws(tosplit[it]) && it != tosplit.size()){
++it;
}
unsigned start = it;

while (!isws(tosplit[it]) and it != tosplit.size()){
while (!isws(tosplit[it]) && it != tosplit.size()){
++it;
}
unsigned end = it;
Expand Down
2 changes: 1 addition & 1 deletion src/stringutilfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool file_has_2int_header(const std::string & filename){
return false;
}
/* next test that they are indeed integers */
if (is_integer(bob[0]) and is_integer(bob[1])){
if (is_integer(bob[0]) && is_integer(bob[1])){
return true;
}

Expand Down