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

Add basic ingredients for CONDA/cl.exe build for Windows. #78

Open
wants to merge 2 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
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ if ( MCPL_ENABLE_CPACK )
include(CPack)
endif()

set(MCPL_CONDA_LIB "")
set(MCPL_CONDA_INCLUDE "")
if ( MCPL_CONDA_WINDOWS )
set(MCPL_CONDA_LIB "$ENV{CONDA_PREFIX}/Library/lib")
set(MCPL_CONDA_INCLUDE "$ENV{CONDA_PREFIX}/Library/include")
endif()

if( NOT MCPL_NOTOUCH_CMAKE_BUILD_TYPE )
if ( NOT gen_is_multicfg )
if ( "x${CMAKE_BUILD_TYPE}" STREQUAL "x" )
Expand Down Expand Up @@ -217,7 +224,8 @@ add_zlib_dependency( mcpl -DMCPL_HASZLIB )

target_include_directories(mcpl
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/mcpl>
$<INSTALL_INTERFACE:${MCPL_INCDIR}> )
$<INSTALL_INTERFACE:${MCPL_INCDIR}>
${MCPL_CONDA_INCLUDE} )

if (MATH_NEEDS_LIBM)
target_link_libraries( mcpl PRIVATE m )
Expand All @@ -233,6 +241,10 @@ install( TARGETS mcpl mcpltool EXPORT MCPLTargets ${INSTDEST} )
install( EXPORT MCPLTargets FILE MCPLTargets.cmake NAMESPACE MCPL:: DESTINATION ${MCPL_CMAKEDIR} )
add_library(MCPL::mcpl ALIAS mcpl)#always alias namespaces locally

if ( MCPL_CONDA_WINDOWS )
install( FILES "util/mcpl-config.bat" DESTINATION ${MCPL_BINDIR} )
endif()

include(CMakePackageConfigHelpers)
write_basic_package_version_file( "${PROJECT_BINARY_DIR}/MCPLConfigVersion.cmake"
VERSION ${MCPL_VERSION} COMPATIBILITY SameMajorVersion )
Expand Down
6 changes: 6 additions & 0 deletions src/mcpl/mcpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@
#include <string.h>
#include <assert.h>
#include <math.h>
// On non-cl.exe compiler, use normal <unistd.h> ...
// otherwise use local wrapper to MS-provided headers.
#ifndef _MSC_EXTENSIONS
#include <unistd.h>
#else
#include "win-unistd.h"
#endif
#include <limits.h>
#ifdef MCPL_THIS_IS_MS
# include <fcntl.h>
Expand Down
58 changes: 58 additions & 0 deletions src/mcpl/win-unistd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef _UNISTD_H
#define _UNISTD_H 1

/* This is intended as a drop-in replacement for unistd.h on Windows.
* Please add functionality as needed.
* https://stackoverflow.com/a/826027/1202830
*/

#include <stdlib.h>
#include <io.h>
// TODO: In case of cl.exe on Windows, set compile-time include to pick
// up path to conda-provided getopt.h!
#include <getopt.h>
#include <process.h> /* for getpid() and the exec..() family */
#include <direct.h> /* for _getcwd() and _chdir() */

#define srandom srand
#define random rand

/* Values for the second argument to access.
These may be OR'd together. */
#define R_OK 4 /* Test for read permission. */
#define W_OK 2 /* Test for write permission. */
//#define X_OK 1 /* execute permission - unsupported in windows*/
#define F_OK 0 /* Test for existence. */

#define access _access
#define dup2 _dup2
#define execve _execve
#define ftruncate _chsize
#define unlink _unlink
#define fileno _fileno
#define getcwd _getcwd
#define chdir _chdir
#define isatty _isatty
#define lseek _lseek
/* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */

#ifdef _WIN64
#define ssize_t __int64
#else
#define ssize_t long
#endif

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
/* should be in some equivalent to <sys/types.h> */
typedef __int8 int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;

#endif /* unistd.h */
1 change: 1 addition & 0 deletions util/mcpl-config.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@python %CONDA_PREFIX%/bin/mcpl-config %*
Loading