Skip to content

Commit

Permalink
cmake: Decouple bioformats cmake logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger Leigh committed Jun 10, 2015
1 parent 1f4e8a9 commit 2a4a08b
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 10 deletions.
19 changes: 11 additions & 8 deletions CMakeLists.txt
Expand Up @@ -47,7 +47,11 @@ project(openmicroscopy)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

include(components/tools/OmeroCpp/cmake/Version.cmake)
set(OMERO_CPP_DIR components/tools/OmeroCpp)
set(OMERO_CPP_SOURCE_DIR ${PROJECT_SOURCE_DIR}/${OMERO_CPP_DIR})
set(OMERO_CPP_BINARY_DIR ${PROJECT_BINARY_DIR}/${OMERO_CPP_DIR})

include(${OMERO_CPP_DIR}/cmake/Version.cmake)

if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
message(FATAL_ERROR "In-tree builds are not supported; please run cmake from a separate build directory.")
Expand All @@ -56,8 +60,7 @@ endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
enable_language(CXX)

list(APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/components/bioformats/cpp/cmake"
"${PROJECT_SOURCE_DIR}/components/tools/OmeroCpp/cmake")
"${OMERO_CPP_SOURCE_DIR}/cmake")

include(CheckIncludeFileCXX)
include(CheckCXXCompilerFlag)
Expand Down Expand Up @@ -117,13 +120,13 @@ else(NOT EXISTS ${PROJECT_SOURCE_DIR}/components/blitz/generated/omero/model/Ima
message(STATUS "C++ and Ice sources already generated; skipping running build.py")
endif(NOT EXISTS ${PROJECT_SOURCE_DIR}/components/blitz/generated/omero/model/Image.ice)

add_subdirectory(components/tools/OmeroCpp)
add_subdirectory(${OMERO_CPP_DIR})
add_subdirectory(examples)

set(LIBRARY_PREFIX OME)
configure_file(${PROJECT_SOURCE_DIR}/components/bioformats/cpp/cmake/TemplateShellConfig.cmake.in
${PROJECT_BINARY_DIR}/config)
configure_file(${OMERO_CPP_SOURCE_DIR}/cmake/TemplateShellConfig.cmake.in
${PROJECT_BINARY_DIR}/config @ONLY)
if(WIN32)
configure_file(${PROJECT_SOURCE_DIR}/components/bioformats/cpp/cmake/TemplateCmdConfig.cmake.in
${PROJECT_BINARY_DIR}/config.bat)
configure_file(${OMERO_CPP_SOURCE_DIR}/cmake/TemplateCmdConfig.cmake.in
${PROJECT_BINARY_DIR}/config.bat @ONLY)
endif()
4 changes: 2 additions & 2 deletions components/tools/OmeroCpp/CMakeLists.txt
Expand Up @@ -422,15 +422,15 @@ install(FILES ${OMERO_CLIENT_STATIC_UTIL_HEADERS}
set(LIBRARY_PREFIX OMERO_ICE)
set(LIBRARY_NAME omero-ice)
set(LIBRARY_HEADER omero/RTypes.h)
configure_file(${PROJECT_SOURCE_DIR}/components/bioformats/cpp/cmake/TemplateConfig.cmake.in
configure_file(${OMERO_CPP_SOURCE_DIR}/cmake/TemplateConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/omero-ice-config.cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/omero-ice-config.cmake
DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cmake)

set(LIBRARY_PREFIX OMERO_CLIENT)
set(LIBRARY_NAME omero-client)
set(LIBRARY_HEADER omero/client.h)
configure_file(${PROJECT_SOURCE_DIR}/components/bioformats/cpp/cmake/TemplateConfig.cmake.in
configure_file(${OMERO_CPP_SOURCE_DIR}/cmake/TemplateConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/omero-client-config.cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/omero-client-config.cmake
DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cmake)
Expand Down
286 changes: 286 additions & 0 deletions components/tools/OmeroCpp/cmake/CompilerChecks.cmake
@@ -0,0 +1,286 @@
# #%L
# Bio-Formats C++ libraries (cmake build infrastructure)
# %%
# Copyright © 2006 - 2015 Open Microscopy Environment:
# - Massachusetts Institute of Technology
# - National Institutes of Health
# - University of Dundee
# - Board of Regents of the University of Wisconsin-Madison
# - Glencoe Software, Inc.
# %%
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of any organization.
# #L%

# Use new variable expansion policy.
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
endif(POLICY CMP0053)
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif(POLICY CMP0054)

function(cxx_std_check flag var)
check_cxx_compiler_flag("${flag}" ${var})
if (${var})
set(CMAKE_CXX_FLAGS_SAVE "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")

check_cxx_source_compiles("#include <cstdarg>
void format(const char *fmt, va_list ap)
{
va_list ap2;
va_copy(ap2, ap);
}
int main() {
}"
"${var}_CSTDARG")

check_cxx_source_compiles("#include <stdarg.h>
void format(const char *fmt, va_list ap)
{
va_list ap2;
va_copy(ap2, ap);
}
int main() {
}"
"${var}_STDARG")

if("${var}" STREQUAL "CXX_FLAG_CXX11")
check_cxx_source_compiles("#include <type_traits>
// overloads are enabled via the return type
template<class T>
typename std::enable_if<std::is_floating_point<T>::value, T>::type
test(T t)
{
return t;
}
int main()
{
test(2.4);
}"
"${var}_ENABLE_IF")
endif("${var}" STREQUAL "CXX_FLAG_CXX11")
else(${var})
set("${var}_CSTDARG" OFF)
set("${var}_STDARG" OFF)
set("${var}_ENABLE_IF" OFF)
endif(${var})

if(${${var}_CSTDARG} OR ${${var}_STDARG})
set(${var} ${${var}} PARENT_SCOPE)
else()
set(${var} FALSE PARENT_SCOPE)
endif()

if("${var}" STREQUAL "CXX_FLAG_CXX11")
if(${var} AND NOT ${${var}_ENABLE_IF})
set(${var} FALSE PARENT_SCOPE)
endif()
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_SAVE}")
endfunction(cxx_std_check)


# Try to put the compiler into the most recent standard mode. This
# will generally have the most features, and will remove the need for
# Boost fallbacks if native implementations are available.
option(cxxstd-autodetect "Enable C++14 features if possible, otherwise fall back to C++11, C++03 or C++98" OFF)
if (cxxstd-autodetect)
if (NOT MSVC)
cxx_std_check(-std=c++14 CXX_FLAG_CXX14)
if (CXX_FLAG_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
cxx_std_check(-std=c++11 CXX_FLAG_CXX11)
if (CXX_FLAG_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
cxx_std_check(-std=c++03 CXX_FLAG_CXX03)
if (CXX_FLAG_CXX03)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
else()
cxx_std_check(-std=c++98 CXX_FLAG_CXX98)
if (CXX_FLAG_CXX98)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
else()
cxx_std_check("" CXX_FLAG_NONE)
if (NOT CXX_FLAG_NONE)
message(WARNING "Could not determine compiler options for enabling the most recent C++ standard; this might be expected for your compiler")
endif (NOT CXX_FLAG_NONE)
endif(CXX_FLAG_CXX98)
endif(CXX_FLAG_CXX03)
endif(CXX_FLAG_CXX11)
endif(CXX_FLAG_CXX14)
endif (NOT MSVC)
endif (cxxstd-autodetect)

# Try to enable the -pedantic flag. This one needs special casing
# since it may break building with older compilers where int64_t (long
# long) isn't available in pedantic mode because it's not part of the
# C++98 standard. Newer compilers support long long properly.
if (NOT MSVC)
set(flag -pedantic)
set(test_cxx_flag "CXX_FLAG${flag}")
CHECK_CXX_COMPILER_FLAG(${flag} "${test_cxx_flag}")
if (${test_cxx_flag})
SET(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
check_cxx_source_compiles(
"int main() {
long long l;
}"
CXX_PEDANTIC_LONG_LONG)
SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
if (${CXX_PEDANTIC_LONG_LONG})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif (${CXX_PEDANTIC_LONG_LONG})
endif (${test_cxx_flag})
endif (NOT MSVC)

# These are annoyingly verbose, produce false positives or don't work
# nicely with all supported compiler versions, so are disabled unless
# explicitly enabled.
option(extra-warnings "Enable extra compiler warnings" OFF)

# This will cause the compiler to fail when an error occurs.
option(fatal-warnings "Compiler warnings are errors" OFF)

# Check if the compiler supports each of the following additional
# warning flags, and enable them if supported. This greatly improves
# the quality of the build by checking for a number of common
# problems, some of which are quite serious.
if (NOT MSVC)
set(test_flags
-Wall
-Wcast-align
-Wcast-qual
-Wctor-dtor-privacy
-Wextra
-Wformat=2
-Wimplicit-atomic-properties
-Wmissing-declarations
-Wno-long-long
-Wnon-virtual-dtor
-Wold-style-cast
-Woverlength-strings
-Woverloaded-virtual
-Wredundant-decls
-Wreorder
-Wswitch-default
-Wunused-variable
-Wwrite-strings
-fstrict-aliasing)
if (extra-warnings)
list(APPEND test_flags
-Wconversion
-Wdocumentation
-Wfloat-equal
-Wmissing-prototypes
-Wunreachable-code)
endif (extra-warnings)
if (fatal-warnings)
list(APPEND test_flags
-Werror)
endif (fatal-warnings)
else (NOT MSVC)
set(test_flags
/bigobj)
if (extra-warnings)
list(APPEND test_flags
/W4)
else (extra-warnings)
list(APPEND test_flags
/W3)
endif (extra-warnings)
if (fatal-warnings)
list(APPEND test_flags
/WX)
endif (fatal-warnings)
endif (NOT MSVC)

foreach(flag ${test_flags})
string(REGEX REPLACE "[^A-Za-z0-9]" "_" flag_var "${flag}")
set(test_cxx_flag "CXX_FLAG${flag_var}")
CHECK_CXX_COMPILER_FLAG(${flag} "${test_cxx_flag}")
if (${test_cxx_flag})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif (${test_cxx_flag})
endforeach(flag ${test_flags})

check_cxx_source_compiles("
#include <tuple>
int main() { std::tuple<int,double> t; }
" OME_HAVE_TUPLE)

check_cxx_source_compiles("
#include <tr1/tuple>
int main() { std::tr1::tuple<int,double> t; }
" OME_HAVE_TR1_TUPLE)

check_cxx_source_compiles("
#include <cstdint>
int main() { uint16_t test(134); }
" OME_HAVE_CSTDINT)

check_cxx_source_compiles("
#include <memory>
struct foo : public ome::compat::enable_shared_from_this<foo>
{
foo() {}
};
int main() { ome::compat::shared_ptr<foo> f(new foo()); }
" OME_HAVE_MEMORY)

check_cxx_source_compiles("
void foo() noexcept{}
int main() { foo(); }
" OME_HAVE_NOEXCEPT)

check_cxx_source_compiles("
#include <array>
int main() { std::array<int,3> a; a[0] = 5; }
" OME_HAVE_ARRAY)

check_cxx_source_compiles("
#include <cstdarg>
void print(const char *fmt, ...)
{
va_list va1, va2;
va_start(va1, fmt);
va_copy(va2, va1);
va_end(va1);
}
int main() { print(\"%d %s\", 43, \"test\"); }
" OME_HAVE_CSTDARG)

0 comments on commit 2a4a08b

Please sign in to comment.