Commit 01ab6889 authored by Kenneth Moreland's avatar Kenneth Moreland

Target link libraries only as necessary.

Previously, the OpenGL and MPI libraries were linked to everything
with a general LINK_LIBRARIES CMake command.  Now, only use
TARGET_LINK_LIBRARIES to bind libraries to a specific target.  Not
only is this cleaner, but it also helps verify that libraries that
should not depend on these libraries don't.
parent d2ca846a
......@@ -7,10 +7,7 @@
#
PROJECT(ICET C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
IF(COMMAND cmake_policy)
CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
# Set the current ICE-T version.
SET(ICET_MAJOR_VERSION 2)
......@@ -32,6 +29,10 @@ SET(C_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
OPTION(BUILD_SHARED_LIBS "Build ICE-T with shared libraries." OFF)
SET(ICET_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
# Options controlling support libraries
OPTION(ICET_USE_OPENGL "Build OpenGL support layer for IceT." ON)
OPTION(ICET_USE_MPI "Build MPI communication layer for IceT." ON)
# Configure testing support.
INCLUDE(Dart)
IF (BUILD_TESTING)
......@@ -44,51 +45,68 @@ ENDIF (CMAKE_BUILD_TYPE MATCHES "Debug")
# Configure OpenGL support.
FIND_PACKAGE(OpenGL)
IF (OPENGL_FOUND)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
LINK_LIBRARIES(${OPENGL_LIBRARIES})
ELSE (OPENGL_FOUND)
FIND_PACKAGE(OSMesa)
IF (OSMESA_INCLUDE_DIR AND OSMESA_LIBRARY)
INCLUDE_DIRECTORIES(${OSMESA_INCLUDE_DIR})
LINK_LIBRARIES(${OSMESA_LIBRARY})
ELSE(OSMESA_INCLUDE_DIR AND OSMESA_LIBRARY)
MESSAGE(SEND_ERROR "Could not find OpenGL or OSMesa, which is required to compile ICE-T.")
ENDIF (OSMESA_INCLUDE_DIR AND OSMESA_LIBRARY)
ENDIF (OPENGL_FOUND)
IF (ICET_USE_OPENGL)
FIND_PACKAGE(OpenGL)
IF (OPENGL_FOUND)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
SET(ICET_OPENGL_LIBRARIES ${OPENGL_LIBRARIES})
ELSE (OPENGL_FOUND)
FIND_PACKAGE(OSMesa)
IF (OSMESA_INCLUDE_DIR AND OSMESA_LIBRARY)
INCLUDE_DIRECTORIES(${OSMESA_INCLUDE_DIR})
SET(ICET_OPENGL_LIBRARIES ${OSMESA_LIBRARY})
ELSE(OSMESA_INCLUDE_DIR AND OSMESA_LIBRARY)
MESSAGE(SEND_ERROR "Could not find OpenGL or OSMesa, which is required when ICET_USE_OPENGL is ON.")
ENDIF (OSMESA_INCLUDE_DIR AND OSMESA_LIBRARY)
ENDIF (OPENGL_FOUND)
ENDIF (ICET_USE_OPENGL)
# Configure MPI support.
FIND_PACKAGE(MPI)
MARK_AS_ADVANCED(CLEAR MPI_INCLUDE_PATH)
MARK_AS_ADVANCED(CLEAR MPI_LIBRARY)
MARK_AS_ADVANCED(CLEAR MPI_EXTRA_LIBRARY)
IF (MPI_INCLUDE_PATH)
IF (ICET_USE_MPI)
FIND_PACKAGE(MPI REQUIRED)
MARK_AS_ADVANCED(CLEAR MPI_INCLUDE_PATH)
MARK_AS_ADVANCED(CLEAR MPI_LIBRARY)
MARK_AS_ADVANCED(CLEAR MPI_EXTRA_LIBRARY)
INCLUDE_DIRECTORIES(${MPI_INCLUDE_PATH})
ELSE (MPI_INCLUDE_PATH)
MESSAGE(SEND_ERROR "Could not find MPI includes, which is required to compile ICE-T.")
ENDIF (MPI_INCLUDE_PATH)
IF (MPI_LIBRARY)
LINK_LIBRARIES(${MPI_LIBRARY})
ELSE (MPI_LIBRARY)
MESSAGE(SEND_ERROR "Could not find MPI library, which is required to compile ICE-T.")
ENDIF (MPI_LIBRARY)
IF (MPI_EXTRA_LIBRARY)
LINK_LIBRARIES(${MPI_EXTRA_LIBRARY})
ENDIF (MPI_EXTRA_LIBRARY)
# Configure MPI testing support.
IF (BUILD_TESTING)
OPTION(ICET_BUILD_TESTING "Build and run the ICE-T tests." ON)
FIND_PROGRAM(ICET_MPIRUN_EXE NAMES mpirun lamexec)
SET(ICET_MPI_PREFLAGS "-np;2" CACHE STRING "Flags used by MPI start program.")
SET(ICET_MPI_POSTFLAGS "" CACHE STRING "Flags used by MPI start program.")
SET(ICET_MPI_LIBRARIES ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY})
# Set up variables used to run MPI programs. In CMake 2.8 or later, they are
# defined by the FindMPI module.
IF (MPIEXEC)
SET(ICET_MPIRUN_EXE ${MPIEXEC})
SET(ICET_MPI_NUMPROC_FLAG ${MPIEXEC_NUMPROC_FLAG})
SET(ICET_MPI_PREFLAGS ${MPIEXEC_PREFLAGS})
SET(ICET_MPI_POSTFLAGS ${MPIEXEC_POSTFLAGS})
ELSE (MPIEXEC)
FIND_PROGRAM(ICET_MPIRUN_EXE NAMES mpiexec mpirun lamexec)
SET(ICET_MPI_NUMPROC_FLAG "-np" CACHE STRING "Flag used by MPI start program. Used to specify the number of processes.")
SET(ICET_MPI_PREFLAGS "" CACHE STRING "Flags used by MPI start program. These are placed directly before the executable.")
SET(ICET_MPI_POSTFLAGS "" CACHE STRING "Flags used by MPI start program. These are placed after all other flags.")
MARK_AS_ADVANCED(
ICET_MPIRUN_EXE
ICET_MPI_NUMPROC_FLAG
ICET_MPI_PREFLAGS
ICET_MPI_POSTFLAGS
)
ENDIF (MPIEXEC)
SET(ICET_MPI_MAX_NUMPROCS "2" CACHE STRING "Maximum number of processors available to run parallel applications.")
MARK_AS_ADVANCED(ICET_BUILD_TESTING ICET_MPIRUN_EXE ICET_MPI_PREFLAGS ICET_MPI_POSTFLAGS ICET_MPI_MAX_NUMPROCS)
MARK_AS_ADVANCED(ICET_MPI_MAX_NUMPROCS)
SEPARATE_ARGUMENTS(ICET_MPI_PREFLAGS)
SEPARATE_ARGUMENTS(ICET_MPI_POSTFLAGS)
ENDIF (ICET_USE_MPI)
# Add extra warnings when possible. The IceT build should be clean. I expect
# no warnings when bulding this code.
IF (CMAKE_COMPILER_IS_GNUCC)
SET(ICET_C_FLAGS_WARN "-ansi -pedantic -Wall -Wno-long-long -Wcast-align -Wextra -Wpointer-arith -Wformat-security -Wshadow -Wunused -Wreturn-type")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ICET_C_FLAGS_WARN}")
ENDIF (CMAKE_COMPILER_IS_GNUCC)
# Configure testing support.
IF (BUILD_TESTING)
OPTION(ICET_BUILD_TESTING "Build and run the ICE-T tests." ON)
MARK_AS_ADVANCED(ICET_BUILD_TESTING)
ENDIF (BUILD_TESTING)
# Configure data type sizes.
......@@ -145,12 +163,16 @@ INCLUDE_DIRECTORIES(${ICET_BINARY_DIR}/src/include)
ADD_SUBDIRECTORY(src)
IF (BUILD_TESTING AND ICET_BUILD_TESTING)
FIND_PACKAGE(GLUT)
IF (GLUT_FOUND)
ADD_SUBDIRECTORY(tests)
ELSE (GLUT_FOUND)
MESSAGE(STATUS "Tests require Glut, which is not found. Disabling tests.")
ENDIF (GLUT_FOUND)
IF (ICET_USE_OPENGL AND ICET_USE_MPI)
FIND_PACKAGE(GLUT)
IF (GLUT_FOUND)
ADD_SUBDIRECTORY(tests)
ELSE (GLUT_FOUND)
MESSAGE(STATUS "Tests require Glut, which is not found. Disabling tests.")
ENDIF (GLUT_FOUND)
ELSE (ICET_USE_OPENGL AND ICET_USE_MPI)
MESSAGE(STATUS "Tests require ICET_USE_OPENGL and ICET_USE_MPI. Disabling tests.")
ENDIF (ICET_USE_OPENGL AND ICET_USE_MPI)
ENDIF (BUILD_TESTING AND ICET_BUILD_TESTING)
ADD_SUBDIRECTORY(doc)
......
......@@ -7,10 +7,13 @@
#
ADD_SUBDIRECTORY(ice-t)
ADD_SUBDIRECTORY(gl)
ADD_SUBDIRECTORY(communication)
ADD_SUBDIRECTORY(strategies)
IF (ICET_USE_OPENGL)
ADD_SUBDIRECTORY(gl)
ENDIF (ICET_USE_OPENGL)
IF (NOT ICET_INSTALL_NO_DEVELOPMENT)
SET(resPath
"${CMAKE_CURRENT_SOURCE_DIR}/ice-t"
......
......@@ -9,23 +9,28 @@
#
SET(ICET_MPI_SRCS
mpi.c
)
mpi.c
)
ADD_LIBRARY(icet_mpi ${ICET_MPI_SRCS})
IF (ICET_USE_MPI)
ADD_LIBRARY(icet_mpi ${ICET_MPI_SRCS})
TARGET_LINK_LIBRARIES(icet_mpi icet)
TARGET_LINK_LIBRARIES(icet_mpi
icet
${ICET_MPI_LIBRARIES}
)
IF(NOT ICET_INSTALL_NO_LIBRARIES)
INSTALL(TARGETS icet_mpi
RUNTIME DESTINATION ${ICET_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${ICET_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${ICET_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries)
ENDIF(NOT ICET_INSTALL_NO_LIBRARIES)
IF(NOT ICET_INSTALL_NO_DEVELOPMENT)
INSTALL(FILES ${ICET_SOURCE_DIR}/src/include/IceTMPI.h
DESTINATION ${ICET_INSTALL_INCLUDE_DIR})
INSTALL(TARGETS icet_mpi
DESTINATION ${ICET_INSTALL_LIB_DIR} COMPONENT Development)
ENDIF(NOT ICET_INSTALL_NO_DEVELOPMENT)
IF(NOT ICET_INSTALL_NO_LIBRARIES)
INSTALL(TARGETS icet_mpi
RUNTIME DESTINATION ${ICET_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${ICET_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${ICET_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries)
ENDIF(NOT ICET_INSTALL_NO_LIBRARIES)
IF(NOT ICET_INSTALL_NO_DEVELOPMENT)
INSTALL(FILES ${ICET_SOURCE_DIR}/src/include/GL/ice-t_mpi.h
DESTINATION ${ICET_INSTALL_INCLUDE_DIR}/GL)
INSTALL(TARGETS icet_mpi
DESTINATION ${ICET_INSTALL_LIB_DIR} COMPONENT Development)
ENDIF(NOT ICET_INSTALL_NO_DEVELOPMENT)
ENDIF (ICET_USE_MPI)
......@@ -14,7 +14,10 @@ SET(ICET_GL_SRCS
ADD_LIBRARY(icet_gl ${ICET_GL_SRCS})
TARGET_LINK_LIBRARIES(icet_gl icet)
TARGET_LINK_LIBRARIES(icet_gl
icet
${ICET_OPENGL_LIBRARIES}
)
IF(NOT ICET_INSTALL_NO_LIBRARIES)
INSTALL(TARGETS icet_gl
......
......@@ -34,11 +34,11 @@ TARGET_LINK_LIBRARIES(icetTests_mpi
)
IF (ICET_MPIRUN_EXE)
SET(PRE_TEST_FLAGS ${ICET_MPIRUN_EXE} ${ICET_MPI_PREFLAGS})
SET(PRE_TEST_FLAGS ${ICET_MPIRUN_EXE} ${ICET_MPI_NUMPROC_FLAG} ${ICET_MPI_MAX_NUMPROCS} ${ICET_MPI_PREFLAGS})
SET(POST_TEST_FLAGS ${ICET_MPI_POSTFLAGS})
ENDIF (ICET_MPIRUN_EXE)
SET(ICET_TEST_FLAGS "" CACHE STRING "Arguments given to the test program.")
SET(ICET_TEST_FLAGS "" CACHE STRING "Arguments given to the test program. These are given between the test executable and the name of the test. Run the test executable with the -h flag to see what is available.")
MARK_AS_ADVANCED(ICET_TEST_FLAGS)
SEPARATE_ARGUMENTS(ICET_TEST_FLAGS)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment