From: Julian Ospald Date: Fri Jun 1 22:54:47 UTC 2012 Subject: build system unset hardcoded install-destinations remove arch suffixes for binaries to avoid trouble within the ebuild respect flags --- CMakeLists.txt +++ CMakeLists.txt @@ -10,9 +10,9 @@ endif() include( CMakeDependentOption ) +include(GNUInstallDirs) set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ) -set( CMAKE_C_FLAGS "-msse2 -pipe" CACHE STRING "" ) set( CMAKE_C_FLAGS_DEBUG "-g" CACHE STRING "" ) set( CMAKE_C_FLAGS_MINSIZEREL "-DNDEBUG -Os" CACHE STRING "" ) set( CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O3 -ffast-math -fomit-frame-pointer -fno-strict-aliasing" CACHE STRING "" ) @@ -56,9 +56,6 @@ option( USE_INTERNAL_CRYPTO "Use internal crypto (nettle)" 0 ) option( NO_UNTRUSTED_PLUGINS "Don't load native plugins from the user dir" 1 ) -option( ENABLE_W_ALL "Use -Wall" 0 ) -option( ENABLE_WARNINGS "Enable various compiler warning options" 1 ) -option( ENABLE_HARDENING "Enable various hardening options" 1 ) cmake_dependent_option( BUILD_GAME_GPP "Build Tremulous GPP game logic" 1 "GAME_LIB OR GAME_QVM" 0 ) cmake_dependent_option( QVM_DEBUG "Enable (some) QVM debugging" 1 GAME_QVM 0 ) @@ -172,134 +169,6 @@ include_directories( "${CMAKE_BINARY_DIR}/CMakeFiles" ) -################# -# Compile flags # -################# - -macro( try_compiler_flag_internal PROP FLAG CC SUFFIX LABEL ) - set( SAVED_FLAGS "${CMAKE_${CC}_FLAGS}" ) - set( CMAKE_${CC}_FLAGS "${CMAKE_${CC}_FLAGS} ${FLAG}" ) - # test it on an executable - if( NOT ${PROP}_${CC}_CACHED ) - try_compile( ${PROP}_${CC} ${MOUNT_DIR}/tests ${MOUNT_DIR}/tests/test.${SUFFIX} - CMAKE_FLAGS "-DCMAKE_${CC}_FLAGS=${CMAKE_${CC}_FLAGS}" ) - endif() - if( ${PROP}_${CC} ) - if( NOT ${PROP}_${CC}_CACHED ) - message( STATUS "Using ${LABEL} flag ${FLAG}" ) - endif() - else() - if( NOT ${PROP}_${CC}_CACHED ) - message( STATUS "${LABEL} flag ${FLAG} is not available" ) - endif() - set( CMAKE_${CC}_FLAGS "${SAVED_FLAGS}" ) - endif() - set( ${PROP}_${CC}_CACHED TRUE CACHE INTERNAL "Set if ${LABEL} option ${FLAG} has been checked for." ) -endmacro() - -macro( try_c_flag PROP FLAG ) - try_compiler_flag_internal( ${PROP} ${FLAG} C c C ) -endmacro() - -macro( try_cxx_flag PROP FLAG ) - try_compiler_flag_internal( ${PROP} ${FLAG} CXX cxx C++) -endmacro() - -macro( try_llvm_flag PROP FLAG ) - try_compiler_flag_internal( ${PROP} ${FLAG} LLVM cc C/LLVM) -endmacro() - -macro( try_c_llvm_flag PROP FLAG ) - try_c_flag( ${PROP} ${FLAG} ) - if( GAME_LIB_LLVM ) - try_llvm_flag( ${PROP} ${FLAG} ) - endif() -endmacro() - -macro( try_c_cxx_flag PROP FLAG ) - try_c_flag( ${PROP} ${FLAG} ) - try_cxx_flag( ${PROP} ${FLAG} ) -endmacro() - -macro( try_c_cxx_llvm_flag PROP FLAG ) - try_c_flag( ${PROP} ${FLAG} ) - try_cxx_flag( ${PROP} ${FLAG} ) - if( GAME_LIB_LLVM ) - try_llvm_flag( ${PROP} ${FLAG} ) - endif() -endmacro() - -# Various warnings -if( ENABLE_W_ALL ) - try_c_cxx_llvm_flag( HAVE_W_ALL -Wall ) -endif() -if( ENABLE_WARNINGS ) - try_c_cxx_llvm_flag( HAVE_W_FORMAT2 -Wformat=2 ) - if( NOT HAVE_W_FORMAT2_C ) - try_c_cxx_llvm_flag( HAVE_W_FORMAT -Wformat ) - endif() - try_c_llvm_flag ( HAVE_W_0LEN_FMT -Wno-format-zero-length ) - try_c_cxx_llvm_flag( HAVE_W_FORMAT_SECURITY -Wformat-security ) - try_c_cxx_llvm_flag( HAVE_W_STRICT_ALIAS_2 -Wstrict-aliasing=2 ) - try_c_cxx_llvm_flag( HAVE_W_MISSING_FMT_ATTR -Wmissing-format-attribute ) - try_c_cxx_llvm_flag( HAVE_W_MISSING_NORETURN -Wmissing-noreturn ) - try_c_llvm_flag ( HAVE_W_IMPLICIT_FN -Wimplicit-function-declaration ) - if( HAVE_W_IMPLICIT_FN_C ) - try_c_cxx_llvm_flag( HAVE_W_ERR_IMPLICIT_FN -Werror=implicit-function-declaration ) - endif() - try_c_cxx_llvm_flag( HAVE_W_FMT_SECURITY -Wformat-security ) - if( HAVE_W_FMT_SECURITY_C ) - try_c_cxx_llvm_flag( HAVE_W_ERR_FMT_SECURITY -Werror=format-security ) - endif() -endif() - -# Hardening -if( ENABLE_HARDENING ) - try_c_cxx_flag( HAVE_F_STACK_PROTECTOR -fstack-protector ) -endif() - -############## -# Link flags # -############## - -macro( try_linker_flag PROP FLAG ) - set( SAVED_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" ) - set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}" ) - # test it on an executable - if( NOT ${PROP}_CACHED ) - try_compile( ${PROP} ${MOUNT_DIR}/tests ${MOUNT_DIR}/tests/test.c - CMAKE_FLAGS -DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS} ) - endif() - if( ${PROP} ) - if( NOT ${PROP}_CACHED ) - message( STATUS "Using linker flag ${FLAG}" ) - endif() - # assume that it works for shared & static libs too - set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAG}" ) - set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAG}" ) - else() - if( NOT ${PROP}_CACHED ) - message( STATUS "Linker flag ${FLAG} is not available" ) - endif() - set( CMAKE_EXE_LINKER_FLAGS "${SAVED_FLAGS}" ) - endif() - set( ${PROP}_CACHED TRUE CACHE INTERNAL "Set if linker option ${FLAG} has been checked for." ) -endmacro() - -# Can we get rid of unneeded external libraries? -try_linker_flag( HAVE_AS_NEEDED -Wl,--as-needed ) - -# If we can, fail if there are unresolved symbols -try_linker_flag( HAVE_Z_DEFS -Wl,-z,defs ) - -if( ENABLE_HARDENING ) - if( ENABLE_FSTACKPROT ) - try_linker_flag( HAVE_FSTACKPROT "-fstack-protector --param=ssp-buffer-size=4" ) - endif() - if( ENABLE_RELRO ) - try_linker_flag( HAVE_Z_RELRO_Z_NOW -Wl,-z,relro,-z,now ) - endif() -endif() ###################### # Define Build Files # @@ -1266,11 +1135,11 @@ include_directories( ${MOUNT_DIR}/libs/cpuinfo ${NEWTON_INCLUDES} ) target_link_libraries( client ${OS_LIBRARIES} ${NEWTON_LIBRARY} ) set_property( TARGET client APPEND PROPERTY COMPILE_DEFINITIONS USE_XREAL_RENDERER COMPAT_ET USE_REFENTITY_ANIMATIONSYSTEM USE_CRYPTO ) - set_target_properties( client PROPERTIES OUTPUT_NAME "daemon.${BUILD_ARCH}" PREFIX "" LINKER_LANGUAGE CXX ) + set_target_properties( client PROPERTIES OUTPUT_NAME "daemon" PREFIX "" LINKER_LANGUAGE CXX ) install( TARGETS client - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) # Mac OS X specific settings @@ -1416,11 +1285,11 @@ include_directories( ${MOUNT_DIR}/libs/cpuinfo ${NEWTON_INCLUDES} ) target_link_libraries( server ${OS_LIBRARIES} ${NEWTON_LIBRARY} ) set_property( TARGET server APPEND PROPERTY COMPILE_DEFINITIONS DEDICATED COMPAT_ET USE_CRYPTO ) - set_target_properties( server PROPERTIES OUTPUT_NAME "daemonded.${BUILD_ARCH}" PREFIX "" LINKER_LANGUAGE CXX ) + set_target_properties( server PROPERTIES OUTPUT_NAME "daemonded" PREFIX "" LINKER_LANGUAGE CXX ) install( TARGETS server - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) # Mac OS X has some trouble with PIC code under X86/32. @@ -1487,11 +1356,11 @@ include_directories( ${LIB_DIR}/picomodel ${MOUNT_DIR}/tools/common ) target_link_libraries( daemonMap ${OS_LIBRARIES} ) set_property( TARGET daemonMap APPEND PROPERTY COMPILE_DEFINITIONS USE_OPENGL ) - set_target_properties( daemonMap PROPERTIES OUTPUT_NAME "daemonmap.${BUILD_ARCH}" PREFIX "" ) + set_target_properties( daemonMap PROPERTIES OUTPUT_NAME "daemonmap" PREFIX "" ) install( TARGETS daemonMap - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) # This section finds and provides REQUIRED dependencies to DaemonMap target find_package( OpenGL REQUIRED )