From 37c93ba031e18527f8ca70b8c6e733c63a5e4a30 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 13 Dec 2015 20:01:01 +0100 Subject: [PATCH] Compiler flag cleanup --- CMakeLists.txt | 26 ------------------ examples/CMakeLists.txt | 4 +++ src/CMakeLists.txt | 59 ++++++++++++++++++++++++++++------------- tests/CMakeLists.txt | 4 +++ 4 files changed, 49 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa22cc38..780917c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,17 +72,7 @@ endif() #-------------------------------------------------------------------- # Set compiler specific flags #-------------------------------------------------------------------- -if (UNIX) - add_definitions(-Wall) - - if (BUILD_SHARED_LIBS) - add_definitions(-fvisibility=hidden) - endif() -endif() - if (MSVC) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) - if (NOT USE_MSVC_RUNTIME_LIBRARY_DLL) foreach (flag CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG @@ -125,12 +115,6 @@ if (MINGW) if (_GLFW_HAS_64ASLR) set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--high-entropy-va ${CMAKE_SHARED_LINKER_FLAGS}") endif() - - # HACK: When building on MinGW, WINVER and UNICODE need to be defined before - # the inclusion of stddef.h (by glfw3.h), which is itself included before - # win32_platform.h. We define them here until a saner solution can be found - # NOTE: MinGW-w64 and Visual C++ do /not/ need this hack. - add_definitions(-DUNICODE -DWINVER=0x0501) endif() #-------------------------------------------------------------------- @@ -371,16 +355,6 @@ foreach(arg ${glfw_PKG_LIBS}) set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} ${arg}") endforeach() -#-------------------------------------------------------------------- -# Choose library output name -#-------------------------------------------------------------------- -if (BUILD_SHARED_LIBS AND UNIX) - # On Unix-like systems, shared libraries can use the soname system. - set(GLFW_LIB_NAME glfw) -else() - set(GLFW_LIB_NAME glfw3) -endif() - #-------------------------------------------------------------------- # Create generated files #-------------------------------------------------------------------- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index be261e6e..3b6e54ce 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -8,6 +8,10 @@ else() link_libraries(${glfw_LIBRARIES}) endif() +if (MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif() + include_directories("${GLFW_SOURCE_DIR}/include" "${GLFW_SOURCE_DIR}/deps") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a1153ad..0d94b4a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,4 @@ -include_directories("${GLFW_SOURCE_DIR}/src" - "${GLFW_BINARY_DIR}/src" - ${glfw_INCLUDE_DIRS}) - -add_definitions(-D_GLFW_USE_CONFIG_H) - set(common_HEADERS internal.h "${GLFW_BINARY_DIR}/src/glfw_config.h" "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" @@ -58,37 +52,66 @@ endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) set_target_properties(glfw PROPERTIES - OUTPUT_NAME "${GLFW_LIB_NAME}" VERSION ${GLFW_VERSION} SOVERSION ${GLFW_VERSION_MAJOR} POSITION_INDEPENDENT_CODE ON FOLDER "GLFW3") +target_compile_definitions(glfw PRIVATE -D_GLFW_USE_CONFIG_H) +target_include_directories(glfw PRIVATE + "${GLFW_SOURCE_DIR}/src" + "${GLFW_BINARY_DIR}/src" + ${glfw_INCLUDE_DIRS}) + +# HACK: When building on MinGW, WINVER and UNICODE need to be defined before +# the inclusion of stddef.h (by glfw3.h), which is itself included before +# win32_platform.h. We define them here until a saner solution can be found +# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack. +target_compile_definitions(glfw PRIVATE + "$<$:UNICODE;WINVER=0x0501>") + +# Enable a reasonable set of warnings (no, -Wextra is not reasonable) +target_compile_options(glfw PRIVATE + "$<$:-Wall>" + "$<$:-Wall>") + if (BUILD_SHARED_LIBS) if (WIN32) - # The GLFW DLL needs a special compile-time macro and import library name - set_target_properties(glfw PROPERTIES PREFIX "") - if (MINGW) + # Remove the lib prefix on the DLL (but not the import library + set_target_properties(glfw PROPERTIES PREFIX "") + + # Add a suffix to the import library to avoid naming conflicts set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a") else() + # Add a suffix to the import library to avoid naming conflicts set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") endif() elseif (APPLE) - # Append -fno-common to the compile flags to work around a bug in - # Apple's GCC - get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS) - if (NOT glfw_CFLAGS) - set(glfw_CFLAGS "") - endif() + # Add -fno-common to work around a bug in Apple's GCC + target_compile_options(glfw PRIVATE "-fno-common") + set_target_properties(glfw PROPERTIES - COMPILE_FLAGS "${glfw_CFLAGS} -fno-common" - INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") + INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") + elseif (UNIX) + # Hide symbols not explicitly tagged for export from the shared library + target_compile_options(glfw PRIVATE "-fvisibility=hidden") endif() target_link_libraries(glfw ${glfw_LIBRARIES}) endif() +if (MSVC) + target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS) +endif() + +if (BUILD_SHARED_LIBS AND UNIX) + # On Unix-like systems, shared libraries can use the soname system. + set_target_properties(glfw PROPERTIES OUTPUT_NAME glfw) +else() + set_target_properties(glfw PROPERTIES OUTPUT_NAME glfw3) +endif() + if (GLFW_INSTALL) install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d8783768..af211600 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,6 +8,10 @@ else() link_libraries(${glfw_LIBRARIES}) endif() +if (MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif() + include_directories("${GLFW_SOURCE_DIR}/include" "${GLFW_SOURCE_DIR}/deps")