diff --git a/CMakeLists.txt b/CMakeLists.txt index e4e1d4d7..ff33bfbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,8 @@ else() endif() set(COMPREHENSIVE_WARNING_FLAGS "-Wall -Wextra -Wpedantic -pedantic-errors -Werror -Wfatal-errors -Wno-psabi") set(CMAKE_CXX_FLAGS "${MORPH_HOST_DEFINITION} -g ${COMPREHENSIVE_WARNING_FLAGS} -march=native -O3") + # Make it possible to compile complex constexpr functions + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fconstexpr-ops-limit=5000000000") endif() else() # Windows # Set flags for Windows. /EHsc required for use of exceptions @@ -175,9 +177,6 @@ if(wxWidgets_FOUND) endif() endif() -# Make it possible to compile complex constexpr functions -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fconstexpr-ops-limit=5000000000") - # rapidxml is bundled in the source, but its headers will be installed in ${CMAKE_INSTALL_PREFIX}/morph/, and they're symlinked in ${PROJECT_SOURCE_DIR}/morph #include_directories("${PROJECT_SOURCE_DIR}/include/rapidxml-1.13") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7d194186..3ea4e1cd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -155,10 +155,14 @@ if(ARMADILLO_FOUND) target_link_libraries(grid_image GLEW::GLEW) endif() - add_executable(grid_resampled_image grid_resampled_image.cpp) - target_link_libraries(grid_resampled_image OpenGL::GL glfw Freetype::Freetype) - if(USE_GLEW) - target_link_libraries(grid_resampled_image GLEW::GLEW) + # Like HexGrid::resampleImage, this one uses an omp call that only works on Mac with + # libomp, so avoid compiling this example on a Mac. + if(NOT APPLE) + add_executable(grid_resampled_image grid_resampled_image.cpp) + target_link_libraries(grid_resampled_image OpenGL::GL glfw Freetype::Freetype) + if(USE_GLEW) + target_link_libraries(grid_resampled_image GLEW::GLEW) + endif() endif() add_executable(grid_layout grid_layout.cpp) @@ -215,16 +219,19 @@ if(USE_GLEW) target_link_libraries(scatter GLEW::GLEW) endif() -add_executable(scatter_ico scatter_ico.cpp) -target_link_libraries(scatter_ico OpenGL::GL glfw Freetype::Freetype) -if(USE_GLEW) - target_link_libraries(scatter_ico GLEW::GLEW) -endif() +# This sphere example uses constexpr code +if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + add_executable(scatter_ico scatter_ico.cpp) + target_link_libraries(scatter_ico OpenGL::GL glfw Freetype::Freetype) + if(USE_GLEW) + target_link_libraries(scatter_ico GLEW::GLEW) + endif() -add_executable(scatter_geodesic scatter_geodesic.cpp) -target_link_libraries(scatter_geodesic OpenGL::GL glfw Freetype::Freetype) -if(USE_GLEW) - target_link_libraries(scatter_geodesic GLEW::GLEW) + add_executable(scatter_geodesic scatter_geodesic.cpp) + target_link_libraries(scatter_geodesic OpenGL::GL glfw Freetype::Freetype) + if(USE_GLEW) + target_link_libraries(scatter_geodesic GLEW::GLEW) + endif() endif() add_executable(scatter_hex_mercator scatter_hex_mercator.cpp) @@ -341,10 +348,13 @@ if(USE_GLEW) target_link_libraries(rod GLEW::GLEW) endif() -add_executable(grating grating.cpp) -target_link_libraries(grating OpenGL::GL glfw Freetype::Freetype) -if(USE_GLEW) - target_link_libraries(grating GLEW::GLEW) +# This example uses constexpr code +if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + add_executable(grating grating.cpp) + target_link_libraries(grating OpenGL::GL glfw Freetype::Freetype) + if(USE_GLEW) + target_link_libraries(grating GLEW::GLEW) + endif() endif() add_executable(cone cone.cpp) @@ -353,36 +363,42 @@ if(USE_GLEW) target_link_libraries(cone GLEW::GLEW) endif() -add_executable(sphere sphere.cpp) -target_link_libraries(sphere OpenGL::GL glfw Freetype::Freetype) -set_property(TARGET sphere PROPERTY CXX_STANDARD 20) -if(USE_GLEW) - target_link_libraries(sphere GLEW::GLEW) +# This sphere example uses constexpr code +if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + add_executable(sphere sphere.cpp) + target_link_libraries(sphere OpenGL::GL glfw Freetype::Freetype) + set_property(TARGET sphere PROPERTY CXX_STANDARD 20) + if(USE_GLEW) + target_link_libraries(sphere GLEW::GLEW) + endif() endif() -add_executable(icosahedron icosahedron.cpp) -target_link_libraries(icosahedron OpenGL::GL glfw Freetype::Freetype) -if(USE_GLEW) - target_link_libraries(icosahedron GLEW::GLEW) -endif() +# constexpr code won't work on Clang +if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + add_executable(icosahedron icosahedron.cpp) + target_link_libraries(icosahedron OpenGL::GL glfw Freetype::Freetype) + if(USE_GLEW) + target_link_libraries(icosahedron GLEW::GLEW) + endif() -# Need C++20 for the way I use constexpr here so that it is legal to -# have "a definition of a variable for which no initialization is -# performed". -add_executable(testce testce.cpp) -set_property(TARGET testce PROPERTY CXX_STANDARD 20) + # Need C++20 for the way I use constexpr here so that it is legal to + # have "a definition of a variable for which no initialization is + # performed". + add_executable(testce testce.cpp) + set_property(TARGET testce PROPERTY CXX_STANDARD 20) -add_executable(geodesic geodesic.cpp) -target_link_libraries(geodesic OpenGL::GL glfw Freetype::Freetype) -if(USE_GLEW) - target_link_libraries(geodesic GLEW::GLEW) -endif() + add_executable(geodesic geodesic.cpp) + target_link_libraries(geodesic OpenGL::GL glfw Freetype::Freetype) + if(USE_GLEW) + target_link_libraries(geodesic GLEW::GLEW) + endif() -add_executable(geodesic_ce geodesic_ce.cpp) -set_property(TARGET geodesic_ce PROPERTY CXX_STANDARD 20) -target_link_libraries(geodesic_ce OpenGL::GL glfw Freetype::Freetype) -if(USE_GLEW) - target_link_libraries(geodesic_ce GLEW::GLEW) + add_executable(geodesic_ce geodesic_ce.cpp) + set_property(TARGET geodesic_ce PROPERTY CXX_STANDARD 20) + target_link_libraries(geodesic_ce OpenGL::GL glfw Freetype::Freetype) + if(USE_GLEW) + target_link_libraries(geodesic_ce GLEW::GLEW) + endif() endif() add_executable(tri tri.cpp) diff --git a/examples/helloworld.cpp b/examples/helloworld.cpp index c79f92a6..93b81935 100644 --- a/examples/helloworld.cpp +++ b/examples/helloworld.cpp @@ -1,7 +1,7 @@ #include int main() { - morph::Visual v(600, 400, "Hello World!"); + morph::Visual v(600, 400, "Hello World!"); v.addLabel ("Hello World!", {0,0,0}); v.keepOpen(); return 0; diff --git a/morph/AllocAndRead.h b/morph/AllocAndRead.h index 78b8176d..3699f541 100644 --- a/morph/AllocAndRead.h +++ b/morph/AllocAndRead.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/morph/BezCurve.h b/morph/BezCurve.h index 954be072..f0530289 100644 --- a/morph/BezCurve.h +++ b/morph/BezCurve.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #ifdef __ICC__ # define ARMA_ALLOW_FAKE_GCC 1 #endif diff --git a/morph/ColourMap_Lists.h b/morph/ColourMap_Lists.h index 3b3c671b..f80b93d2 100644 --- a/morph/ColourMap_Lists.h +++ b/morph/ColourMap_Lists.h @@ -1,6 +1,6 @@ #pragma once -#include +#include /*! * Listed colour maps, copied from _cm_listed.py diff --git a/morph/HdfData.h b/morph/HdfData.h index ffe6a1d8..680c9cd6 100644 --- a/morph/HdfData.h +++ b/morph/HdfData.h @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/morph/MathAlgo.h b/morph/MathAlgo.h index 893056fa..5176f974 100644 --- a/morph/MathAlgo.h +++ b/morph/MathAlgo.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/morph/PointRowsVisual.h b/morph/PointRowsVisual.h index 40abf699..944f3ede 100644 --- a/morph/PointRowsVisual.h +++ b/morph/PointRowsVisual.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace morph { diff --git a/morph/Random.h b/morph/Random.h index a08ac1bf..dfc8b2cb 100644 --- a/morph/Random.h +++ b/morph/Random.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include /*! diff --git a/morph/Scale.h b/morph/Scale.h index 28fd3c90..859c2eeb 100644 --- a/morph/Scale.h +++ b/morph/Scale.h @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include #include @@ -77,7 +77,7 @@ namespace morph { * integers. */ template - class ScaleImplBase + struct ScaleImplBase { public: /*! diff --git a/morph/Visual.h b/morph/Visual.h index 014d1c7d..a9caf6bb 100644 --- a/morph/Visual.h +++ b/morph/Visual.h @@ -78,7 +78,7 @@ #include #include #include -#include +#include #include diff --git a/morph/VisualModel.h b/morph/VisualModel.h index 00983e7e..21c7cb32 100644 --- a/morph/VisualModel.h +++ b/morph/VisualModel.h @@ -44,7 +44,7 @@ #include #include #include -#include +#include // Switches on some changes where I carefully unbind gl buffers after calling // glBufferData() and rebind when changing the vertex model. Makes no difference on my diff --git a/morph/bn/Basins.h b/morph/bn/Basins.h index d1fe0ab5..0feb55da 100644 --- a/morph/bn/Basins.h +++ b/morph/bn/Basins.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include namespace morph { namespace bn { diff --git a/morph/bn/GeneNet.h b/morph/bn/GeneNet.h index 6a6d14aa..b3369903 100644 --- a/morph/bn/GeneNet.h +++ b/morph/bn/GeneNet.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include // Using intrinsics for computing Hamming distances #include diff --git a/morph/bn/GeneNetDual.h b/morph/bn/GeneNetDual.h index e7b65ff7..9eebc57a 100644 --- a/morph/bn/GeneNetDual.h +++ b/morph/bn/GeneNetDual.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace morph { namespace bn { diff --git a/morph/bn/Genome.h b/morph/bn/Genome.h index 423a1fcc..39430f77 100644 --- a/morph/bn/Genome.h +++ b/morph/bn/Genome.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/morph/bn/Genosect.h b/morph/bn/Genosect.h index 51f660a1..e514e29a 100644 --- a/morph/bn/Genosect.h +++ b/morph/bn/Genosect.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace morph { namespace bn { diff --git a/morph/bn/GradGenome.h b/morph/bn/GradGenome.h index dd8f5f4c..1968ea88 100644 --- a/morph/bn/GradGenome.h +++ b/morph/bn/GradGenome.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/morph/bn/GradGenosect.h b/morph/bn/GradGenosect.h index 0786bb59..c247d87f 100644 --- a/morph/bn/GradGenosect.h +++ b/morph/bn/GradGenosect.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace morph { namespace bn { diff --git a/morph/bn/Quine.h b/morph/bn/Quine.h index e91a8d54..c3c9a6b0 100644 --- a/morph/bn/Quine.h +++ b/morph/bn/Quine.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include diff --git a/morph/bn/Random.h b/morph/bn/Random.h index fb5534c6..b47bbcc6 100644 --- a/morph/bn/Random.h +++ b/morph/bn/Random.h @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include #include diff --git a/morph/gl/compute_shaderprog.h b/morph/gl/compute_shaderprog.h index c4e22695..806a8ca5 100644 --- a/morph/gl/compute_shaderprog.h +++ b/morph/gl/compute_shaderprog.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/morph/gl/shaders.h b/morph/gl/shaders.h index c65dc199..0536c7f9 100644 --- a/morph/gl/shaders.h +++ b/morph/gl/shaders.h @@ -130,12 +130,12 @@ namespace morph { if (morph::Tools::fileExists (entry.filename)) { std::cout << "Using " << morph::gl::shader_type_str(entry.type) << " shader from the file " << entry.filename << std::endl; - source = std::move (morph::gl::ReadShader (entry.filename)); + source = morph::gl::ReadShader (entry.filename); } else { if constexpr (debug_shaders == true) { std::cout << "Using compiled-in " << morph::gl::shader_type_str(entry.type) << " shader\n"; } - source = std::move (morph::gl::ReadDefaultShader (entry.compiledIn)); + source = morph::gl::ReadDefaultShader (entry.compiledIn); } if (source == nullptr) { for (auto entry : shader_info) { diff --git a/morph/gl/ssbo.h b/morph/gl/ssbo.h index 56e12149..f2aabf8d 100644 --- a/morph/gl/ssbo.h +++ b/morph/gl/ssbo.h @@ -9,7 +9,7 @@ * Author: Seb James. */ -#include +#include #include #include #include diff --git a/morph/loadpng.h b/morph/loadpng.h index c2dbe614..71f709b3 100644 --- a/morph/loadpng.h +++ b/morph/loadpng.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/morph/vec.h b/morph/vec.h index cd651022..2e5f5c90 100644 --- a/morph/vec.h +++ b/morph/vec.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include diff --git a/morph/vvec.h b/morph/vvec.h index c81ce4b7..7dd59853 100644 --- a/morph/vvec.h +++ b/morph/vvec.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7400c8b0..efd3c623 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -249,21 +249,27 @@ add_test(testConfig testConfig) add_executable(testQuaternion testQuaternion.cpp) add_test(testQuaternion testQuaternion) -add_executable(testQuat_constexpr testQuat_constexpr.cpp) -set_property(TARGET testQuat_constexpr PROPERTY CXX_STANDARD 20) -add_test(testQuat_constexpr testQuat_constexpr) +# Note that we only compile the constexpr tests if compiler is not Clang. Clang doesn't like std::abs, +# std::sin (etc) within a constexpr function. +if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + add_executable(testQuat_constexpr testQuat_constexpr.cpp) + set_property(TARGET testQuat_constexpr PROPERTY CXX_STANDARD 20) + add_test(testQuat_constexpr testQuat_constexpr) +endif() # test morph::vec. add_executable(testvec testvec.cpp) add_test(testvec testvec) -# constexpr functionality in morph::vec -# Need C++20 for the way I use constexpr here so that it is legal to -# have "a definition of a variable for which no initialization is -# performed". -add_executable(testvec_constexpr testvec_constexpr.cpp) -set_property(TARGET testvec_constexpr PROPERTY CXX_STANDARD 20) -add_test(testvec_constexpr testvec_constexpr) +if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + # constexpr functionality in morph::vec + # Need C++20 for the way I use constexpr here so that it is legal to + # have "a definition of a variable for which no initialization is + # performed". + add_executable(testvec_constexpr testvec_constexpr.cpp) + set_property(TARGET testvec_constexpr PROPERTY CXX_STANDARD 20) + add_test(testvec_constexpr testvec_constexpr) +endif() add_executable(testvec_asmapkey testvec_asmapkey.cpp) add_test(testvec_asmapkey testvec_asmapkey) @@ -328,10 +334,12 @@ add_test(testScaleVector testScaleVector) add_executable(testTransformMatrix testTransformMatrix.cpp) add_test(testTransformMatrix testTransformMatrix) -# constexpr TransformMatrix -add_executable(testTransMat_constexpr testTransMat_constexpr.cpp) -set_property(TARGET testTransMat_constexpr PROPERTY CXX_STANDARD 20) -add_test(testTransMat_constexpr testTransMat_constexpr) +if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + # constexpr TransformMatrix + add_executable(testTransMat_constexpr testTransMat_constexpr.cpp) + set_property(TARGET testTransMat_constexpr PROPERTY CXX_STANDARD 20) + add_test(testTransMat_constexpr testTransMat_constexpr) +endif() # Test morph::Matrix33 (3x3 matrix) add_executable(testMatrix33 testMatrix33.cpp)