Skip to content

Commit

Permalink
Merge pull request #652 from hibtc/opt_X11
Browse files Browse the repository at this point in the history
Make X11 optional
  • Loading branch information
tpersson committed Aug 10, 2018
2 parents 9ff1a85 + 59d136a commit 6448a10
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Makefile_c
Expand Up @@ -35,7 +35,8 @@ mad_gcst.o: CPPFLAGS += -D_VERSION=$(VERSION) \
-D_VERSION_DATE=$(VERSION_DATE) \
-D_VERSION_OSTYPE=$(OSTYPE)
mad_dict.o: CPPFLAGS += -D_VERSION_NUM=$(VERSION_NUM)
mad_gxx11c.o: CPPFLAGS += $(call incdir,/usr/X11/include /opt/X11/include)
mad_gxx11c.o: CPPFLAGS += $(call incdir,/usr/X11/include /opt/X11/include) \
$(if $(call neq,$(X11),yes),,-D_USE_X11)
mad_gxx11c.o: CFLAGS += $(if $(call neq,$(CCNAME),icc),,-diag-disable 161) \
$(if $(call neq,$(CCNAME),gcc),,-Wno-variadic-macros)
mad_dict.o: CFLAGS += $(if $(call neq,$(CCNAME),gcc),,-Wno-overlength-strings)
Expand Down
8 changes: 4 additions & 4 deletions Makefile_f90
Expand Up @@ -27,12 +27,12 @@ FC_DIR_PTC := libs/ptc/src
FC_SRC_PTC := $(notdir $(wildcard $(FC_DIR_PTC)/*.f90 $(FC_DIR_PTC)/*.F90))

# x11 dependencies
ifeq ($(OSTYPE),Windows)
FC_SRC_MAD += gxx11ps.f90
FC_SRC_RM += gxx11.f90
else
ifeq ($(X11),yes)
FC_SRC_MAD += gxx11.f90
FC_SRC_RM += gxx11ps.f90
else
FC_SRC_MAD += gxx11ps.f90
FC_SRC_RM += gxx11.f90
endif

# ptc dependencies
Expand Down
11 changes: 9 additions & 2 deletions Makefile_lib
Expand Up @@ -25,10 +25,14 @@ endif
# Libraries on Linux

ifeq ($(OSTYPE),Linux)
LIBS += $(if $(call eq,$(ARCH),32),$(call libdir,/usr/lib),) -lpthread -lX11
LIBS += $(if $(call eq,$(ARCH),32),$(call libdir,/usr/lib),) -lpthread
LDLIBS += -lstdc++ -lm
ifeq ($(X11),yes)
LIBS += -lX11
endif
endif


# Garbage Collector

ifeq ($(USEGC),yes)
Expand All @@ -40,14 +44,15 @@ endif

ifeq ($(OSTYPE),Darwin)
ifeq ($(STATIC),yes)
# X11
ifeq ($(X11),yes)
X11PATH := /opt/local/lib/
X11LIBS := libX11.a libxcb.a libXau.a libXdmcp.a
ifneq ($(wildcard /opt/local/lib/),)
LIBS += $(wildcard $(addprefix $(X11PATH),$(X11LIBS)))
else
LIBS += $(call libdir,/usr/X11/lib) -lX11
endif
endif

# C/C++
GNULIBS := $(wildcard $(call GNULIB,libstdc++.a) $(call GNULIB,libgcc_eh.a))
Expand All @@ -58,7 +63,9 @@ ifeq ($(OSTYPE),Darwin)
endif

else
ifeq ($(X11),yes)
LIBS += $(call libdir,/usr/X11/lib) -lX11
endif
LDLIBS += -lstdc++ -lm
endif

Expand Down
2 changes: 1 addition & 1 deletion Makefile_lnx
Expand Up @@ -57,7 +57,7 @@ madx-linux-nagfor: madx-linux64-nagfor madx-linux32-nagfor

LINUX_STATIC := $(if $(call eq,$(PLUGIN),yes),no,yes)

madx-linux%: MAKE_ARGS = PRJNAME=$@ DESTDIR=$(DESTDIR) ONLINE=yes STATIC=$(LINUX_STATIC) USEGC=yes APPENDLD=yes
madx-linux%: MAKE_ARGS = PRJNAME=$@ DESTDIR=$(DESTDIR) ONLINE=yes STATIC=$(LINUX_STATIC) USEGC=yes APPENDLD=yes X11=yes
madx-linux%: MAKE_OPTS = -j9 $(MAKEARGS)
madx-linux%: MAKE_LINK = ln -sf $(DESTDIR)$@ && ln -sf $@

Expand Down
2 changes: 1 addition & 1 deletion Makefile_mac
Expand Up @@ -61,7 +61,7 @@ madx-macosx-intel: madx-macosx64-intel madx-macosx32-intel

MACOSX_STATIC := $(if $(call eq,$(PLUGIN),yes),no,yes)

madx-macosx%: MAKE_ARGS = PRJNAME=$@ DESTDIR=$(DESTDIR) ONLINE=no STATIC=$(MACOSX_STATIC) USEGC=yes APPENDLD=yes
madx-macosx%: MAKE_ARGS = PRJNAME=$@ DESTDIR=$(DESTDIR) ONLINE=no STATIC=$(MACOSX_STATIC) USEGC=yes APPENDLD=yes X11=yes
madx-macosx%: MAKE_OPTS = -j9 $(MAKEARGS)
madx-macosx%: MAKE_LINK = ln -sf $(DESTDIR)$@ && ln -sf $@

Expand Down
2 changes: 1 addition & 1 deletion Makefile_win
Expand Up @@ -42,7 +42,7 @@ cleanarch:
madx-win-gnu: madx-win64-gnu madx-win32-gnu
madx-win-intel: madx-win64-intel madx-win32-intel

madx-win%: MAKE_ARGS = PRJNAME=$@ DESTDIR=$(DESTDIR) ONLINE=no STATIC=yes USEGC=yes APPENDLD=yes
madx-win%: MAKE_ARGS = PRJNAME=$@ DESTDIR=$(DESTDIR) ONLINE=no STATIC=yes USEGC=yes APPENDLD=yes X11=no
madx-win%: MAKE_OPTS = -j9 $(MAKEARGS)
madx-win%: MAKE_LINK = ln -sf $(DESTDIR)$@.exe && ln -sf $@.exe

Expand Down
6 changes: 5 additions & 1 deletion cmake/setupOptions.cmake
Expand Up @@ -6,6 +6,10 @@ option( USE_GC "Use Garbage Collector" ON)
option( MADX_NTPSA "Build with NTPSA" ON)
option( MADX_FORCE_32 "Force 32bit build" OFF)

if (NOT (WIN32 OR CYGWIN))
option( MADX_X11 "Turn on plotting using X11" ON )
endif()

if(MADX_STATIC)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib)
Expand All @@ -17,7 +21,7 @@ if(MADX_STATIC)
if(BUILD_SHARED_LIBS)
message(FATAL_ERROR "Cannot build shared libs with MADX_STATIC on")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if (MADX_X11 AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"))
link_directories(${CMAKE_SOURCE_DIR}/lib${ARCH}/) # for libX11.a
endif()
endif()
Expand Down
39 changes: 23 additions & 16 deletions src/CMakeLists.txt
Expand Up @@ -10,10 +10,13 @@ file(GLOB src_files
*.F90
*.cpp)
file(GLOB main_file mad_main.c)
if(WIN32 OR CYGWIN)
file(GLOB gxx_remove gxx11c.c gxx11.f90)

if(MADX_X11)
file(GLOB gxx_remove gxx11ps.f90)
set_property(SOURCE mad_gxx11c.c
APPEND PROPERTY COMPILE_DEFINITIONS _USE_X11)
else()
file(GLOB gxx_remove gxx11psc.c gxx11ps.f90)
file(GLOB gxx_remove gxx11.f90)
endif()

# Some source files which should not be included:
Expand Down Expand Up @@ -55,8 +58,12 @@ set_target_properties(madx PROPERTIES LINKER_LANGUAGE Fortran)

# set library version:
set_target_properties(madx PROPERTIES VERSION ${MADX_VERSION})
set_target_properties(madx PROPERTIES CXX_STANDARD 11)

if (${CMAKE_VERSION} VERSION_LESS "3.1")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
set_target_properties(madx PROPERTIES CXX_STANDARD 11)
endif()

# adding an executable:
if(MADX_BUNDLE)
Expand All @@ -74,16 +81,18 @@ target_link_libraries(madxbin madx)

# I turn off search for libraries in case you are on Linux,
# to make sure we make use of the lib/lib64 folders
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
#necessary to search for X11 for OSX instead of directly including it
find_package(X11)
if(X11_FOUND)
include_directories(${X11_INCLUDE_DIR})
target_link_libraries(madx ${X11_X11_LIB})
endif()
else()
target_link_libraries(madx X11)
endif()
if (MADX_X11)
if (MADX_STATIC AND (CMAKE_SYSTEM_NAME STREQUAL "Linux"))
target_link_libraries(madx X11)
else()
#necessary to search for X11 for OSX instead of directly including it
find_package(X11)
if(X11_FOUND)
include_directories(${X11_INCLUDE_DIR})
target_link_libraries(madx ${X11_X11_LIB})
endif()
endif()
endif ()

if(LAPACK_FOUND AND BLAS_FOUND)
target_link_libraries(madx ${LAPACK_LIBRARIES})
Expand All @@ -92,8 +101,6 @@ endif()
# Online libraries:
if(MADX_ONLINE)
target_link_libraries(madx ${SDDS_LIBRARIES})
endif()
if(NOT WIN32)
target_link_libraries(madx z)
endif()

Expand Down
4 changes: 2 additions & 2 deletions src/mad_gxx11c.c
@@ -1,4 +1,4 @@
#ifndef _WIN32
#ifdef _USE_X11

/* X include files */
#define _HPUX_SOURCE
Expand Down Expand Up @@ -284,7 +284,7 @@ wstring( char *s, int *l )
s[loc] = '\0';
}

#else // case _WIN32
#else // case _USE_X11

#include <time.h>
#include "mad_extrn_f.h"
Expand Down

0 comments on commit 6448a10

Please sign in to comment.